From 44d5c9e2cf9f1ce0670be5bedd1e415cd5c3e739 Mon Sep 17 00:00:00 2001 From: kleidione Freitas Date: Thu, 24 Mar 2022 09:16:43 -0300 Subject: veux: Merge common tree to veux - Ref: https://github.com/xiaomi-sm6375-devs/android_device_xiaomi_sm6375-common Signed-off-by: kleidione --- Android.bp | 6 + Android.mk | 110 +- BoardConfig.mk | 235 +- README.md | 6 +- audio/audio_policy_configuration.xml | 384 ++ biometrics/Android.bp | 21 + biometrics/BiometricsFingerprint.cpp | 383 ++ biometrics/BiometricsFingerprint.h | 90 + ...ometrics.fingerprint@2.1-service.xiaomi_holi.rc | 36 + ...metrics.fingerprint@2.1-service.xiaomi_holi.xml | 42 + biometrics/service.cpp | 59 + biometrics/xiaomi_fingerprint.h | 172 + bluetooth/include/bdroid_buildcfg.h | 32 + bootctrl/Android.bp | 28 + compatibility_matrix.xml | 86 + config.fs | 200 + configs/component-overrides.xml | 19 + configs/powerhint.xml | 624 ++ configs/public.libraries.txt | 9 + configs/snapdragon_color_libs_config.xml | 33 + ...elephony_system-ext_privapp-permissions-qti.xml | 49 + device.mk | 519 +- extract-files.sh | 59 +- framework_compatibility_matrix.xml | 1121 ++++ gps/Android.bp | 45 + gps/Android.mk | 44 + gps/CleanSpec.mk | 50 + gps/Makefile.am | 10 + gps/android/1.0/AGnss.cpp | 203 + gps/android/1.0/AGnss.h | 79 + gps/android/1.0/AGnssRil.cpp | 115 + gps/android/1.0/AGnssRil.h | 83 + gps/android/1.0/Android.mk | 99 + gps/android/1.0/Gnss.cpp | 346 + gps/android/1.0/Gnss.h | 143 + gps/android/1.0/GnssBatching.cpp | 130 + gps/android/1.0/GnssBatching.h | 80 + gps/android/1.0/GnssConfiguration.cpp | 225 + gps/android/1.0/GnssConfiguration.h | 71 + gps/android/1.0/GnssDebug.cpp | 173 + gps/android/1.0/GnssDebug.h | 59 + gps/android/1.0/GnssGeofencing.cpp | 141 + gps/android/1.0/GnssGeofencing.h | 91 + gps/android/1.0/GnssMeasurement.cpp | 101 + gps/android/1.0/GnssMeasurement.h | 77 + gps/android/1.0/GnssNi.cpp | 85 + gps/android/1.0/GnssNi.h | 75 + .../1.0/android.hardware.gnss@1.0-service-qti.rc | 4 + .../1.0/android.hardware.gnss@1.0-service-qti.xml | 35 + gps/android/1.0/location_api/BatchingAPIClient.cpp | 197 + gps/android/1.0/location_api/BatchingAPIClient.h | 75 + gps/android/1.0/location_api/GeofenceAPIClient.cpp | 275 + gps/android/1.0/location_api/GeofenceAPIClient.h | 77 + gps/android/1.0/location_api/GnssAPIClient.cpp | 565 ++ gps/android/1.0/location_api/GnssAPIClient.h | 110 + gps/android/1.0/location_api/LocationUtil.cpp | 274 + gps/android/1.0/location_api/LocationUtil.h | 57 + .../1.0/location_api/MeasurementAPIClient.cpp | 276 + .../1.0/location_api/MeasurementAPIClient.h | 78 + gps/android/1.0/service.cpp | 85 + gps/android/1.1/AGnss.cpp | 203 + gps/android/1.1/AGnss.h | 79 + gps/android/1.1/AGnssRil.cpp | 115 + gps/android/1.1/AGnssRil.h | 83 + gps/android/1.1/Android.mk | 101 + gps/android/1.1/Gnss.cpp | 466 ++ gps/android/1.1/Gnss.h | 154 + gps/android/1.1/GnssBatching.cpp | 130 + gps/android/1.1/GnssBatching.h | 80 + gps/android/1.1/GnssConfiguration.cpp | 308 + gps/android/1.1/GnssConfiguration.h | 78 + gps/android/1.1/GnssDebug.cpp | 175 + gps/android/1.1/GnssDebug.h | 59 + gps/android/1.1/GnssGeofencing.cpp | 141 + gps/android/1.1/GnssGeofencing.h | 91 + gps/android/1.1/GnssMeasurement.cpp | 134 + gps/android/1.1/GnssMeasurement.h | 83 + gps/android/1.1/GnssNi.cpp | 85 + gps/android/1.1/GnssNi.h | 75 + .../1.1/android.hardware.gnss@1.1-service-qti.rc | 4 + .../1.1/android.hardware.gnss@1.1-service-qti.xml | 35 + gps/android/1.1/location_api/BatchingAPIClient.cpp | 197 + gps/android/1.1/location_api/BatchingAPIClient.h | 75 + gps/android/1.1/location_api/GeofenceAPIClient.cpp | 275 + gps/android/1.1/location_api/GeofenceAPIClient.h | 77 + gps/android/1.1/location_api/GnssAPIClient.cpp | 565 ++ gps/android/1.1/location_api/GnssAPIClient.h | 110 + gps/android/1.1/location_api/LocationUtil.cpp | 274 + gps/android/1.1/location_api/LocationUtil.h | 57 + .../1.1/location_api/MeasurementAPIClient.cpp | 332 + .../1.1/location_api/MeasurementAPIClient.h | 85 + gps/android/1.1/service.cpp | 85 + gps/android/2.0/AGnss.cpp | 209 + gps/android/2.0/AGnss.h | 77 + gps/android/2.0/AGnssRil.cpp | 135 + gps/android/2.0/AGnssRil.h | 84 + gps/android/2.0/Android.mk | 112 + gps/android/2.0/Gnss.cpp | 677 ++ gps/android/2.0/Gnss.h | 187 + gps/android/2.0/GnssBatching.cpp | 163 + gps/android/2.0/GnssBatching.h | 84 + gps/android/2.0/GnssConfiguration.cpp | 317 + gps/android/2.0/GnssConfiguration.h | 80 + gps/android/2.0/GnssDebug.cpp | 299 + gps/android/2.0/GnssDebug.h | 62 + gps/android/2.0/GnssGeofencing.cpp | 141 + gps/android/2.0/GnssGeofencing.h | 91 + gps/android/2.0/GnssMeasurement.cpp | 175 + gps/android/2.0/GnssMeasurement.h | 87 + gps/android/2.0/GnssNi.cpp | 85 + gps/android/2.0/GnssNi.h | 75 + gps/android/2.0/GnssVisibilityControl.cpp | 169 + gps/android/2.0/GnssVisibilityControl.h | 90 + gps/android/2.0/MeasurementCorrections.cpp | 73 + gps/android/2.0/MeasurementCorrections.h | 77 + .../2.0/android.hardware.gnss@2.0-service-qti.rc | 4 + .../2.0/android.hardware.gnss@2.0-service-qti.xml | 36 + gps/android/2.0/location_api/BatchingAPIClient.cpp | 251 + gps/android/2.0/location_api/BatchingAPIClient.h | 82 + gps/android/2.0/location_api/GeofenceAPIClient.cpp | 275 + gps/android/2.0/location_api/GeofenceAPIClient.h | 77 + gps/android/2.0/location_api/GnssAPIClient.cpp | 728 +++ gps/android/2.0/location_api/GnssAPIClient.h | 115 + gps/android/2.0/location_api/LocationUtil.cpp | 334 + gps/android/2.0/location_api/LocationUtil.h | 60 + .../2.0/location_api/MeasurementAPIClient.cpp | 507 ++ .../2.0/location_api/MeasurementAPIClient.h | 90 + gps/android/2.0/service.cpp | 81 + gps/android/2.1/AGnss.cpp | 209 + gps/android/2.1/AGnss.h | 78 + gps/android/2.1/AGnssRil.cpp | 135 + gps/android/2.1/AGnssRil.h | 84 + gps/android/2.1/Android.mk | 116 + gps/android/2.1/Gnss.cpp | 800 +++ gps/android/2.1/Gnss.h | 193 + gps/android/2.1/GnssAntennaInfo.cpp | 202 + gps/android/2.1/GnssAntennaInfo.h | 90 + gps/android/2.1/GnssBatching.cpp | 163 + gps/android/2.1/GnssBatching.h | 84 + gps/android/2.1/GnssConfiguration.cpp | 408 ++ gps/android/2.1/GnssConfiguration.h | 88 + gps/android/2.1/GnssDebug.cpp | 299 + gps/android/2.1/GnssDebug.h | 62 + gps/android/2.1/GnssGeofencing.cpp | 141 + gps/android/2.1/GnssGeofencing.h | 91 + gps/android/2.1/GnssMeasurement.cpp | 211 + gps/android/2.1/GnssMeasurement.h | 93 + gps/android/2.1/GnssNi.cpp | 85 + gps/android/2.1/GnssNi.h | 75 + gps/android/2.1/GnssVisibilityControl.cpp | 169 + gps/android/2.1/GnssVisibilityControl.h | 90 + gps/android/2.1/MeasurementCorrections.cpp | 199 + gps/android/2.1/MeasurementCorrections.h | 106 + .../2.1/android.hardware.gnss@2.1-service-qti.rc | 4 + .../2.1/android.hardware.gnss@2.1-service-qti.xml | 36 + gps/android/2.1/location_api/BatchingAPIClient.cpp | 251 + gps/android/2.1/location_api/BatchingAPIClient.h | 82 + gps/android/2.1/location_api/GeofenceAPIClient.cpp | 275 + gps/android/2.1/location_api/GeofenceAPIClient.h | 77 + gps/android/2.1/location_api/GnssAPIClient.cpp | 864 +++ gps/android/2.1/location_api/GnssAPIClient.h | 118 + gps/android/2.1/location_api/LocationUtil.cpp | 405 ++ gps/android/2.1/location_api/LocationUtil.h | 68 + .../2.1/location_api/MeasurementAPIClient.cpp | 642 ++ .../2.1/location_api/MeasurementAPIClient.h | 96 + gps/android/2.1/service.cpp | 81 + gps/android/Android.mk | 2 + gps/android/utils/Android.bp | 37 + gps/android/utils/battery_listener.cpp | 280 + gps/android/utils/battery_listener.h | 32 + gps/batching/Android.bp | 31 + gps/batching/BatchingAdapter.cpp | 1045 +++ gps/batching/BatchingAdapter.h | 152 + gps/batching/Makefile.am | 44 + gps/batching/configure.ac | 74 + gps/batching/location-batching.pc.in | 10 + gps/batching/location_batching.cpp | 134 + gps/configure.ac | 87 + gps/core/Android.bp | 56 + gps/core/ContextBase.cpp | 384 ++ gps/core/ContextBase.h | 385 ++ gps/core/EngineHubProxyBase.h | 160 + gps/core/LBSProxyBase.h | 70 + gps/core/LocAdapterBase.cpp | 439 ++ gps/core/LocAdapterBase.h | 246 + gps/core/LocAdapterProxyBase.h | 77 + gps/core/LocApiBase.cpp | 1069 +++ gps/core/LocApiBase.h | 375 ++ gps/core/LocContext.cpp | 87 + gps/core/LocContext.h | 60 + gps/core/Makefile.am | 74 + gps/core/SystemStatus.cpp | 1760 +++++ gps/core/SystemStatus.h | 924 +++ gps/core/SystemStatusOsObserver.cpp | 592 ++ gps/core/SystemStatusOsObserver.h | 181 + gps/core/configure.ac | 107 + gps/core/data-items/DataItemConcreteTypesBase.h | 555 ++ gps/core/data-items/DataItemId.h | 79 + gps/core/data-items/DataItemsFactoryProxy.cpp | 82 + gps/core/data-items/DataItemsFactoryProxy.h | 55 + gps/core/data-items/IDataItemCore.h | 82 + gps/core/loc-core.pc.in | 10 + gps/core/loc_core_log.cpp | 215 + gps/core/loc_core_log.h | 58 + gps/core/observer/IDataItemObserver.h | 76 + gps/core/observer/IDataItemSubscription.h | 129 + gps/core/observer/IFrameworkActionReq.h | 104 + gps/core/observer/IOsObserver.h | 107 + gps/etc/Android.bp | 55 + gps/etc/apdr.conf | 183 + gps/etc/flp.conf | 60 + gps/etc/gnss_antenna_info.conf | 134 + gps/etc/gps.conf | 391 ++ gps/etc/izat.conf | 277 + gps/etc/lowi.conf | 26 + gps/etc/sap.conf | 181 + gps/etc/seccomp_policy/gnss@2.0-base.policy | 95 + gps/etc/seccomp_policy/gnss@2.0-xtra-daemon.policy | 48 + gps/geofence/Android.bp | 31 + gps/geofence/GeofenceAdapter.cpp | 866 +++ gps/geofence/GeofenceAdapter.h | 136 + gps/geofence/Makefile.am | 50 + gps/geofence/configure.ac | 72 + gps/geofence/location-geofence.pc.in | 10 + gps/geofence/location_geofence.cpp | 145 + gps/gnss/Agps.cpp | 675 ++ gps/gnss/Agps.h | 318 + gps/gnss/Android.bp | 35 + gps/gnss/GnssAdapter.cpp | 6916 ++++++++++++++++++++ gps/gnss/GnssAdapter.h | 648 ++ gps/gnss/Makefile.am | 32 + gps/gnss/NativeAgpsHandler.cpp | 127 + gps/gnss/NativeAgpsHandler.h | 64 + gps/gnss/XtraSystemStatusObserver.cpp | 384 ++ gps/gnss/XtraSystemStatusObserver.h | 112 + gps/gnss/location_gnss.cpp | 593 ++ gps/gps_vendor_board.mk | 7 + gps/gps_vendor_product.mk | 44 + gps/loc-hal.pc.in | 10 + gps/location/Android.bp | 36 + gps/location/ILocationAPI.h | 406 ++ gps/location/LocationAPI.cpp | 976 +++ gps/location/LocationAPI.h | 512 ++ gps/location/LocationAPIClientBase.cpp | 977 +++ gps/location/LocationAPIClientBase.h | 592 ++ gps/location/LocationDataTypes.h | 2070 ++++++ gps/location/Makefile.am | 44 + gps/location/configure.ac | 95 + gps/location/location-api.pc.in | 10 + gps/location/location_interface.h | 144 + gps/pla/Android.bp | 7 + gps/pla/android/loc_pla.h | 97 + gps/pla/oe/loc_pla.h | 175 + gps/utils/Android.bp | 54 + gps/utils/LocHeap.cpp | 280 + gps/utils/LocHeap.h | 100 + gps/utils/LocIpc.cpp | 430 ++ gps/utils/LocIpc.h | 241 + gps/utils/LocLoggerBase.h | 39 + gps/utils/LocSharedLock.h | 81 + gps/utils/LocThread.cpp | 111 + gps/utils/LocThread.h | 95 + gps/utils/LocTimer.cpp | 648 ++ gps/utils/LocTimer.h | 78 + gps/utils/LocUnorderedSetMap.h | 201 + gps/utils/LogBuffer.cpp | 189 + gps/utils/LogBuffer.h | 95 + gps/utils/Makefile.am | 75 + gps/utils/MsgTask.cpp | 120 + gps/utils/MsgTask.h | 56 + gps/utils/SkipList.h | 158 + gps/utils/configure.ac | 92 + gps/utils/gps-utils.pc.in | 10 + gps/utils/gps_extended.h | 114 + gps/utils/gps_extended_c.h | 2429 +++++++ gps/utils/linked_list.c | 325 + gps/utils/linked_list.h | 219 + gps/utils/loc_cfg.cpp | 1140 ++++ gps/utils/loc_cfg.h | 167 + gps/utils/loc_gps.h | 2235 +++++++ gps/utils/loc_log.cpp | 282 + gps/utils/loc_log.h | 122 + gps/utils/loc_misc_utils.cpp | 351 + gps/utils/loc_misc_utils.h | 321 + gps/utils/loc_nmea.cpp | 2347 +++++++ gps/utils/loc_nmea.h | 95 + gps/utils/loc_target.cpp | 249 + gps/utils/loc_target.h | 82 + gps/utils/loc_timer.h | 74 + gps/utils/log_util.h | 291 + gps/utils/msg_q.c | 380 ++ gps/utils/msg_q.h | 230 + gpt-utils/Android.bp | 41 + gpt-utils/gpt-utils.cpp | 1519 +++++ gpt-utils/gpt-utils.h | 193 + gpt-utils/recovery-ufs-bsg.cpp | 255 + gpt-utils/recovery-ufs-bsg.h | 131 + gpt-utils/sparse_crc32.cpp | 97 + gpt-utils/sparse_crc32.h | 24 + libhidl/Android.bp | 12 + libinit/Android.bp | 24 +- libinit/include/libinit_dalvik_heap.h | 23 + libinit/include/libinit_utils.h | 18 + libinit/include/libinit_variant.h | 31 + libinit/init_xiaomi_holi.cpp | 13 + libinit/init_xiaomi_veux.cpp | 54 +- libinit/libinit_dalvik_heap.cpp | 67 + libinit/libinit_utils.cpp | 73 + libinit/libinit_variant.cpp | 49 + lineage.dependencies | 6 - manifest.xml | 727 ++ manifest_nfc.xml | 29 + odm.prop | 2 + org.ifaa.android.manager/Android.bp | 30 + .../src/org/ifaa/android/manager/IFAAManager.java | 69 + .../ifaa/android/manager/IFAAManagerFactory.java | 11 + .../org/ifaa/android/manager/IFAAManagerImpl.java | 322 + .../org/ifaa/android/manager/IFAAManagerV2.java | 9 + .../org/ifaa/android/manager/IFAAManagerV3.java | 20 + .../org/ifaa/android/manager/IFAAManagerV4.java | 11 + .../src/org/ifaa/android/manager/IIFAAService.aidl | 12 + .../base/packages/SystemUI/res/values/config.xml | 16 - .../lineage-sdk/lineage/res/res/values/config.xml | 57 - .../packages/apps/Settings/res/values/config.xml | 23 - .../frameworks/base/core/res/res/values/config.xml | 374 -- .../frameworks/base/core/res/res/values/dimens.xml | 26 - .../base/core/res/res/xml/power_profile.xml | 111 - .../base/packages/SystemUI/res/values/config.xml | 25 - .../base/packages/SystemUI/res/values/dimens.xml | 37 - .../packages/apps/Settings/res/values/config.xml | 24 - permissions/privapp-permissions-hotword.xml | 14 + proprietary-files.txt | 867 ++- releasetools.py | 32 + reorder-libs.py | 2 +- rootdir/Android.mk | 124 + rootdir/bin/init.class_main.sh | 155 + rootdir/bin/init.kernel.post_boot-blair.sh | 249 + rootdir/bin/init.kernel.post_boot-holi.sh | 246 + rootdir/bin/init.kernel.post_boot.sh | 49 + rootdir/bin/init.mi.btmac.sh | 21 + rootdir/bin/init.qcom.post_boot.sh | 6235 ++++++++++++++++++ rootdir/bin/init.qcom.sh | 465 ++ rootdir/bin/vendor_modprobe.sh | 38 + rootdir/etc/charger_fstab.qti | 33 + rootdir/etc/fstab.default | 51 + rootdir/etc/fstab.emmc | 51 + rootdir/etc/init.batterysecret.rc | 31 + rootdir/etc/init.nfc.rc | 15 + rootdir/etc/init.qcom.rc | 1581 +++++ rootdir/etc/init.qti.kernel.rc | 175 + rootdir/etc/init.qti.ufs.rc | 30 + rootdir/etc/init.recovery.qcom.rc | 38 + rootdir/etc/init.target.rc | 286 + rootdir/etc/ueventd.qcom.rc | 507 ++ sensors/Android.bp | 49 + sensors/HalProxy.cpp | 778 +++ sensors/HalProxyCallback.cpp | 90 + ...are.sensors@2.1-service.xiaomi_holi-multihal.rc | 7 + ...d.hardware.sensors@2.1.xiaomi_holi-multihal.xml | 11 + sensors/service.cpp | 39 + sepolicy/private/file_contexts | 2 + sepolicy/public/attributes | 3 + sepolicy/public/property.te | 5 + sepolicy/public/property_contexts | 6 + sepolicy/vendor/adsprpcd.te | 1 + sepolicy/vendor/app.te | 1 + sepolicy/vendor/batterysecret.te | 49 + sepolicy/vendor/device.te | 8 + sepolicy/vendor/file.te | 17 + sepolicy/vendor/file_contexts | 56 + sepolicy/vendor/genfs_contexts | 58 + sepolicy/vendor/hal_audio_default.te | 13 + sepolicy/vendor/hal_bluetooth_default.te | 6 + sepolicy/vendor/hal_bootctl_default.te | 1 + sepolicy/vendor/hal_camera_default.te | 2 + sepolicy/vendor/hal_fingerprint_default.te | 37 + sepolicy/vendor/hal_health_default.te | 2 + sepolicy/vendor/hal_ir_default.te | 1 + sepolicy/vendor/hal_mlipay.te | 22 + sepolicy/vendor/hal_nfc_default.te | 2 + sepolicy/vendor/hal_perf_default.te | 5 + sepolicy/vendor/hal_power_default.te | 3 + sepolicy/vendor/hal_sensors_default.te | 10 + sepolicy/vendor/hal_wifi_default.te | 1 + sepolicy/vendor/hwservice_contexts | 15 + sepolicy/vendor/mi_thermald.te | 35 + sepolicy/vendor/property.te | 5 + sepolicy/vendor/property_contexts | 26 + sepolicy/vendor/qti_init_shell.te | 1 + sepolicy/vendor/recovery.te | 1 + sepolicy/vendor/sensors.te | 1 + sepolicy/vendor/system_app.te | 2 + sepolicy/vendor/tee.te | 2 + sepolicy/vendor/thermal-engine.te | 11 + sepolicy/vendor/vendor_modprobe.te | 4 + sepolicy/vendor/vendor_qti_init_shell.te | 4 + setup-makefiles.sh | 32 +- system.prop | 42 + system_ext.prop | 5 + vendor.prop | 272 + vibrator/Android.bp | 42 + vibrator/Vibrator.cpp | 587 ++ vibrator/excluded-input-devices.xml | 32 + vibrator/include/Vibrator.h | 96 + vibrator/service.cpp | 50 + ...or.qti.hardware.vibrator.service.xiaomi_holi.rc | 4 + ...r.qti.hardware.vibrator.service.xiaomi_holi.xml | 33 + wifi/WCNSS_qcom_cfg.ini | 569 ++ wifi/p2p_supplicant_overlay.conf | 4 + wifi/wpa_supplicant_overlay.conf | 8 + 410 files changed, 89426 insertions(+), 826 deletions(-) create mode 100644 Android.bp create mode 100644 audio/audio_policy_configuration.xml create mode 100644 biometrics/Android.bp create mode 100644 biometrics/BiometricsFingerprint.cpp create mode 100644 biometrics/BiometricsFingerprint.h create mode 100644 biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.rc create mode 100644 biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.xml create mode 100644 biometrics/service.cpp create mode 100644 biometrics/xiaomi_fingerprint.h create mode 100644 bluetooth/include/bdroid_buildcfg.h create mode 100644 bootctrl/Android.bp create mode 100644 compatibility_matrix.xml create mode 100644 config.fs create mode 100644 configs/component-overrides.xml create mode 100644 configs/powerhint.xml create mode 100644 configs/public.libraries.txt create mode 100644 configs/snapdragon_color_libs_config.xml create mode 100644 configs/telephony_system-ext_privapp-permissions-qti.xml create mode 100644 framework_compatibility_matrix.xml create mode 100644 gps/Android.bp create mode 100644 gps/Android.mk create mode 100644 gps/CleanSpec.mk create mode 100644 gps/Makefile.am create mode 100644 gps/android/1.0/AGnss.cpp create mode 100644 gps/android/1.0/AGnss.h create mode 100644 gps/android/1.0/AGnssRil.cpp create mode 100644 gps/android/1.0/AGnssRil.h create mode 100644 gps/android/1.0/Android.mk create mode 100644 gps/android/1.0/Gnss.cpp create mode 100644 gps/android/1.0/Gnss.h create mode 100644 gps/android/1.0/GnssBatching.cpp create mode 100644 gps/android/1.0/GnssBatching.h create mode 100644 gps/android/1.0/GnssConfiguration.cpp create mode 100644 gps/android/1.0/GnssConfiguration.h create mode 100644 gps/android/1.0/GnssDebug.cpp create mode 100644 gps/android/1.0/GnssDebug.h create mode 100644 gps/android/1.0/GnssGeofencing.cpp create mode 100644 gps/android/1.0/GnssGeofencing.h create mode 100644 gps/android/1.0/GnssMeasurement.cpp create mode 100644 gps/android/1.0/GnssMeasurement.h create mode 100644 gps/android/1.0/GnssNi.cpp create mode 100644 gps/android/1.0/GnssNi.h create mode 100644 gps/android/1.0/android.hardware.gnss@1.0-service-qti.rc create mode 100644 gps/android/1.0/android.hardware.gnss@1.0-service-qti.xml create mode 100644 gps/android/1.0/location_api/BatchingAPIClient.cpp create mode 100644 gps/android/1.0/location_api/BatchingAPIClient.h create mode 100644 gps/android/1.0/location_api/GeofenceAPIClient.cpp create mode 100644 gps/android/1.0/location_api/GeofenceAPIClient.h create mode 100644 gps/android/1.0/location_api/GnssAPIClient.cpp create mode 100644 gps/android/1.0/location_api/GnssAPIClient.h create mode 100644 gps/android/1.0/location_api/LocationUtil.cpp create mode 100644 gps/android/1.0/location_api/LocationUtil.h create mode 100644 gps/android/1.0/location_api/MeasurementAPIClient.cpp create mode 100644 gps/android/1.0/location_api/MeasurementAPIClient.h create mode 100644 gps/android/1.0/service.cpp create mode 100644 gps/android/1.1/AGnss.cpp create mode 100644 gps/android/1.1/AGnss.h create mode 100644 gps/android/1.1/AGnssRil.cpp create mode 100644 gps/android/1.1/AGnssRil.h create mode 100644 gps/android/1.1/Android.mk create mode 100644 gps/android/1.1/Gnss.cpp create mode 100644 gps/android/1.1/Gnss.h create mode 100644 gps/android/1.1/GnssBatching.cpp create mode 100644 gps/android/1.1/GnssBatching.h create mode 100644 gps/android/1.1/GnssConfiguration.cpp create mode 100644 gps/android/1.1/GnssConfiguration.h create mode 100644 gps/android/1.1/GnssDebug.cpp create mode 100644 gps/android/1.1/GnssDebug.h create mode 100644 gps/android/1.1/GnssGeofencing.cpp create mode 100644 gps/android/1.1/GnssGeofencing.h create mode 100644 gps/android/1.1/GnssMeasurement.cpp create mode 100644 gps/android/1.1/GnssMeasurement.h create mode 100644 gps/android/1.1/GnssNi.cpp create mode 100644 gps/android/1.1/GnssNi.h create mode 100644 gps/android/1.1/android.hardware.gnss@1.1-service-qti.rc create mode 100644 gps/android/1.1/android.hardware.gnss@1.1-service-qti.xml create mode 100644 gps/android/1.1/location_api/BatchingAPIClient.cpp create mode 100644 gps/android/1.1/location_api/BatchingAPIClient.h create mode 100644 gps/android/1.1/location_api/GeofenceAPIClient.cpp create mode 100644 gps/android/1.1/location_api/GeofenceAPIClient.h create mode 100644 gps/android/1.1/location_api/GnssAPIClient.cpp create mode 100644 gps/android/1.1/location_api/GnssAPIClient.h create mode 100644 gps/android/1.1/location_api/LocationUtil.cpp create mode 100644 gps/android/1.1/location_api/LocationUtil.h create mode 100644 gps/android/1.1/location_api/MeasurementAPIClient.cpp create mode 100644 gps/android/1.1/location_api/MeasurementAPIClient.h create mode 100644 gps/android/1.1/service.cpp create mode 100644 gps/android/2.0/AGnss.cpp create mode 100644 gps/android/2.0/AGnss.h create mode 100644 gps/android/2.0/AGnssRil.cpp create mode 100644 gps/android/2.0/AGnssRil.h create mode 100644 gps/android/2.0/Android.mk create mode 100644 gps/android/2.0/Gnss.cpp create mode 100644 gps/android/2.0/Gnss.h create mode 100644 gps/android/2.0/GnssBatching.cpp create mode 100644 gps/android/2.0/GnssBatching.h create mode 100644 gps/android/2.0/GnssConfiguration.cpp create mode 100644 gps/android/2.0/GnssConfiguration.h create mode 100644 gps/android/2.0/GnssDebug.cpp create mode 100644 gps/android/2.0/GnssDebug.h create mode 100644 gps/android/2.0/GnssGeofencing.cpp create mode 100644 gps/android/2.0/GnssGeofencing.h create mode 100644 gps/android/2.0/GnssMeasurement.cpp create mode 100644 gps/android/2.0/GnssMeasurement.h create mode 100644 gps/android/2.0/GnssNi.cpp create mode 100644 gps/android/2.0/GnssNi.h create mode 100644 gps/android/2.0/GnssVisibilityControl.cpp create mode 100644 gps/android/2.0/GnssVisibilityControl.h create mode 100644 gps/android/2.0/MeasurementCorrections.cpp create mode 100644 gps/android/2.0/MeasurementCorrections.h create mode 100644 gps/android/2.0/android.hardware.gnss@2.0-service-qti.rc create mode 100644 gps/android/2.0/android.hardware.gnss@2.0-service-qti.xml create mode 100644 gps/android/2.0/location_api/BatchingAPIClient.cpp create mode 100644 gps/android/2.0/location_api/BatchingAPIClient.h create mode 100644 gps/android/2.0/location_api/GeofenceAPIClient.cpp create mode 100644 gps/android/2.0/location_api/GeofenceAPIClient.h create mode 100644 gps/android/2.0/location_api/GnssAPIClient.cpp create mode 100644 gps/android/2.0/location_api/GnssAPIClient.h create mode 100644 gps/android/2.0/location_api/LocationUtil.cpp create mode 100644 gps/android/2.0/location_api/LocationUtil.h create mode 100644 gps/android/2.0/location_api/MeasurementAPIClient.cpp create mode 100644 gps/android/2.0/location_api/MeasurementAPIClient.h create mode 100644 gps/android/2.0/service.cpp create mode 100644 gps/android/2.1/AGnss.cpp create mode 100644 gps/android/2.1/AGnss.h create mode 100644 gps/android/2.1/AGnssRil.cpp create mode 100644 gps/android/2.1/AGnssRil.h create mode 100644 gps/android/2.1/Android.mk create mode 100644 gps/android/2.1/Gnss.cpp create mode 100644 gps/android/2.1/Gnss.h create mode 100644 gps/android/2.1/GnssAntennaInfo.cpp create mode 100644 gps/android/2.1/GnssAntennaInfo.h create mode 100644 gps/android/2.1/GnssBatching.cpp create mode 100644 gps/android/2.1/GnssBatching.h create mode 100644 gps/android/2.1/GnssConfiguration.cpp create mode 100644 gps/android/2.1/GnssConfiguration.h create mode 100644 gps/android/2.1/GnssDebug.cpp create mode 100644 gps/android/2.1/GnssDebug.h create mode 100644 gps/android/2.1/GnssGeofencing.cpp create mode 100644 gps/android/2.1/GnssGeofencing.h create mode 100644 gps/android/2.1/GnssMeasurement.cpp create mode 100644 gps/android/2.1/GnssMeasurement.h create mode 100644 gps/android/2.1/GnssNi.cpp create mode 100644 gps/android/2.1/GnssNi.h create mode 100644 gps/android/2.1/GnssVisibilityControl.cpp create mode 100644 gps/android/2.1/GnssVisibilityControl.h create mode 100644 gps/android/2.1/MeasurementCorrections.cpp create mode 100644 gps/android/2.1/MeasurementCorrections.h create mode 100644 gps/android/2.1/android.hardware.gnss@2.1-service-qti.rc create mode 100755 gps/android/2.1/android.hardware.gnss@2.1-service-qti.xml create mode 100644 gps/android/2.1/location_api/BatchingAPIClient.cpp create mode 100755 gps/android/2.1/location_api/BatchingAPIClient.h create mode 100755 gps/android/2.1/location_api/GeofenceAPIClient.cpp create mode 100755 gps/android/2.1/location_api/GeofenceAPIClient.h create mode 100644 gps/android/2.1/location_api/GnssAPIClient.cpp create mode 100755 gps/android/2.1/location_api/GnssAPIClient.h create mode 100644 gps/android/2.1/location_api/LocationUtil.cpp create mode 100644 gps/android/2.1/location_api/LocationUtil.h create mode 100644 gps/android/2.1/location_api/MeasurementAPIClient.cpp create mode 100644 gps/android/2.1/location_api/MeasurementAPIClient.h create mode 100755 gps/android/2.1/service.cpp create mode 100644 gps/android/Android.mk create mode 100644 gps/android/utils/Android.bp create mode 100644 gps/android/utils/battery_listener.cpp create mode 100644 gps/android/utils/battery_listener.h create mode 100644 gps/batching/Android.bp create mode 100644 gps/batching/BatchingAdapter.cpp create mode 100644 gps/batching/BatchingAdapter.h create mode 100644 gps/batching/Makefile.am create mode 100644 gps/batching/configure.ac create mode 100644 gps/batching/location-batching.pc.in create mode 100644 gps/batching/location_batching.cpp create mode 100644 gps/configure.ac create mode 100644 gps/core/Android.bp create mode 100644 gps/core/ContextBase.cpp create mode 100644 gps/core/ContextBase.h create mode 100644 gps/core/EngineHubProxyBase.h create mode 100644 gps/core/LBSProxyBase.h create mode 100644 gps/core/LocAdapterBase.cpp create mode 100644 gps/core/LocAdapterBase.h create mode 100644 gps/core/LocAdapterProxyBase.h create mode 100644 gps/core/LocApiBase.cpp create mode 100644 gps/core/LocApiBase.h create mode 100644 gps/core/LocContext.cpp create mode 100644 gps/core/LocContext.h create mode 100644 gps/core/Makefile.am create mode 100644 gps/core/SystemStatus.cpp create mode 100644 gps/core/SystemStatus.h create mode 100644 gps/core/SystemStatusOsObserver.cpp create mode 100644 gps/core/SystemStatusOsObserver.h create mode 100644 gps/core/configure.ac create mode 100644 gps/core/data-items/DataItemConcreteTypesBase.h create mode 100644 gps/core/data-items/DataItemId.h create mode 100644 gps/core/data-items/DataItemsFactoryProxy.cpp create mode 100644 gps/core/data-items/DataItemsFactoryProxy.h create mode 100644 gps/core/data-items/IDataItemCore.h create mode 100644 gps/core/loc-core.pc.in create mode 100644 gps/core/loc_core_log.cpp create mode 100644 gps/core/loc_core_log.h create mode 100644 gps/core/observer/IDataItemObserver.h create mode 100644 gps/core/observer/IDataItemSubscription.h create mode 100644 gps/core/observer/IFrameworkActionReq.h create mode 100644 gps/core/observer/IOsObserver.h create mode 100644 gps/etc/Android.bp create mode 100644 gps/etc/apdr.conf create mode 100644 gps/etc/flp.conf create mode 100644 gps/etc/gnss_antenna_info.conf create mode 100644 gps/etc/gps.conf create mode 100644 gps/etc/izat.conf create mode 100644 gps/etc/lowi.conf create mode 100644 gps/etc/sap.conf create mode 100644 gps/etc/seccomp_policy/gnss@2.0-base.policy create mode 100644 gps/etc/seccomp_policy/gnss@2.0-xtra-daemon.policy create mode 100644 gps/geofence/Android.bp create mode 100644 gps/geofence/GeofenceAdapter.cpp create mode 100644 gps/geofence/GeofenceAdapter.h create mode 100644 gps/geofence/Makefile.am create mode 100644 gps/geofence/configure.ac create mode 100644 gps/geofence/location-geofence.pc.in create mode 100644 gps/geofence/location_geofence.cpp create mode 100644 gps/gnss/Agps.cpp create mode 100644 gps/gnss/Agps.h create mode 100644 gps/gnss/Android.bp create mode 100644 gps/gnss/GnssAdapter.cpp create mode 100644 gps/gnss/GnssAdapter.h create mode 100644 gps/gnss/Makefile.am create mode 100644 gps/gnss/NativeAgpsHandler.cpp create mode 100644 gps/gnss/NativeAgpsHandler.h create mode 100644 gps/gnss/XtraSystemStatusObserver.cpp create mode 100644 gps/gnss/XtraSystemStatusObserver.h create mode 100644 gps/gnss/location_gnss.cpp create mode 100644 gps/gps_vendor_board.mk create mode 100644 gps/gps_vendor_product.mk create mode 100644 gps/loc-hal.pc.in create mode 100644 gps/location/Android.bp create mode 100644 gps/location/ILocationAPI.h create mode 100644 gps/location/LocationAPI.cpp create mode 100644 gps/location/LocationAPI.h create mode 100644 gps/location/LocationAPIClientBase.cpp create mode 100644 gps/location/LocationAPIClientBase.h create mode 100644 gps/location/LocationDataTypes.h create mode 100644 gps/location/Makefile.am create mode 100644 gps/location/configure.ac create mode 100644 gps/location/location-api.pc.in create mode 100644 gps/location/location_interface.h create mode 100644 gps/pla/Android.bp create mode 100644 gps/pla/android/loc_pla.h create mode 100644 gps/pla/oe/loc_pla.h create mode 100644 gps/utils/Android.bp create mode 100644 gps/utils/LocHeap.cpp create mode 100644 gps/utils/LocHeap.h create mode 100644 gps/utils/LocIpc.cpp create mode 100644 gps/utils/LocIpc.h create mode 100644 gps/utils/LocLoggerBase.h create mode 100644 gps/utils/LocSharedLock.h create mode 100644 gps/utils/LocThread.cpp create mode 100644 gps/utils/LocThread.h create mode 100644 gps/utils/LocTimer.cpp create mode 100644 gps/utils/LocTimer.h create mode 100644 gps/utils/LocUnorderedSetMap.h create mode 100644 gps/utils/LogBuffer.cpp create mode 100644 gps/utils/LogBuffer.h create mode 100644 gps/utils/Makefile.am create mode 100644 gps/utils/MsgTask.cpp create mode 100644 gps/utils/MsgTask.h create mode 100644 gps/utils/SkipList.h create mode 100644 gps/utils/configure.ac create mode 100644 gps/utils/gps-utils.pc.in create mode 100644 gps/utils/gps_extended.h create mode 100644 gps/utils/gps_extended_c.h create mode 100644 gps/utils/linked_list.c create mode 100644 gps/utils/linked_list.h create mode 100644 gps/utils/loc_cfg.cpp create mode 100644 gps/utils/loc_cfg.h create mode 100644 gps/utils/loc_gps.h create mode 100644 gps/utils/loc_log.cpp create mode 100644 gps/utils/loc_log.h create mode 100644 gps/utils/loc_misc_utils.cpp create mode 100644 gps/utils/loc_misc_utils.h create mode 100644 gps/utils/loc_nmea.cpp create mode 100644 gps/utils/loc_nmea.h create mode 100644 gps/utils/loc_target.cpp create mode 100644 gps/utils/loc_target.h create mode 100644 gps/utils/loc_timer.h create mode 100644 gps/utils/log_util.h create mode 100644 gps/utils/msg_q.c create mode 100644 gps/utils/msg_q.h create mode 100644 gpt-utils/Android.bp create mode 100644 gpt-utils/gpt-utils.cpp create mode 100644 gpt-utils/gpt-utils.h create mode 100644 gpt-utils/recovery-ufs-bsg.cpp create mode 100644 gpt-utils/recovery-ufs-bsg.h create mode 100644 gpt-utils/sparse_crc32.cpp create mode 100644 gpt-utils/sparse_crc32.h create mode 100644 libhidl/Android.bp create mode 100644 libinit/include/libinit_dalvik_heap.h create mode 100644 libinit/include/libinit_utils.h create mode 100644 libinit/include/libinit_variant.h create mode 100644 libinit/init_xiaomi_holi.cpp create mode 100644 libinit/libinit_dalvik_heap.cpp create mode 100644 libinit/libinit_utils.cpp create mode 100644 libinit/libinit_variant.cpp delete mode 100644 lineage.dependencies create mode 100644 manifest.xml create mode 100644 manifest_nfc.xml create mode 100644 odm.prop create mode 100644 org.ifaa.android.manager/Android.bp create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManager.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerFactory.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerImpl.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV2.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV3.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV4.java create mode 100644 org.ifaa.android.manager/src/org/ifaa/android/manager/IIFAAService.aidl delete mode 100644 overlay-lineage/frameworks/base/packages/SystemUI/res/values/config.xml delete mode 100644 overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml delete mode 100644 overlay-lineage/packages/apps/Settings/res/values/config.xml delete mode 100644 overlay/frameworks/base/core/res/res/values/config.xml delete mode 100644 overlay/frameworks/base/core/res/res/values/dimens.xml delete mode 100644 overlay/frameworks/base/core/res/res/xml/power_profile.xml delete mode 100644 overlay/frameworks/base/packages/SystemUI/res/values/config.xml delete mode 100644 overlay/frameworks/base/packages/SystemUI/res/values/dimens.xml delete mode 100644 overlay/packages/apps/Settings/res/values/config.xml create mode 100644 permissions/privapp-permissions-hotword.xml create mode 100644 releasetools.py create mode 100644 rootdir/Android.mk create mode 100755 rootdir/bin/init.class_main.sh create mode 100755 rootdir/bin/init.kernel.post_boot-blair.sh create mode 100755 rootdir/bin/init.kernel.post_boot-holi.sh create mode 100755 rootdir/bin/init.kernel.post_boot.sh create mode 100755 rootdir/bin/init.mi.btmac.sh create mode 100755 rootdir/bin/init.qcom.post_boot.sh create mode 100755 rootdir/bin/init.qcom.sh create mode 100755 rootdir/bin/vendor_modprobe.sh create mode 100644 rootdir/etc/charger_fstab.qti create mode 100644 rootdir/etc/fstab.default create mode 100644 rootdir/etc/fstab.emmc create mode 100644 rootdir/etc/init.batterysecret.rc create mode 100644 rootdir/etc/init.nfc.rc create mode 100644 rootdir/etc/init.qcom.rc create mode 100644 rootdir/etc/init.qti.kernel.rc create mode 100644 rootdir/etc/init.qti.ufs.rc create mode 100644 rootdir/etc/init.recovery.qcom.rc create mode 100644 rootdir/etc/init.target.rc create mode 100644 rootdir/etc/ueventd.qcom.rc create mode 100644 sensors/Android.bp create mode 100644 sensors/HalProxy.cpp create mode 100644 sensors/HalProxyCallback.cpp create mode 100644 sensors/android.hardware.sensors@2.1-service.xiaomi_holi-multihal.rc create mode 100644 sensors/android.hardware.sensors@2.1.xiaomi_holi-multihal.xml create mode 100644 sensors/service.cpp create mode 100644 sepolicy/private/file_contexts create mode 100644 sepolicy/public/attributes create mode 100644 sepolicy/public/property.te create mode 100644 sepolicy/public/property_contexts create mode 100644 sepolicy/vendor/adsprpcd.te create mode 100644 sepolicy/vendor/app.te create mode 100644 sepolicy/vendor/batterysecret.te create mode 100644 sepolicy/vendor/device.te create mode 100644 sepolicy/vendor/file.te create mode 100644 sepolicy/vendor/file_contexts create mode 100644 sepolicy/vendor/genfs_contexts create mode 100644 sepolicy/vendor/hal_audio_default.te create mode 100644 sepolicy/vendor/hal_bluetooth_default.te create mode 100644 sepolicy/vendor/hal_bootctl_default.te create mode 100644 sepolicy/vendor/hal_camera_default.te create mode 100644 sepolicy/vendor/hal_fingerprint_default.te create mode 100644 sepolicy/vendor/hal_health_default.te create mode 100644 sepolicy/vendor/hal_ir_default.te create mode 100644 sepolicy/vendor/hal_mlipay.te create mode 100644 sepolicy/vendor/hal_nfc_default.te create mode 100644 sepolicy/vendor/hal_perf_default.te create mode 100644 sepolicy/vendor/hal_power_default.te create mode 100644 sepolicy/vendor/hal_sensors_default.te create mode 100644 sepolicy/vendor/hal_wifi_default.te create mode 100644 sepolicy/vendor/hwservice_contexts create mode 100644 sepolicy/vendor/mi_thermald.te create mode 100644 sepolicy/vendor/property.te create mode 100644 sepolicy/vendor/property_contexts create mode 100644 sepolicy/vendor/qti_init_shell.te create mode 100644 sepolicy/vendor/recovery.te create mode 100644 sepolicy/vendor/sensors.te create mode 100644 sepolicy/vendor/system_app.te create mode 100644 sepolicy/vendor/tee.te create mode 100644 sepolicy/vendor/thermal-engine.te create mode 100644 sepolicy/vendor/vendor_modprobe.te create mode 100644 sepolicy/vendor/vendor_qti_init_shell.te create mode 100644 system.prop create mode 100644 system_ext.prop create mode 100644 vendor.prop create mode 100644 vibrator/Android.bp create mode 100644 vibrator/Vibrator.cpp create mode 100644 vibrator/excluded-input-devices.xml create mode 100644 vibrator/include/Vibrator.h create mode 100644 vibrator/service.cpp create mode 100644 vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.rc create mode 100644 vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.xml create mode 100644 wifi/WCNSS_qcom_cfg.ini create mode 100644 wifi/p2p_supplicant_overlay.conf create mode 100644 wifi/wpa_supplicant_overlay.conf diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..2722586 --- /dev/null +++ b/Android.bp @@ -0,0 +1,6 @@ +soong_namespace { + imports: [ + "hardware/qcom-caf/bootctrl", + "hardware/xiaomi", + ], +} diff --git a/Android.mk b/Android.mk index 5f8f29f..92b17a7 100644 --- a/Android.mk +++ b/Android.mk @@ -6,6 +6,112 @@ LOCAL_PATH := $(call my-dir) -ifeq ($(TARGET_DEVICE),veux) +ifneq ($(filter peux veux,$(TARGET_DEVICE)),) + include $(call all-makefiles-under,$(LOCAL_PATH)) -endif + +include $(CLEAR_VARS) + +FIRMWARE_MOUNT_POINT := $(TARGET_OUT_VENDOR)/firmware_mnt +$(FIRMWARE_MOUNT_POINT): $(LOCAL_INSTALLED_MODULE) + @echo "Creating $(FIRMWARE_MOUNT_POINT)" + @mkdir -p $(TARGET_OUT_VENDOR)/firmware_mnt + +BT_FIRMWARE_MOUNT_POINT := $(TARGET_OUT_VENDOR)/bt_firmware +$(BT_FIRMWARE_MOUNT_POINT): $(LOCAL_INSTALLED_MODULE) + @echo "Creating $(BT_FIRMWARE_MOUNT_POINT)" + @mkdir -p $(TARGET_OUT_VENDOR)/bt_firmware + +DSP_MOUNT_POINT := $(TARGET_OUT_VENDOR)/dsp +$(DSP_MOUNT_POINT): $(LOCAL_INSTALLED_MODULE) + @echo "Creating $(DSP_MOUNT_POINT)" + @mkdir -p $(TARGET_OUT_VENDOR)/dsp + +VM_SYSTEM_MOUNT_POINT := $(TARGET_OUT_VENDOR)/vm-system +$(VM_SYSTEM_MOUNT_POINT): $(LOCAL_INSTALLED_MODULE) + @echo "Creating $(VM_SYSTEM_MOUNT_POINT)" + @mkdir -p $(TARGET_OUT_VENDOR)/vm-system + +ALL_DEFAULT_INSTALLED_MODULES += $(FIRMWARE_MOUNT_POINT) +ALL_DEFAULT_INSTALLED_MODULES += $(BT_FIRMWARE_MOUNT_POINT) +ALL_DEFAULT_INSTALLED_MODULES += $(DSP_MOUNT_POINT) +ALL_DEFAULT_INSTALLED_MODULES += $(VM_SYSTEM_MOUNT_POINT) + +RFS_MSM_ADSP_SYMLINKS := $(TARGET_OUT_VENDOR)/rfs/msm/adsp/ +$(RFS_MSM_ADSP_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Creating RFS MSM ADSP folder structure: $@" + @rm -rf $@/* + @mkdir -p $(dir $@)/readonly/vendor + $(hide) ln -sf /data/vendor/tombstones/rfs/lpass $@/ramdumps + $(hide) ln -sf /mnt/vendor/persist/rfs/msm/adsp $@/readwrite + $(hide) ln -sf /mnt/vendor/persist/rfs/shared $@/shared + $(hide) ln -sf /mnt/vendor/persist/hlos_rfs/shared $@/hlos + $(hide) ln -sf /vendor/firmware_mnt $@/readonly/firmware + $(hide) ln -sf /vendor/firmware $@/readonly/vendor/firmware + +RFS_MSM_CDSP_SYMLINKS := $(TARGET_OUT_VENDOR)/rfs/msm/cdsp/ +$(RFS_MSM_CDSP_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Creating RFS MSM CDSP folder structure: $@" + @rm -rf $@/* + @mkdir -p $(dir $@)/readonly/vendor + $(hide) ln -sf /data/vendor/tombstones/rfs/cdsp $@/ramdumps + $(hide) ln -sf /mnt/vendor/persist/rfs/msm/cdsp $@/readwrite + $(hide) ln -sf /mnt/vendor/persist/rfs/shared $@/shared + $(hide) ln -sf /mnt/vendor/persist/hlos_rfs/shared $@/hlos + $(hide) ln -sf /vendor/firmware_mnt $@/readonly/firmware + $(hide) ln -sf /vendor/firmware $@/readonly/vendor/firmware + +RFS_MSM_MPSS_SYMLINKS := $(TARGET_OUT_VENDOR)/rfs/msm/mpss/ +$(RFS_MSM_MPSS_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Creating RFS MSM MPSS folder structure: $@" + @rm -rf $@/* + @mkdir -p $(dir $@)/readonly/vendor + $(hide) ln -sf /data/vendor/tombstones/rfs/modem $@/ramdumps + $(hide) ln -sf /mnt/vendor/persist/rfs/msm/mpss $@/readwrite + $(hide) ln -sf /mnt/vendor/persist/rfs/shared $@/shared + $(hide) ln -sf /mnt/vendor/persist/hlos_rfs/shared $@/hlos + $(hide) ln -sf /vendor/firmware_mnt $@/readonly/firmware + $(hide) ln -sf /vendor/firmware $@/readonly/vendor/firmware + +RFS_MSM_SLPI_SYMLINKS := $(TARGET_OUT_VENDOR)/rfs/msm/slpi/ +$(RFS_MSM_SLPI_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Creating RFS MSM SLPI folder structure: $@" + @rm -rf $@/* + @mkdir -p $(dir $@)/readonly/vendor + $(hide) ln -sf /data/vendor/tombstones/rfs/slpi $@/ramdumps + $(hide) ln -sf /mnt/vendor/persist/rfs/msm/slpi $@/readwrite + $(hide) ln -sf /mnt/vendor/persist/rfs/shared $@/shared + $(hide) ln -sf /mnt/vendor/persist/hlos_rfs/shared $@/hlos + $(hide) ln -sf /vendor/firmware_mnt $@/readonly/firmware + $(hide) ln -sf /vendor/firmware $@/readonly/vendor/firmware + +WIFI_FIRMWARE_SYMLINKS := $(TARGET_OUT_VENDOR)/firmware/wlan/qca_cld/ +$(WIFI_FIRMWARE_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "Creating wifi firmware symlinks: $@" + mkdir -p $@ + $(hide) ln -sf /vendor/etc/wifi/WCNSS_qcom_cfg.ini $@/WCNSS_qcom_cfg.ini + +ALL_DEFAULT_INSTALLED_MODULES += $(RFS_MSM_ADSP_SYMLINKS) $(RFS_MSM_CDSP_SYMLINKS) $(RFS_MSM_MPSS_SYMLINKS) $(RFS_MSM_SLPI_SYMLINKS) +ALL_DEFAULT_INSTALLED_MODULES += $(WIFI_FIRMWARE_SYMLINKS) + +# Symlinks +EGL_LIBRARIES := \ + libEGL_adreno.so \ + libGLESv2_adreno.so \ + libq3dtools_adreno.so + +EGL_32_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR)/lib/,$(notdir $(EGL_LIBRARIES))) +$(EGL_32_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "EGL 32 lib link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf egl/$(notdir $@) $@ + +EGL_64_SYMLINKS := $(addprefix $(TARGET_OUT_VENDOR)/lib64/,$(notdir $(EGL_LIBRARIES))) +$(EGL_64_SYMLINKS): $(LOCAL_INSTALLED_MODULE) + @echo "EGL lib link: $@" + @mkdir -p $(dir $@) + @rm -rf $@ + $(hide) ln -sf egl/$(notdir $@) $@ + +endif \ No newline at end of file diff --git a/BoardConfig.mk b/BoardConfig.mk index ab2d7b7..899135b 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -6,22 +6,247 @@ DEVICE_PATH := device/xiaomi/veux -# Inherit from sm6375-common -include device/xiaomi/sm6375-common/BoardConfigCommon.mk +# A/B +AB_OTA_UPDATER := true + +AB_OTA_PARTITIONS += \ + boot \ + dtbo \ + odm \ + product \ + system \ + system_ext \ + vbmeta \ + vbmeta_system \ + vendor \ + vendor_boot + +# Architecture +TARGET_ARCH := arm64 +TARGET_ARCH_VARIANT := armv8-a +TARGET_CPU_ABI := arm64-v8a +TARGET_CPU_ABI2 := +TARGET_CPU_VARIANT := generic +TARGET_CPU_VARIANT_RUNTIME := kryo300 + +TARGET_2ND_ARCH := arm +TARGET_2ND_ARCH_VARIANT := armv8-a +TARGET_2ND_CPU_ABI := armeabi-v7a +TARGET_2ND_CPU_ABI2 := armeabi +TARGET_2ND_CPU_VARIANT := generic +TARGET_2ND_CPU_VARIANT_RUNTIME := cortex-a75 + +# Audio +AUDIO_FEATURE_ENABLED_EXTN_FORMATS := true +AUDIO_FEATURE_ENABLED_HDMI_SPK := true +AUDIO_FEATURE_ENABLED_PROXY_DEVICE := true + +AUDIO_FEATURE_ENABLED_EXTENDED_COMPRESS_FORMAT := true +AUDIO_FEATURE_ENABLED_GKI := true +BOARD_SUPPORTS_SOUND_TRIGGER := true + +# Audio Policy +USE_CUSTOM_AUDIO_POLICY := 1 +USE_XML_AUDIO_POLICY_CONF := 1 + +# APEX +DEXPREOPT_GENERATE_APEX_IMAGE := true + +# Assert +TARGET_OTA_ASSERT_DEVICE := peux,veux # Build Broken BUILD_BROKEN_DUP_RULES := true BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES := true -# Display +# Bootloader +TARGET_BOOTLOADER_BOARD_NAME := holi +TARGET_NO_BOOTLOADER := true + +# Bluetooth +BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := $(DEVICE_PATH)/bluetooth/include + +# Camera +TARGET_USES_QTI_CAMERA_DEVICE := true + +# Display Density TARGET_SCREEN_DENSITY := 440 +# DRM +TARGET_ENABLE_MEDIADRM_64 := true + +# Filesystem +TARGET_FS_CONFIG_GEN := $(DEVICE_PATH)/config.fs + +# GPS +BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := default +LOC_HIDL_VERSION := 4.0 + +# HIDL +DEVICE_MATRIX_FILE := $(DEVICE_PATH)/compatibility_matrix.xml +DEVICE_MANIFEST_FILE := $(DEVICE_PATH)/manifest.xml +DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE := $(DEVICE_PATH)/framework_compatibility_matrix.xml + +ODM_MANIFEST_SKUS += nfc +ODM_MANIFEST_NFC_FILES := $(DEVICE_PATH)/manifest_nfc.xml + # Init TARGET_INIT_VENDOR_LIB := //$(DEVICE_PATH):init_xiaomi_veux TARGET_RECOVERY_DEVICE_MODULES := init_xiaomi_veux -# OTA assert -TARGET_OTA_ASSERT_DEVICE := peux,veux +# Media +TARGET_USES_ION := true +TARGET_DISABLED_UBWC := true + +# Kernel +BOARD_INCLUDE_DTB_IN_BOOTIMG := true +BOARD_KERNEL_BASE := 0x00000000 +BOARD_KERNEL_IMAGE_NAME := Image +BOARD_KERNEL_PAGESIZE := 4096 +BOARD_KERNEL_SEPARATED_DTBO := true +KERNEL_LD := LD=ld.lld + +BOARD_BOOT_HEADER_VERSION := 3 +BOARD_MKBOOTIMG_ARGS += --header_version $(BOARD_BOOT_HEADER_VERSION) + +TARGET_KERNEL_ADDITIONAL_FLAGS := DTC_EXT=$(shell pwd)/prebuilts/misc/linux-x86/dtc/dtc LLVM=1 +TARGET_KERNEL_SOURCE := kernel/xiaomi/sm6375 + +BOARD_KERNEL_CMDLINE += androidboot.console=ttyMSM0 +BOARD_KERNEL_CMDLINE += androidboot.hardware=qcom +BOARD_KERNEL_CMDLINE += androidboot.memcg=1 +BOARD_KERNEL_CMDLINE += androidboot.usbcontroller=4e00000.dwc3 +BOARD_KERNEL_CMDLINE += cgroup.memory=nokmem,nosocket +BOARD_KERNEL_CMDLINE += console=ttyMSM0,115200n8 +BOARD_KERNEL_CMDLINE += earlycon=msm_geni_serial,0x04C8C000 +BOARD_KERNEL_CMDLINE += loop.max_part=7 +BOARD_KERNEL_CMDLINE += msm_rtb.filter=0x237 +BOARD_KERNEL_CMDLINE += service_locator.enable=1 +BOARD_KERNEL_CMDLINE += swiotlb=0 +BOARD_KERNEL_CMDLINE += pcie_ports=compat +BOARD_KERNEL_CMDLINE += iptable_raw.raw_before_defrag=1 +BOARD_KERNEL_CMDLINE += ip6table_raw.raw_before_defrag=1 +BOARD_KERNEL_CMDLINE += video=vfb:640x400,bpp=32,memsize=3072000 +BOARD_KERNEL_CMDLINE += androidboot.init_fatal_reboot_target=recovery + +# Prebuilt Kernel +BOARD_KERNEL_BINARIES := kernel +BOARD_PREBUILT_DTBOIMAGE := $(DEVICE_PATH)-kernel/dtbo.img +TARGET_FORCE_PREBUILT_KERNEL := true +TARGET_PREBUILT_KERNEL := $(DEVICE_PATH)-kernel/kernel +TARGET_KERNEL_CONFIG := holi_QGKI +TARGET_PREBUILT_DTB := $(DEVICE_PATH)-kernel/dtb.img +PRODUCT_COPY_FILES += \ + $(DEVICE_PATH)-kernel/dtb.img:$(TARGET_COPY_OUT)/dtb.img \ + $(DEVICE_PATH)-kernel/kernel:kernel \ + $(call find-copy-subdir-files,*,$(DEVICE_PATH)-kernel/ramdisk-modules/,$(TARGET_COPY_OUT_VENDOR_RAMDISK)/lib/modules) \ + $(call find-copy-subdir-files,*,$(DEVICE_PATH)-kernel/vendor-modules/,$(TARGET_COPY_OUT_VENDOR)/lib/modules) + +# Partitions +BOARD_BOOTIMAGE_PARTITION_SIZE := 134217728 +BOARD_DTBOIMG_PARTITION_SIZE := 8388608 +BOARD_SUPER_PARTITION_SIZE := 9126805504 +BOARD_USERDATAIMAGE_PARTITION_SIZE := 109156577280 +BOARD_VENDOR_BOOTIMAGE_PARTITION_SIZE := 100663296 + +BOARD_SUPER_PARTITION_GROUPS := qti_dynamic_partitions +BOARD_QTI_DYNAMIC_PARTITIONS_PARTITION_LIST := odm system system_ext vendor product +BOARD_QTI_DYNAMIC_PARTITIONS_SIZE := 9122611200 # BOARD_SUPER_PARTITION_SIZE - 4MB + +BOARD_ODMIMAGE_FILE_SYSTEM_TYPE := ext4 +BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE := ext4 +BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE := ext4 +BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := ext4 +BOARD_USERDATAIMAGE_FILE_SYSTEM_TYPE := f2fs +BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4 + +ifeq ($(WITH_GMS),true) +BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE := 104857600 +BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE := 104857600 +else +BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT := -1 +BOARD_PRODUCTIMAGE_PARTITION_RESERVED_SIZE := 1887436800 +BOARD_SYSTEMIMAGE_EXTFS_INODE_COUNT := -1 +BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE := 1887436800 +endif +BOARD_SYSTEM_EXTIMAGE_PARTITION_RESERVED_SIZE := 104857600 +BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE := 104857600 + +TARGET_COPY_OUT_ODM := odm +TARGET_COPY_OUT_SYSTEM_EXT := system_ext +TARGET_COPY_OUT_VENDOR := vendor +TARGET_COPY_OUT_PRODUCT := product + +# Partitions +BOARD_USES_METADATA_PARTITION := true +BOARD_FLASH_BLOCK_SIZE := 131072 + +# Platform +BOARD_USES_QCOM_HARDWARE := true +TARGET_BOARD_PLATFORM := holi + +# Properties +TARGET_ODM_PROP += $(DEVICE_PATH)/odm.prop +TARGET_SYSTEM_EXT_PROP += $(DEVICE_PATH)/system_ext.prop +TARGET_SYSTEM_PROP += $(DEVICE_PATH)/system.prop +TARGET_VENDOR_PROP += $(DEVICE_PATH)/vendor.prop + +# Power +TARGET_TAP_TO_WAKE_NODE := "/proc/tp_gesture" + +# Recovery +BOARD_INCLUDE_RECOVERY_DTBO := true +BOARD_USES_RECOVERY_AS_BOOT := true +TARGET_RECOVERY_FSTAB := $(DEVICE_PATH)/rootdir/etc/fstab.default +TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888" +TARGET_USERIMAGES_USE_EXT4 := true +TARGET_USERIMAGES_USE_F2FS := true +TARGET_USES_MKE2FS := true + +# Releasetools +TARGET_RELEASETOOLS_EXTENSIONS := $(DEVICE_PATH) + +# Render Script +OVERRIDE_RS_DRIVER := libRSDriver_adreno.so + +# RIL +ENABLE_VENDOR_RIL_SERVICE := true + +# Security Patch Level +VENDOR_SECURITY_PATCH := 2022-02-01 + +# Sepolicy +include device/qcom/sepolicy_vndr/SEPolicy.mk +SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/private +SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/public +BOARD_VENDOR_SEPOLICY_DIRS += $(DEVICE_PATH)/sepolicy/vendor + +# Verified Boot +BOARD_AVB_ENABLE := true +BOARD_AVB_MAKE_VBMETA_IMAGE_ARGS += --flags 3 +BOARD_AVB_VBMETA_SYSTEM := system system_ext product +BOARD_AVB_VBMETA_SYSTEM_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem +BOARD_AVB_VBMETA_SYSTEM_ALGORITHM := SHA256_RSA2048 +BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP) +BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX_LOCATION := 1 +BOARD_AVB_RECOVERY_KEY_PATH := external/avb/test/data/testkey_rsa4096.pem +BOARD_AVB_RECOVERY_ALGORITHM := SHA256_RSA4096 +BOARD_AVB_RECOVERY_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP) +BOARD_AVB_RECOVERY_ROLLBACK_INDEX_LOCATION := 1 + +# WiFi +BOARD_WLAN_DEVICE := qcwcn +BOARD_HOSTAPD_DRIVER := NL80211 +BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +BOARD_WPA_SUPPLICANT_DRIVER := NL80211 +BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE) +WIFI_DRIVER_DEFAULT := wlan +WIFI_DRIVER_STATE_CTRL_PARAM := "/dev/wlan" +WIFI_DRIVER_STATE_OFF := "OFF" +WIFI_DRIVER_STATE_ON := "ON" +WIFI_HIDL_FEATURE_DUAL_INTERFACE := true +WIFI_HIDL_UNIFIED_SUPPLICANT_SERVICE_RC_ENTRY := true +WPA_SUPPLICANT_VERSION := VER_0_8_X # Inherit from the proprietary version include vendor/xiaomi/veux/BoardConfigVendor.mk diff --git a/README.md b/README.md index a4b117c..507de21 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ | CPU | Octa-core (2x2.2 GHz Kryo 660 Gold & 6x1.7 GHz Kryo 660 Silver) | | Chipset | Qualcomm SM6375 Snapdragon 695G (6 nm) | | GPU | Adreno 619 | -| Memory | 4 GB / 8 GB | +| Memory | 6 GB / 8 GB | | Shipped Software | Android 11, MIUI 13 | -| Storage | 64 GB / 256 GB | +| Storage | 128 GB / 256 GB | | Battery | 5000 mAh | | Dimensions | 165.1 x 76.4 x 9.3 mm (6.5 x 3.01 x 0.37 in) | | Display | 6.67 inches, 107.4 cm2 (~86.0% screen-to-body ratio) | @@ -21,4 +21,4 @@ ## Device Picture -![POCO X4 Pro 5G/Redmi Note 11E Pro/Redmi Note 11 Pro 5G/Redmi Note 11 Pro+ 5G](https://fdn2.gsmarena.com/vv/pics/xiaomi/xiaomi-poco-x4-pro-2.jpg "POCO X4 Pro 5G/Redmi Note 11E Pro/Redmi Note 11 Pro 5G/Redmi Note 11 Pro+ 5G") +![POCO X4 Pro 5G/Redmi Note 11E Pro/Redmi Note 11 Pro 5G/Redmi Note 11 Pro+ 5G](https://i.ibb.co/4syxpfw/330608dc148bfa50f6326d996d6c8e8b.png "POCO X4 Pro 5G/Redmi Note 11E Pro/Redmi Note 11 Pro 5G/Redmi Note 11 Pro+ 5G") diff --git a/audio/audio_policy_configuration.xml b/audio/audio_policy_configuration.xml new file mode 100644 index 0000000..d01c2c1 --- /dev/null +++ b/audio/audio_policy_configuration.xml @@ -0,0 +1,384 @@ + + + + + + + + + + + + + + + Earpiece + Speaker + Telephony Tx + Built-In Mic + Built-In Back Mic + FM Tuner + Telephony Rx + + Speaker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/biometrics/Android.bp b/biometrics/Android.bp new file mode 100644 index 0000000..f5f26c7 --- /dev/null +++ b/biometrics/Android.bp @@ -0,0 +1,21 @@ +cc_binary { + name: "android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + init_rc: ["android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.rc"], + vintf_fragments: ["android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.xml"], + srcs: [ + "BiometricsFingerprint.cpp", + "service.cpp", + ], + shared_libs: [ + "libcutils", + "liblog", + "libhidlbase", + "libhardware", + "libutils", + "android.hardware.biometrics.fingerprint@2.1", + "//hardware/xiaomi:vendor.xiaomi.hardware.fingerprintextension@1.0", + ], + vendor: true, +} diff --git a/biometrics/BiometricsFingerprint.cpp b/biometrics/BiometricsFingerprint.cpp new file mode 100644 index 0000000..668c220 --- /dev/null +++ b/biometrics/BiometricsFingerprint.cpp @@ -0,0 +1,383 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi" +#define LOG_VERBOSE "android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi" + +#include + +#include "xiaomi_fingerprint.h" +#include "BiometricsFingerprint.h" + +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +// Supported fingerprint HAL version +static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 1); + +// List of fingerprint HALs +static const char *kHALClasses[] = { + "fpc", + "goodix", + "silead", +}; + +using RequestStatus = + android::hardware::biometrics::fingerprint::V2_1::RequestStatus; + +BiometricsFingerprint *BiometricsFingerprint::sInstance = nullptr; + +BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr), mDevice(nullptr) { + sInstance = this; // keep track of the most recent instance + for (const auto& class_name : kHALClasses) { + mDevice = openHal(class_name); + if (!mDevice) { + ALOGE("Can't open HAL module, class %s", class_name); + } else { + ALOGI("Opened fingerprint HAL, class %s", class_name); + property_set("persist.vendor.sys.fp.vendor", class_name); // fix AliPay TouchID + break; + } + } +} + +BiometricsFingerprint::~BiometricsFingerprint() { + ALOGV("~BiometricsFingerprint()"); + if (mDevice == nullptr) { + ALOGE("No valid device"); + return; + } + int err; + if (0 != (err = mDevice->common.close( + reinterpret_cast(mDevice)))) { + ALOGE("Can't close fingerprint module, error: %d", err); + return; + } + mDevice = nullptr; +} + +Return BiometricsFingerprint::ErrorFilter(int32_t error) { + switch(error) { + case 0: return RequestStatus::SYS_OK; + case -2: return RequestStatus::SYS_ENOENT; + case -4: return RequestStatus::SYS_EINTR; + case -5: return RequestStatus::SYS_EIO; + case -11: return RequestStatus::SYS_EAGAIN; + case -12: return RequestStatus::SYS_ENOMEM; + case -13: return RequestStatus::SYS_EACCES; + case -14: return RequestStatus::SYS_EFAULT; + case -16: return RequestStatus::SYS_EBUSY; + case -22: return RequestStatus::SYS_EINVAL; + case -28: return RequestStatus::SYS_ENOSPC; + case -110: return RequestStatus::SYS_ETIMEDOUT; + default: + ALOGE("An unknown error returned from fingerprint vendor library: %d", error); + return RequestStatus::SYS_UNKNOWN; + } +} + +// Translate from errors returned by traditional HAL (see fingerprint.h) to +// HIDL-compliant FingerprintError. +FingerprintError BiometricsFingerprint::VendorErrorFilter(int32_t error, + int32_t* vendorCode) { + *vendorCode = 0; + switch(error) { + case FINGERPRINT_ERROR_HW_UNAVAILABLE: + return FingerprintError::ERROR_HW_UNAVAILABLE; + case FINGERPRINT_ERROR_UNABLE_TO_PROCESS: + return FingerprintError::ERROR_UNABLE_TO_PROCESS; + case FINGERPRINT_ERROR_TIMEOUT: + return FingerprintError::ERROR_TIMEOUT; + case FINGERPRINT_ERROR_NO_SPACE: + return FingerprintError::ERROR_NO_SPACE; + case FINGERPRINT_ERROR_CANCELED: + return FingerprintError::ERROR_CANCELED; + case FINGERPRINT_ERROR_UNABLE_TO_REMOVE: + return FingerprintError::ERROR_UNABLE_TO_REMOVE; + case FINGERPRINT_ERROR_LOCKOUT: + return FingerprintError::ERROR_LOCKOUT; + default: + if (error >= FINGERPRINT_ERROR_VENDOR_BASE) { + // vendor specific code. + *vendorCode = error - FINGERPRINT_ERROR_VENDOR_BASE; + return FingerprintError::ERROR_VENDOR; + } + } + ALOGE("Unknown error from fingerprint vendor library: %d", error); + return FingerprintError::ERROR_UNABLE_TO_PROCESS; +} + +// Translate acquired messages returned by traditional HAL (see fingerprint.h) +// to HIDL-compliant FingerprintAcquiredInfo. +FingerprintAcquiredInfo BiometricsFingerprint::VendorAcquiredFilter( + int32_t info, int32_t* vendorCode) { + *vendorCode = 0; + switch(info) { + case FINGERPRINT_ACQUIRED_GOOD: + return FingerprintAcquiredInfo::ACQUIRED_GOOD; + case FINGERPRINT_ACQUIRED_PARTIAL: + return FingerprintAcquiredInfo::ACQUIRED_PARTIAL; + case FINGERPRINT_ACQUIRED_INSUFFICIENT: + return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; + case FINGERPRINT_ACQUIRED_IMAGER_DIRTY: + return FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY; + case FINGERPRINT_ACQUIRED_TOO_SLOW: + return FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW; + case FINGERPRINT_ACQUIRED_TOO_FAST: + return FingerprintAcquiredInfo::ACQUIRED_TOO_FAST; + default: + if (info >= FINGERPRINT_ACQUIRED_VENDOR_BASE) { + // vendor specific code. + *vendorCode = info - FINGERPRINT_ACQUIRED_VENDOR_BASE; + return FingerprintAcquiredInfo::ACQUIRED_VENDOR; + } + } + ALOGE("Unknown acquiredmsg from fingerprint vendor library: %d", info); + return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; +} + +Return BiometricsFingerprint::setNotify( + const sp& clientCallback) { + std::lock_guard lock(mClientCallbackMutex); + mClientCallback = clientCallback; + // This is here because HAL 2.1 doesn't have a way to propagate a + // unique token for its driver. Subsequent versions should send a unique + // token for each call to setNotify(). This is fine as long as there's only + // one fingerprint device on the platform. + return reinterpret_cast(mDevice); +} + +Return BiometricsFingerprint::preEnroll() { + return mDevice->pre_enroll(mDevice); +} + +Return BiometricsFingerprint::enroll(const hidl_array& hat, + uint32_t gid, uint32_t timeoutSec) { + const hw_auth_token_t* authToken = + reinterpret_cast(hat.data()); + return ErrorFilter(mDevice->enroll(mDevice, authToken, gid, timeoutSec)); +} + +Return BiometricsFingerprint::postEnroll() { + return ErrorFilter(mDevice->post_enroll(mDevice)); +} + +Return BiometricsFingerprint::getAuthenticatorId() { + return mDevice->get_authenticator_id(mDevice); +} + +Return BiometricsFingerprint::cancel() { + return ErrorFilter(mDevice->cancel(mDevice)); +} + +Return BiometricsFingerprint::enumerate() { + return ErrorFilter(mDevice->enumerate(mDevice)); +} + +Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { + return ErrorFilter(mDevice->remove(mDevice, gid, fid)); +} + +Return BiometricsFingerprint::setActiveGroup(uint32_t gid, + const hidl_string& storePath) { + if (storePath.size() >= PATH_MAX || storePath.size() <= 0) { + ALOGE("Bad path length: %zd", storePath.size()); + return RequestStatus::SYS_EINVAL; + } + if (access(storePath.c_str(), W_OK)) { + return RequestStatus::SYS_EINVAL; + } + + return ErrorFilter(mDevice->set_active_group(mDevice, gid, + storePath.c_str())); +} + +Return BiometricsFingerprint::authenticate(uint64_t operationId, + uint32_t gid) { + return ErrorFilter(mDevice->authenticate(mDevice, operationId, gid)); +} + +IBiometricsFingerprint* BiometricsFingerprint::getInstance() { + if (!sInstance) { + sInstance = new BiometricsFingerprint(); + } + return sInstance; +} + +IXiaomiFingerprint* BiometricsFingerprint::getXiaomiInstance() { + if (!sInstance) { + sInstance = new BiometricsFingerprint(); + } + return sInstance; +} + +xiaomi_fingerprint_device_t* BiometricsFingerprint::openHal(const char *class_name) { + int err; + const hw_module_t *hw_mdl = nullptr; + ALOGD("Opening fingerprint hal library..."); + if (0 != (err = hw_get_module_by_class(FINGERPRINT_HARDWARE_MODULE_ID, class_name, &hw_mdl))) { + ALOGE("Can't open fingerprint HW Module, class %s, error: %d", class_name, err); + return nullptr; + } + + if (hw_mdl == nullptr) { + ALOGE("No valid fingerprint module, class %s", class_name); + return nullptr; + } + + fingerprint_module_t const *module = + reinterpret_cast(hw_mdl); + if (module->common.methods->open == nullptr) { + ALOGE("No valid open method, class %s", class_name); + return nullptr; + } + + hw_device_t *device = nullptr; + + if (0 != (err = module->common.methods->open(hw_mdl, nullptr, &device))) { + ALOGE("Can't open fingerprint methods, class %s, error: %d", class_name, err); + return nullptr; + } + + if (kVersion != device->version) { + // enforce version on new devices because of HIDL@2.1 translation layer + ALOGE("Wrong fp version, class %s. Expected %d, got %d", class_name, kVersion, device->version); + return nullptr; + } + + xiaomi_fingerprint_device_t* fp_device = + reinterpret_cast(device); + + if (0 != (err = + fp_device->set_notify(fp_device, BiometricsFingerprint::notify))) { + ALOGE("Can't register fingerprint module callback, class %s, error: %d", class_name, err); + return nullptr; + } + + return fp_device; +} + +void BiometricsFingerprint::notify(const fingerprint_msg_t *msg) { + BiometricsFingerprint* thisPtr = static_cast( + BiometricsFingerprint::getInstance()); + std::lock_guard lock(thisPtr->mClientCallbackMutex); + if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) { + ALOGE("Receiving callbacks before the client callback is registered."); + return; + } + const uint64_t devId = reinterpret_cast(thisPtr->mDevice); + switch (msg->type) { + case FINGERPRINT_ERROR: { + int32_t vendorCode = 0; + FingerprintError result = VendorErrorFilter(msg->data.error, &vendorCode); + ALOGD("onError(%d)", result); + if (!thisPtr->mClientCallback->onError(devId, result, vendorCode).isOk()) { + ALOGE("failed to invoke fingerprint onError callback"); + } + } + break; + case FINGERPRINT_ACQUIRED: { + int32_t vendorCode = 0; + FingerprintAcquiredInfo result = + VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode); + ALOGD("onAcquired(%d)", result); + if (!thisPtr->mClientCallback->onAcquired(devId, result, vendorCode).isOk()) { + ALOGE("failed to invoke fingerprint onAcquired callback"); + } + } + break; + case FINGERPRINT_TEMPLATE_ENROLLING: + ALOGD("onEnrollResult(fid=%d, gid=%d, rem=%d)", + msg->data.enroll.finger.fid, + msg->data.enroll.finger.gid, + msg->data.enroll.samples_remaining); + if (!thisPtr->mClientCallback->onEnrollResult(devId, + msg->data.enroll.finger.fid, + msg->data.enroll.finger.gid, + msg->data.enroll.samples_remaining).isOk()) { + ALOGE("failed to invoke fingerprint onEnrollResult callback"); + } + break; + case FINGERPRINT_TEMPLATE_REMOVED: + ALOGD("onRemove(fid=%d, gid=%d, rem=%d)", + msg->data.removed.finger.fid, + msg->data.removed.finger.gid, + msg->data.removed.remaining_templates); + if (!thisPtr->mClientCallback->onRemoved(devId, + msg->data.removed.finger.fid, + msg->data.removed.finger.gid, + msg->data.removed.remaining_templates).isOk()) { + ALOGE("failed to invoke fingerprint onRemoved callback"); + } + break; + case FINGERPRINT_AUTHENTICATED: + if (msg->data.authenticated.finger.fid != 0) { + ALOGD("onAuthenticated(fid=%d, gid=%d)", + msg->data.authenticated.finger.fid, + msg->data.authenticated.finger.gid); + const uint8_t* hat = + reinterpret_cast(&msg->data.authenticated.hat); + const hidl_vec token( + std::vector(hat, hat + sizeof(msg->data.authenticated.hat))); + if (!thisPtr->mClientCallback->onAuthenticated(devId, + msg->data.authenticated.finger.fid, + msg->data.authenticated.finger.gid, + token).isOk()) { + ALOGE("failed to invoke fingerprint onAuthenticated callback"); + } + } else { + // Not a recognized fingerprint + if (!thisPtr->mClientCallback->onAuthenticated(devId, + msg->data.authenticated.finger.fid, + msg->data.authenticated.finger.gid, + hidl_vec()).isOk()) { + ALOGE("failed to invoke fingerprint onAuthenticated callback"); + } + } + break; + case FINGERPRINT_TEMPLATE_ENUMERATING: + ALOGD("onEnumerate(fid=%d, gid=%d, rem=%d)", + msg->data.enumerated.finger.fid, + msg->data.enumerated.finger.gid, + msg->data.enumerated.remaining_templates); + if (!thisPtr->mClientCallback->onEnumerate(devId, + msg->data.enumerated.finger.fid, + msg->data.enumerated.finger.gid, + msg->data.enumerated.remaining_templates).isOk()) { + ALOGE("failed to invoke fingerprint onEnumerate callback"); + } + break; + } +} + +Return BiometricsFingerprint::extCmd(int32_t cmd, int32_t param) { + return mDevice->extCmd(mDevice, cmd, param); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android diff --git a/biometrics/BiometricsFingerprint.h b/biometrics/BiometricsFingerprint.h new file mode 100644 index 0000000..84e3080 --- /dev/null +++ b/biometrics/BiometricsFingerprint.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H +#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H + +#include +#include +#include "xiaomi_fingerprint.h" +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; +using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; +using ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint; + +struct BiometricsFingerprint : public IBiometricsFingerprint, public IXiaomiFingerprint { +public: + BiometricsFingerprint(); + ~BiometricsFingerprint(); + + // Method to wrap legacy HAL with BiometricsFingerprint class + static IBiometricsFingerprint* getInstance(); + static IXiaomiFingerprint* getXiaomiInstance(); + + // Methods from ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint follow. + Return setNotify(const sp& clientCallback) override; + Return preEnroll() override; + Return enroll(const hidl_array& hat, uint32_t gid, uint32_t timeoutSec) override; + Return postEnroll() override; + Return getAuthenticatorId() override; + Return cancel() override; + Return enumerate() override; + Return remove(uint32_t gid, uint32_t fid) override; + Return setActiveGroup(uint32_t gid, const hidl_string& storePath) override; + Return authenticate(uint64_t operationId, uint32_t gid) override; + + // Methods from ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint follow. + Return extCmd(int32_t cmd, int32_t param) override; + +private: + static xiaomi_fingerprint_device_t* openHal(const char *class_name); + static void notify(const fingerprint_msg_t *msg); /* Static callback for legacy HAL implementation */ + static Return ErrorFilter(int32_t error); + static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode); + static FingerprintAcquiredInfo VendorAcquiredFilter(int32_t error, int32_t* vendorCode); + static BiometricsFingerprint* sInstance; + + std::mutex mClientCallbackMutex; + sp mClientCallback; + xiaomi_fingerprint_device_t *mDevice; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H diff --git a/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.rc b/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.rc new file mode 100644 index 0000000..2fed25b --- /dev/null +++ b/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.rc @@ -0,0 +1,36 @@ +service vendor.fps_hal /vendor/bin/hw/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi + # "class hal" causes a race condition on some devices due to files created + # in /data. As a workaround, postpone startup until later in boot once + # /data is mounted. + class late_start + user system + group system input uhid + +on boot + #for silead fingeprint + mkdir /data/vendor/silead 0777 system system + chown system system /dev/silead_fp + chmod 0660 /dev/silead_fp + chown system system /dev/spidev1.0 + chmod 0660 /dev/spidev1.0 + chown system system /dev/silead_stub + chmod 0660 /dev/silead_stub + + #for goodix dump + mkdir /data/vendor/goodix 0777 system system + mkdir /data/vendor_de/0/goodix 0770 system system + + #fpc fingerprint + chown system system /sys/bus/platform/devices/soc:fpc1020/hw_reset + chown system system /sys/bus/platform/devices/soc:fpc1020/irq + chown system system /sys/bus/platform/devices/soc:fpc1020/wakeup_enable + chown system system /sys/bus/platform/devices/soc:fpc1020/regulator_enable + chown system system /sys/bus/platform/devices/soc:fpc1020/compatible_all + chown system system /sys/bus/platform/devices/soc:fpc1020/fingerdown_wait + + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/hw_reset + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/irq + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/wakeup_enable + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/regulator_enable + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/compatible_all + chmod 0644 /sys/bus/platform/devices/soc:fpc1020/fingerdown_wait diff --git a/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.xml b/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.xml new file mode 100644 index 0000000..66a77d9 --- /dev/null +++ b/biometrics/android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi.xml @@ -0,0 +1,42 @@ + + + android.hardware.biometrics.fingerprint + hwbinder + 2.1 + + IBiometricsFingerprint + default + + + + vendor.goodix.hardware.biometrics.fingerprint + hwbinder + 2.1 + + IGoodixFingerprintDaemon + default + + + IGoodixFingerprintDaemonExt + default + + + + vendor.xiaomi.hardware.fingerprintextension + hwbinder + 1.0 + + IXiaomiFingerprint + default + + + + vendor.silead.hardware.fingerprintext + hwbinder + 1.0 + + ISileadFingerprint + default + + + diff --git a/biometrics/service.cpp b/biometrics/service.cpp new file mode 100644 index 0000000..0f6f70e --- /dev/null +++ b/biometrics/service.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi" + +#include +#include +#include +#include +#include +#include +#include "BiometricsFingerprint.h" + +using android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +using android::hardware::biometrics::fingerprint::V2_1::implementation::BiometricsFingerprint; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::sp; +using vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint; + +int main() { + android::sp bio = BiometricsFingerprint::getInstance(); + android::sp xfe = BiometricsFingerprint::getXiaomiInstance(); + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (bio != nullptr) { + if (::android::OK != bio->registerAsService()) { + return 1; + } + } else { + ALOGE("Can't create instance of BiometricsFingerprint, nullptr"); + } + + if (xfe != nullptr) { + if (::android::OK != xfe->registerAsService()) { + return 1; + } + } else { + ALOGE("Can't create instance of XiaomiFingerprint, nullptr"); + } + + joinRpcThreadpool(); + + return 0; // should never get here +} diff --git a/biometrics/xiaomi_fingerprint.h b/biometrics/xiaomi_fingerprint.h new file mode 100644 index 0000000..7d6d14f --- /dev/null +++ b/biometrics/xiaomi_fingerprint.h @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef XIAOMI_FINGERPRINT_H +#define XIAOMI_FINGERPRINT_H + +#include +#include + +typedef struct xiaomi_fingerprint_device { + /** + * Common methods of the fingerprint device. This *must* be the first member + * of fingerprint_device as users of this structure will cast a hw_device_t + * to fingerprint_device pointer in contexts where it's known + * the hw_device_t references a fingerprint_device. + */ + struct hw_device_t common; + + /* + * Client provided callback function to receive notifications. + * Do not set by hand, use the function above instead. + */ + fingerprint_notify_t notify; + + /* + * Set notification callback: + * Registers a user function that would receive notifications from the HAL + * The call will block if the HAL state machine is in busy state until HAL + * leaves the busy state. + * + * Function return: 0 if callback function is successfuly registered + * or a negative number in case of error, generally from the errno.h set. + */ + int (*set_notify)(struct xiaomi_fingerprint_device *dev, fingerprint_notify_t notify); + + /* + * Fingerprint pre-enroll enroll request: + * Generates a unique token to upper layers to indicate the start of an enrollment transaction. + * This token will be wrapped by security for verification and passed to enroll() for + * verification before enrollment will be allowed. This is to ensure adding a new fingerprint + * template was preceded by some kind of credential confirmation (e.g. device password). + * + * Function return: 0 if function failed + * otherwise, a uint64_t of token + */ + uint64_t (*pre_enroll)(struct xiaomi_fingerprint_device *dev); + + /* + * Fingerprint enroll request: + * Switches the HAL state machine to collect and store a new fingerprint + * template. Switches back as soon as enroll is complete + * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING && + * fingerprint_msg.data.enroll.samples_remaining == 0) + * or after timeout_sec seconds. + * The fingerprint template will be assigned to the group gid. User has a choice + * to supply the gid or set it to 0 in which case a unique group id will be generated. + * + * Function return: 0 if enrollment process can be successfully started + * or a negative number in case of error, generally from the errno.h set. + * A notify() function may be called indicating the error condition. + */ + int (*enroll)(struct xiaomi_fingerprint_device *dev, const hw_auth_token_t *hat, + uint32_t gid, uint32_t timeout_sec); + + /* + * Finishes the enroll operation and invalidates the pre_enroll() generated challenge. + * This will be called at the end of a multi-finger enrollment session to indicate + * that no more fingers will be added. + * + * Function return: 0 if the request is accepted + * or a negative number in case of error, generally from the errno.h set. + */ + int (*post_enroll)(struct xiaomi_fingerprint_device *dev); + + /* + * get_authenticator_id: + * Returns a token associated with the current fingerprint set. This value will + * change whenever a new fingerprint is enrolled, thus creating a new fingerprint + * set. + * + * Function return: current authenticator id or 0 if function failed. + */ + uint64_t (*get_authenticator_id)(struct xiaomi_fingerprint_device *dev); + + /* + * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED + * to all running clients. Switches the HAL state machine back to the idle state. + * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge. + * + * Function return: 0 if cancel request is accepted + * or a negative number in case of error, generally from the errno.h set. + */ + int (*cancel)(struct xiaomi_fingerprint_device *dev); + + /* + * Enumerate all the fingerprint templates found in the directory set by + * set_active_group() + * For each template found a notify() will be called with: + * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED + * fingerprint_msg.data.enumerated.finger indicating a template id + * fingerprint_msg.data.enumerated.remaining_templates indicating how many more + * enumeration messages to expect. + * Note: If there are no fingerprints, then this should return 0 and the first fingerprint + * enumerated should have fingerid=0 and remaining=0 + * Function return: 0 if enumerate request is accepted + * or a negative number in case of error, generally from the errno.h set. + */ + int (*enumerate)(struct xiaomi_fingerprint_device *dev); + + /* + * Fingerprint remove request: + * Deletes a fingerprint template. + * Works only within the path set by set_active_group(). + * The fid parameter can be used as a widcard: + * * fid == 0 -- delete all the templates in the group. + * * fid != 0 -- delete this specific template from the group. + * For each template found a notify() will be called with: + * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED + * fingerprint_msg.data.removed.finger indicating a template id deleted + * fingerprint_msg.data.removed.remaining_templates indicating how many more + * templates will be deleted by this operation. + * + * Function return: 0 if fingerprint template(s) can be successfully deleted + * or a negative number in case of error, generally from the errno.h set. + */ + int (*remove)(struct xiaomi_fingerprint_device *dev, uint32_t gid, uint32_t fid); + + /* + * Restricts the HAL operation to a set of fingerprints belonging to a + * group provided. + * The caller must provide a path to a storage location within the user's + * data directory. + * + * Function return: 0 on success + * or a negative number in case of error, generally from the errno.h set. + */ + int (*set_active_group)(struct xiaomi_fingerprint_device *dev, uint32_t gid, + const char *store_path); + + /* + * Authenticates an operation identifed by operation_id + * + * Function return: 0 on success + * or a negative number in case of error, generally from the errno.h set. + */ + int (*authenticate)(struct xiaomi_fingerprint_device *dev, uint64_t operation_id, uint32_t gid); + + /* + * Call a Xiaomi fingerprint extension command. + */ + int (*extCmd)(struct xiaomi_fingerprint_device *dev, int32_t cmd, int32_t param); + + /* + * Reserved for backward binary compatibility + */ + void *reserved[4]; +} xiaomi_fingerprint_device_t; + +#endif // XIAOMI_FINGERPRINT_H diff --git a/bluetooth/include/bdroid_buildcfg.h b/bluetooth/include/bdroid_buildcfg.h new file mode 100644 index 0000000..55a6e1e --- /dev/null +++ b/bluetooth/include/bdroid_buildcfg.h @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Not a Contribution, Apache license notifications and license are retained + * for attribution purposes only. + * + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BDROID_BUILDCFG_H +#define _BDROID_BUILDCFG_H + +// Disables read remote device feature +#define MAX_ACL_CONNECTIONS 16 +#define MAX_L2CAP_CHANNELS 16 +#define BLE_VND_INCLUDED TRUE + +/* Increasing SEPs to 12 from 6 to support SHO/MCast i.e. two streams per codec */ +#define AVDT_NUM_SEPS 12 +#endif diff --git a/bootctrl/Android.bp b/bootctrl/Android.bp new file mode 100644 index 0000000..50218a5 --- /dev/null +++ b/bootctrl/Android.bp @@ -0,0 +1,28 @@ +// +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_library { + name: "bootctrl.xiaomi_holi", + defaults: ["bootctrl_hal_defaults"], + static_libs: ["libgptutils.xiaomi_holi"], +} + +cc_library_shared { + name: "android.hardware.boot@1.1-impl-qti", + stem: "android.hardware.boot@1.0-impl-1.1-qti", + defaults: ["android.hardware.boot@1.1-impl-qti_defaults"], + static_libs: ["libgptutils.xiaomi_holi"], +} diff --git a/compatibility_matrix.xml b/compatibility_matrix.xml new file mode 100644 index 0000000..a3e3746 --- /dev/null +++ b/compatibility_matrix.xml @@ -0,0 +1,86 @@ + + + + android.frameworks.schedulerservice + 1.0 + + ISchedulingPolicyService + default + + + + android.frameworks.sensorservice + 1.0 + + ISensorManager + default + + + + android.hidl.allocator + 1.0 + + IAllocator + ashmem + + + + android.hidl.manager + 1.0 + + IServiceManager + default + + + + android.hidl.memory + 1.0 + + IMapper + ashmem + + + + android.hidl.token + 1.0 + + ITokenManager + default + + + + android.system.wifi.keystore + 1.0 + + IKeystore + default + + + + vendor.qti.hardware.qccsyshal + 1.0 + + IQccsyshal + qccsyshal + + + + vendor.qti.hardware.sigma_miracast + 1.0 + + Isigma_miracast + sigmahal + + + + vendor.qti.hardware.wifi.keystore + 1.0 + + IKeystoreExt + default + + + diff --git a/config.fs b/config.fs new file mode 100644 index 0000000..d2d0ad3 --- /dev/null +++ b/config.fs @@ -0,0 +1,200 @@ +[AID_VENDOR_QTI_DIAG] +value:2901 + +[AID_VENDOR_QDSS] +value:2902 + +[AID_VENDOR_RFS] +value:2903 + +[AID_VENDOR_RFS_SHARED] +value:2904 + +[AID_VENDOR_ADPL_ODL] +value:2905 + +[AID_VENDOR_QRTR] +value:2906 + +[AID_VENDOR_THERMAL] +value:2907 + +[vendor/bin/wcnss_filter] +mode: 0755 +user: AID_BLUETOOTH +group: AID_BLUETOOTH +caps: BLOCK_SUSPEND + +[system/vendor/bin/wcnss_filter] +mode: 0755 +user: AID_BLUETOOTH +group: AID_BLUETOOTH +caps: BLOCK_SUSPEND + +[vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti] +mode: 0755 +user: AID_BLUETOOTH +group: AID_BLUETOOTH +caps: BLOCK_SUSPEND NET_ADMIN + +[system/vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: BLOCK_SUSPEND NET_ADMIN + +[vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti-lazy] +mode: 0755 +user: AID_BLUETOOTH +group: AID_BLUETOOTH +caps: BLOCK_SUSPEND NET_ADMIN + +[system/vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti-lazy] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: BLOCK_SUSPEND NET_ADMIN + +[system/bin/cnss-daemon] +mode: 0755 +user: AID_BLUETOOTH +group: AID_BLUETOOTH +caps: NET_BIND_SERVICE + +[vendor/bin/pm-service] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE SYS_BOOT + +[system/vendor/bin/pm-service] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE SYS_BOOT + +[system/bin/pm-service] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE SYS_BOOT + +[vendor/bin/pd-mapper] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE + +[system/vendor/bin/pd-mapper] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE + +[system/bin/pd-mapper] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE + +[vendor/bin/imsdatadaemon] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE + +[system/vendor/bin/imsdatadaemon] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE + +[vendor/bin/ims_rtp_daemon] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE + +[system/vendor/bin/ims_rtp_daemon] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE + +[vendor/bin/imsrcsd] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE BLOCK_SUSPEND WAKE_ALARM + +[system/vendor/bin/imsrcsd] +mode: 0755 +user: AID_RADIO +group: AID_RADIO +caps: NET_BIND_SERVICE BLOCK_SUSPEND WAKE_ALARM + +[vendor/bin/cnd] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE BLOCK_SUSPEND NET_ADMIN + +[system/vendor/bin/cnd] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE BLOCK_SUSPEND NET_ADMIN + +[vendor/bin/loc_launcher] +mode: 0755 +user: AID_GPS +group: AID_GPS +caps: SETUID SETGID + +[system/vendor/bin/loc_launcher] +mode: 0755 +user: AID_GPS +group: AID_GPS +caps: SETUID SETGID + +[vendor/bin/sensors.qti] +mode: 0755 +user: AID_SYSTEM +group: AID_SYSTEM +caps: NET_BIND_SERVICE + +[firmware/] +mode: 0771 +user: AID_SYSTEM +group: AID_SYSTEM +caps: 0 + +[firmware/image/*] +mode: 0771 +user: AID_SYSTEM +group: AID_SYSTEM +caps: 0 + +[vendor/firmware_mnt/image/*] +mode: 0771 +user: AID_SYSTEM +group: AID_SYSTEM +caps: 0 + +[bt_firmware/] +mode: 0771 +user: AID_SYSTEM +group: AID_SYSTEM +caps: 0 + +[persist/] +mode: 0771 +user: AID_SYSTEM +group: AID_SYSTEM +caps: 0 + +[dsp/] +mode: 0771 +user: AID_MEDIA +group: AID_MEDIA +caps: 0 diff --git a/configs/component-overrides.xml b/configs/component-overrides.xml new file mode 100644 index 0000000..4d058d3 --- /dev/null +++ b/configs/component-overrides.xml @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/configs/powerhint.xml b/configs/powerhint.xml new file mode 100644 index 0000000..914e8cf --- /dev/null +++ b/configs/powerhint.xml @@ -0,0 +1,624 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/configs/public.libraries.txt b/configs/public.libraries.txt new file mode 100644 index 0000000..a599ed2 --- /dev/null +++ b/configs/public.libraries.txt @@ -0,0 +1,9 @@ +libqti-perfd-client.so +libadsprpc.so +libcdsprpc.so +libsdsprpc.so +libfastcvopt.so +liblistensoundmodel2.so +libOpenCL.so + +libmialgoengine.so 64 diff --git a/configs/snapdragon_color_libs_config.xml b/configs/snapdragon_color_libs_config.xml new file mode 100644 index 0000000..e257b1f --- /dev/null +++ b/configs/snapdragon_color_libs_config.xml @@ -0,0 +1,33 @@ + + + + + libsnapdragoncolor-qdcm.so + 1 + + diff --git a/configs/telephony_system-ext_privapp-permissions-qti.xml b/configs/telephony_system-ext_privapp-permissions-qti.xml new file mode 100644 index 0000000..d844441 --- /dev/null +++ b/configs/telephony_system-ext_privapp-permissions-qti.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/device.mk b/device.mk index 1923252..4f71ec2 100644 --- a/device.mk +++ b/device.mk @@ -4,23 +4,518 @@ # SPDX-License-Identifier: Apache-2.0 # -# Inherit from sm6375-common -$(call inherit-product, device/xiaomi/sm6375-common/holi.mk) +# Inherit from vendor blobs +$(call inherit-product, vendor/xiaomi/veux/veux-vendor.mk) -PRODUCT_SHIPPING_API_LEVEL := 30 +# APEX's +$(call inherit-product, $(SRC_TARGET_DIR)/product/updatable_apex.mk) -# Device uses high-density artwork where available -PRODUCT_AAPT_CONFIG := normal -PRODUCT_AAPT_PREF_CONFIG := xhdpi +# GSI Keys +$(call inherit-product, $(SRC_TARGET_DIR)/product/gsi_keys.mk) + +# Enable project quotas and casefolding for emulated storage without sdcardfs +$(call inherit-product, $(SRC_TARGET_DIR)/product/emulated_storage.mk) + +# Enable virtual A/B OTA +$(call inherit-product, $(SRC_TARGET_DIR)/product/virtual_ab_ota/launch_with_vendor_ramdisk.mk) + +# A/B +AB_OTA_POSTINSTALL_CONFIG += \ + RUN_POSTINSTALL_system=true \ + POSTINSTALL_PATH_system=system/bin/otapreopt_script \ + FILESYSTEM_TYPE_system=ext4 \ + POSTINSTALL_OPTIONAL_system=true + +AB_OTA_POSTINSTALL_CONFIG += \ + RUN_POSTINSTALL_vendor=true \ + POSTINSTALL_PATH_vendor=bin/checkpoint_gc \ + FILESYSTEM_TYPE_vendor=ext4 \ + POSTINSTALL_OPTIONAL_vendor=true + +PRODUCT_PACKAGES += \ + checkpoint_gc \ + otapreopt_script + +# Audio +PRODUCT_PACKAGES += \ + libvolumelistener \ + libqcomvisualizer \ + libqcomvoiceprocessing \ + libqcompostprocbundle + +PRODUCT_PACKAGES += \ + android.hardware.audio.effect@6.0-impl \ + android.hardware.audio.service \ + android.hardware.audio@6.0-impl \ + android.hardware.soundtrigger@2.2-impl \ + audioadsprpcd \ + audio.a2dp.default \ + audio.primary.holi \ + audio.r_submix.default \ + audio.usb.default \ + libaudiopreprocessing \ + libbatterylistener \ + libbundlewrapper \ + libcomprcapture \ + libdownmix \ + libdynproc \ + libeffectproxy \ + libexthwplugin \ + libhdmiedid \ + libhfp \ + libldnhncr \ + libreverbwrapper \ + libsndmonitor \ + libspkrprot \ + libvisualizer -# Boot animation +# Audio Configs +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/audio/audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio/audio_policy_configuration.xml + +PRODUCT_COPY_FILES += \ + frameworks/av/services/audiopolicy/config/a2dp_in_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio/sku_holi/a2dp_in_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/bluetooth_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio/sku_holi/bluetooth_audio_policy_configuration.xml + +# AVB +PRODUCT_PACKAGES += \ + q-gsi.avbpubkey \ + r-gsi.avbpubkey \ + s-gsi.avbpubkey + +# Bluetooth +PRODUCT_PACKAGES += \ + audio.bluetooth.default \ + android.hardware.bluetooth@1.1.vendor \ + android.hardware.bluetooth.audio@2.1-impl \ + com.dsi.ant@1.0.vendor \ + vendor.qti.hardware.bluetooth_audio@2.0.vendor \ + vendor.qti.hardware.bluetooth_audio@2.1.vendor \ + vendor.qti.hardware.btconfigstore@1.0.vendor \ + vendor.qti.hardware.btconfigstore@2.0.vendor + +PRODUCT_COPY_FILES += \ + frameworks/av/services/audiopolicy/config/a2dp_in_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/a2dp_in_audio_policy_configuration.xml \ + frameworks/av/services/audiopolicy/config/bluetooth_audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/bluetooth_audio_policy_configuration.xml + +# Boot Animation TARGET_SCREEN_HEIGHT := 2400 TARGET_SCREEN_WIDTH := 1080 -# Overlays -DEVICE_PACKAGE_OVERLAYS += \ - $(LOCAL_PATH)/overlay \ - $(LOCAL_PATH)/overlay-lineage +# Boot Control +PRODUCT_PACKAGES += \ + android.hardware.boot@1.1-impl-qti \ + android.hardware.boot@1.1-impl-qti.recovery \ + android.hardware.boot@1.1-service + +PRODUCT_PACKAGES_DEBUG += \ + bootctl + +# Camera +PRODUCT_PACKAGES += \ + android.hardware.camera.provider@2.4-impl \ + android.hardware.camera.provider@2.4-service_64 \ + libcamera2ndk_vendor \ + libstdc++.vendor \ + vendor.qti.hardware.camera.postproc@1.0.vendor + +# Component Overrides +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/component-overrides.xml:$(TARGET_COPY_OUT_VENDOR)/etc/sysconfig/component-overrides.xml + +# Consumer IR +PRODUCT_PACKAGES += \ + android.hardware.ir@1.0-impl \ + android.hardware.ir@1.0-service + +# Device Uses High-Density Artwork Where Available +PRODUCT_AAPT_CONFIG := normal +PRODUCT_AAPT_PREF_CONFIG := xhdpi + +# Display +PRODUCT_PACKAGES += \ + android.hardware.graphics.mapper@3.0-impl-qti-display \ + android.hardware.graphics.mapper@4.0-impl-qti-display \ + android.hardware.memtrack@1.0-impl \ + android.hardware.memtrack@1.0-service \ + vendor.qti.hardware.display.allocator-service \ + vendor.qti.hardware.display.composer-service \ + vendor.qti.hardware.display.mapper@1.0.vendor \ + vendor.qti.hardware.display.mapper@1.1.vendor \ + vendor.qti.hardware.display.mapper@2.0.vendor \ + vendor.qti.hardware.display.mapper@3.0.vendor \ + vendor.qti.hardware.display.mapper@4.0.vendor + +PRODUCT_PACKAGES += \ + vendor.display.config@1.15.vendor \ + vendor.display.config@2.0.vendor + +PRODUCT_PACKAGES += \ + libdisplayconfig.qti \ + libdisplayconfig.qti.vendor \ + libqdMetaData \ + libtinyxml \ + memtrack.default \ + vndservicemanager + +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/snapdragon_color_libs_config.xml:$(TARGET_COPY_OUT_VENDOR)/etc/snapdragon_color_libs_config.xml + +# DRM +PRODUCT_PACKAGES += \ + android.hardware.drm@1.4-service.clearkey \ + android.hardware.drm@1.4.vendor + +PRODUCT_PACKAGES += \ + libdrm + +# Fastbootd +PRODUCT_PACKAGES += \ + fastbootd + +# Filesystem +PRODUCT_PACKAGES += \ + fs_config_files + +# Fingerprint +PRODUCT_PACKAGES += \ + android.hardware.biometrics.fingerprint@2.1-service.xiaomi_holi \ + vendor.goodix.hardware.biometrics.fingerprint@2.1.vendor \ + vendor.xiaomi.hardware.fingerprintextension@1.0.vendor + +# GPS +PRODUCT_PACKAGES += \ + android.hardware.gnss@2.1-impl-qti \ + android.hardware.gnss@2.1-service-qti + +PRODUCT_PACKAGES += \ + libbatching \ + libgeofencing \ + libgnss + +PRODUCT_PACKAGES += \ + apdr.conf \ + flp.conf \ + gnss_antenna_info.conf \ + gps.conf \ + izat.conf \ + lowi.conf \ + sap.conf + +PRODUCT_PACKAGES += \ + gnss@2.0-base.policy \ + gnss@2.0-xtra-daemon.policy + +# Gatekeeper +PRODUCT_PACKAGES += \ + android.hardware.gatekeeper@1.0.vendor + +# GPS +PRODUCT_PACKAGES += \ + android.hardware.gnss@1.1.vendor \ + android.hardware.gnss@2.1.vendor + +# Health +PRODUCT_PACKAGES += \ + android.hardware.health@2.1-impl \ + android.hardware.health@2.1-service + +# HIDL +PRODUCT_PACKAGES += \ + android.hidl.base@1.0 \ + android.hidl.base@1.0.vendor \ + libhidltransport.vendor \ + libhwbinder.vendor + +# Hotword Enrollement Permissions +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/permissions/privapp-permissions-hotword.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/permissions/privapp-permissions-hotword.xml + +# IFAA Manager +PRODUCT_PACKAGES += \ + org.ifaa.android.manager + +PRODUCT_BOOT_JARS += \ + org.ifaa.android.manager + +# IPACM +PRODUCT_PACKAGES += \ + ipacm \ + IPACM_cfg.xml \ + libipanat \ + liboffloadhal + +# Keymaster +PRODUCT_PACKAGES += \ + android.hardware.keymaster@4.1.vendor + +# LiveDisplay +PRODUCT_PACKAGES += \ + vendor.lineage.livedisplay@2.0-service-sdm + +# Media +PRODUCT_PACKAGES += \ + libavservices_minijail \ + libavservices_minijail.vendor \ + libavservices_minijail_vendor \ + libcodec2_hidl@1.1.vendor \ + libmm-omxcore \ + libOmxAacEnc \ + libOmxAmrEnc \ + libOmxCore \ + libOmxEvrcEnc \ + libOmxG711Enc \ + libOmxQcelp13Enc \ + libOmxVdec \ + libOmxVenc \ + libstagefrighthw \ + libstagefright_omx \ + libstagefright_foundation \ + libstagefright_softomx.vendor + +# Net +PRODUCT_PACKAGES += \ + netutils-wrapper-1.0 + +PRODUCT_PACKAGES += \ + android.system.net.netd@1.1.vendor + +# Neural Networks +PRODUCT_PACKAGES += \ + android.hardware.neuralnetworks@1.3.vendor + +# NFC +PRODUCT_PACKAGES += \ + android.hardware.nfc@1.0-impl \ + android.hardware.secure_element@1.0.vendor \ + com.android.nfc_extras \ + NfcNci \ + SecureElement \ + Tag + +# Partitions +PRODUCT_BUILD_SUPER_PARTITION := false +PRODUCT_USE_DYNAMIC_PARTITIONS := true + +# Permissions +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.audio.low_latency.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.low_latency.xml \ + frameworks/native/data/etc/android.hardware.audio.pro.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.pro.xml \ + frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \ + frameworks/native/data/etc/android.hardware.bluetooth_le.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth_le.xml \ + frameworks/native/data/etc/android.hardware.camera.flash-autofocus.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.flash-autofocus.xml \ + frameworks/native/data/etc/android.hardware.camera.front.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.front.xml \ + frameworks/native/data/etc/android.hardware.camera.full.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.full.xml \ + frameworks/native/data/etc/android.hardware.camera.raw.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.camera.raw.xml \ + frameworks/native/data/etc/android.hardware.consumerir.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.consumerir.xml \ + frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml \ + frameworks/native/data/etc/android.hardware.location.gps.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.location.gps.xml \ + frameworks/native/data/etc/android.hardware.nfc.hce.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/android.hardware.nfc.hce.xml \ + frameworks/native/data/etc/android.hardware.nfc.hcef.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/android.hardware.nfc.hcef.xml \ + frameworks/native/data/etc/android.hardware.nfc.uicc.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/android.hardware.nfc.uicc.xml \ + frameworks/native/data/etc/android.hardware.nfc.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/android.hardware.nfc.xml \ + frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \ + frameworks/native/data/etc/android.hardware.se.omapi.ese.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/android.hardware.se.omapi.ese.xml \ + frameworks/native/data/etc/android.hardware.se.omapi.uicc.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.se.omapi.uicc.xml \ + frameworks/native/data/etc/android.hardware.sensor.accelerometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.accelerometer.xml \ + frameworks/native/data/etc/android.hardware.sensor.barometer.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.barometer.xml \ + frameworks/native/data/etc/android.hardware.sensor.compass.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.compass.xml \ + frameworks/native/data/etc/android.hardware.sensor.gyroscope.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.gyroscope.xml \ + frameworks/native/data/etc/android.hardware.sensor.hifi_sensors.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.hifi_sensors.xml \ + frameworks/native/data/etc/android.hardware.sensor.light.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.light.xml \ + frameworks/native/data/etc/android.hardware.sensor.proximity.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.proximity.xml \ + frameworks/native/data/etc/android.hardware.sensor.stepcounter.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.stepcounter.xml \ + frameworks/native/data/etc/android.hardware.sensor.stepdetector.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.stepdetector.xml \ + frameworks/native/data/etc/android.hardware.telephony.cdma.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.cdma.xml \ + frameworks/native/data/etc/android.hardware.telephony.gsm.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.gsm.xml \ + frameworks/native/data/etc/android.hardware.telephony.ims.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.telephony.ims.xml \ + frameworks/native/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \ + frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml \ + frameworks/native/data/etc/android.hardware.usb.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.host.xml \ + frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \ + frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \ + frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ + frameworks/native/data/etc/android.hardware.wifi.aware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.aware.xml \ + frameworks/native/data/etc/android.hardware.wifi.direct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.direct.xml \ + frameworks/native/data/etc/android.hardware.wifi.passpoint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.passpoint.xml \ + frameworks/native/data/etc/android.hardware.wifi.rtt.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.rtt.xml \ + frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml \ + frameworks/native/data/etc/android.software.ipsec_tunnels.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.ipsec_tunnels.xml \ + frameworks/native/data/etc/android.software.midi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.midi.xml \ + frameworks/native/data/etc/android.software.sip.voip.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.sip.voip.xml \ + frameworks/native/data/etc/android.software.verified_boot.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/permissions/android.software.verified_boot.xml \ + frameworks/native/data/etc/android.software.verified_boot.xml:$(TARGET_COPY_OUT_SYSTEM_EXT)/etc/permissions/android.software.verified_boot.xml \ + frameworks/native/data/etc/android.software.verified_boot.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.verified_boot.xml \ + frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute-0.xml \ + frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level-1.xml \ + frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version-1_1.xml \ + frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ + frameworks/native/data/etc/com.android.nfc_extras.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/com.android.nfc_extras.xml \ + frameworks/native/data/etc/com.nxp.mifare.xml:$(TARGET_COPY_OUT_ODM)/etc/permissions/sku_nfc/com.nxp.mifare.xml + +# Power +PRODUCT_PACKAGES += \ + android.hardware.power-service-qti \ + vendor.qti.hardware.perf@2.2.vendor + +# Powerhint +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/powerhint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/powerhint.xml + +# Public Libraries +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/public.libraries.txt:$(TARGET_COPY_OUT_VENDOR)/etc/public.libraries.txt + +# QMI +PRODUCT_PACKAGES += \ + libjson \ + libqti_vndfwk_detect \ + libqti_vndfwk_detect.vendor \ + libvndfwk_detect_jni.qti \ + libvndfwk_detect_jni.qti.vendor + +# RCS +PRODUCT_PACKAGES += \ + com.android.ims.rcsmanager \ + PresencePolling \ + RcsService + +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/configs/telephony_system-ext_privapp-permissions-qti.xml:$(TARGET_COPY_OUT_SYSTEM_EXT)/etc/permissions/telephony_system-ext-privapp-permissions-qti.xml + +# RenderScript HAL +PRODUCT_PACKAGES += \ + android.hardware.renderscript@1.0-impl + +# RIL +PRODUCT_PACKAGES += \ + libjson \ + librmnetctl + +PRODUCT_PACKAGES += \ + android.hardware.radio@1.6.vendor \ + android.hardware.radio.config@1.3.vendor \ + android.hardware.radio.deprecated@1.0.vendor \ + android.hardware.secure_element@1.2.vendor + +# Rootdir +PRODUCT_PACKAGES += \ + init.batterysecret.rc \ + init.class_main.sh \ + init.mi.btmac.sh \ + init.kernel.post_boot.sh \ + init.kernel.post_boot-blair.sh \ + init.kernel.post_boot-holi.sh \ + init.qcom.sh \ + init.qcom.post_boot.sh \ + init.nfc.rc \ + init.qcom.rc \ + init.qti.kernel.rc \ + init.qti.ufs.rc \ + init.target.rc \ + ueventd.qcom.rc \ + vendor_modprobe.sh + +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/rootdir/etc/charger_fstab.qti:$(TARGET_COPY_OUT_VENDOR)/etc/charger_fstab.qti \ + $(LOCAL_PATH)/rootdir/etc/fstab.default:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.default \ + $(LOCAL_PATH)/rootdir/etc/fstab.default:$(TARGET_COPY_OUT_RECOVERY)/root/first_stage_ramdisk/fstab.default \ + $(LOCAL_PATH)/rootdir/etc/fstab.default:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/first_stage_ramdisk/fstab.default \ + $(LOCAL_PATH)/rootdir/etc/fstab.emmc:$(TARGET_COPY_OUT_VENDOR)/etc/fstab.emmc \ + $(LOCAL_PATH)/rootdir/etc/fstab.emmc:$(TARGET_COPY_OUT_RECOVERY)/root/first_stage_ramdisk/fstab.emmc \ + $(LOCAL_PATH)/rootdir/etc/fstab.emmc:$(TARGET_COPY_OUT_VENDOR_RAMDISK)/first_stage_ramdisk/fstab.emmc \ + $(LOCAL_PATH)/rootdir/etc/init.recovery.qcom.rc:$(TARGET_COPY_OUT_RECOVERY)/root/init.recovery.qcom.rc + +# Sensors +PRODUCT_PACKAGES += \ + android.hardware.sensors@2.1-service.xiaomi_holi-multihal \ + libsensorndkbridge + +# Service Tracker +PRODUCT_PACKAGES += \ + vendor.qti.hardware.servicetracker@1.0.vendor \ + vendor.qti.hardware.servicetracker@1.1.vendor \ + vendor.qti.hardware.servicetracker@1.2.vendor + +# Shipping API Level +PRODUCT_SHIPPING_API_LEVEL := 30 + +# Soong Namespaces +PRODUCT_SOONG_NAMESPACES += \ + $(LOCAL_PATH) \ + hardware/xiaomi + +# Telephony +PRODUCT_PACKAGES += \ + ims-ext-common \ + ims_ext_common.xml \ + qti-telephony-hidl-wrapper \ + qti_telephony_hidl_wrapper.xml \ + qti-telephony-utils \ + qti_telephony_utils.xml \ + telephony-ext + +PRODUCT_BOOT_JARS += \ + telephony-ext + +# Thermal +PRODUCT_PACKAGES += \ + android.hardware.thermal@2.0-service.qti + +# Trust +PRODUCT_PACKAGES += \ + vendor.lineage.trust@1.0-service + +# Update Engine +PRODUCT_PACKAGES += \ + update_engine \ + update_engine_sideload \ + update_verifier + +PRODUCT_PACKAGES_DEBUG += \ + update_engine_client + +# USB +PRODUCT_PACKAGES += \ + android.hardware.usb@1.3-service-qti + +PRODUCT_PACKAGES += \ + init.qcom.usb.rc \ + init.qcom.usb.sh + +PRODUCT_SOONG_NAMESPACES += \ + vendor/qcom/opensource/usb/etc + +# Vibrator +PRODUCT_PACKAGES += \ + vendor.qti.hardware.vibrator.service.xiaomi_holi + +PRODUCT_COPY_FILES += \ + $(LOCAL_PATH)/vibrator/excluded-input-devices.xml:$(TARGET_COPY_OUT_VENDOR)/etc/excluded-input-devices.xml + +# WiFi +PRODUCT_PACKAGES += \ + android.hardware.wifi@1.0-service \ + hostapd \ + libwifi-hal-ctrl \ + libwifi-hal-qcom \ + libwpa_client \ + vendor.qti.hardware.wifi.hostapd@1.2.vendor \ + vendor.qti.hardware.wifi.supplicant@2.1.vendor \ + wpa_cli \ + wpa_supplicant \ + wpa_supplicant.conf + +PRODUCT_COPY_FILES += \ + $(call find-copy-subdir-files,*,$(LOCAL_PATH)/wifi/,$(TARGET_COPY_OUT_VENDOR)/etc/wifi) + +# WiFi Display +PRODUCT_PACKAGES += \ + libnl \ + libwfdaac_vendor + +PRODUCT_BOOT_JARS += \ + WfdCommon # Inherit from vendor blobs -$(call inherit-product, vendor/xiaomi/veux/veux-vendor.mk) +include vendor/xiaomi/veux/veux-vendor.mk diff --git a/extract-files.sh b/extract-files.sh index 7d85c26..ababc8f 100755 --- a/extract-files.sh +++ b/extract-files.sh @@ -1,21 +1,58 @@ #!/bin/bash # -# Copyright (C) 2016 The CyanogenMod Project -# Copyright (C) 2017-2020 The LineageOS Project +# Copyright (C) 2022 The LineageOS Project # # SPDX-License-Identifier: Apache-2.0 # -# If we're being sourced by the common script that we called, -# stop right here. No need to go down the rabbit hole. -if [ "${BASH_SOURCE[0]}" != "${0}" ]; then - return +set -e + +DEVICE=veux +VENDOR=xiaomi + +# Load extract_utils and do some sanity checks +MY_DIR="${BASH_SOURCE%/*}" +if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi + +ANDROID_ROOT="${MY_DIR}"/../../.. + +HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" +if [ ! -f "${HELPER}" ]; then + echo "Unable to find helper script at ${HELPER}" + exit 1 fi +source "${HELPER}" -set -e +# Default to sanitizing the vendor folder before extraction +CLEAN_VENDOR=true + +while [ "${#}" -gt 0 ]; do + case "${1}" in + -n | --no-cleanup ) + CLEAN_VENDOR=false + ;; + -k | --kang ) + KANG="--kang" + ;; + -s | --section ) + SECTION="${2}"; shift + CLEAN_VENDOR=false + ;; + * ) + SRC="${1}" + ;; + esac + shift +done + +if [ -z "${SRC}" ]; then + SRC="adb" +fi + +# Initialize the helper for common device +setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" true "${CLEAN_VENDOR}" -export DEVICE=veux -export DEVICE_COMMON=sm6375-common -export VENDOR=xiaomi +extract "${MY_DIR}/proprietary-files.txt" "${SRC}" \ + "${KANG}" --section "${SECTION}" -"./../../${VENDOR}/${DEVICE_COMMON}/extract-files.sh" "$@" +"${MY_DIR}/setup-makefiles.sh" \ No newline at end of file diff --git a/framework_compatibility_matrix.xml b/framework_compatibility_matrix.xml new file mode 100644 index 0000000..2dae099 --- /dev/null +++ b/framework_compatibility_matrix.xml @@ -0,0 +1,1121 @@ + + + + android.hardware.automotive.evs + 1.1 + + IEvsEnumerator + default + + + + android.hardware.bluetooth.audio + 2.1 + + IBluetoothAudioProvidersFactory + default + + + + android.hardware.gnss + 1.0-1 + 2.0-1 + + IGnss + default + gnss_vendor + + + + android.hardware.media.c2 + 1.0 + + IComponentStore + default + software + + + + android.hardware.nfc + 1.0 + + INfc + default + + + + android.hardware.nfc + 1.2 + + INfc + default + + + + android.hardware.radio + 1.0-4 + + IRadio + slot1 + slot2 + + + ISap + slot1 + slot2 + + + + android.hardware.radio.config + 1.0-1 + + IRadioConfig + default + + + + android.hardware.secure_element + 1.2 + + ISecureElement + SIM1 + SIM2 + + + + android.hardware.wifi.supplicant + 1.0-2 + + ISupplicant + default + wigigp2p + + + + com.dsi.ant + 1.0 + + IAnt + default + + + + com.qualcomm.qti.dpm.api + 1.0 + + IdpmQmi + dpmQmiService + + + + com.qualcomm.qti.imscmservice + 2.0-2 + + IImsCmService + qti.ims.connectionmanagerservice + + + + com.qualcomm.qti.uceservice + 2.0-1 + 2.2 + 2.3 + + IUceService + com.qualcomm.qti.uceservice + + + + com.qualcomm.qti.wifidisplayhal + 1.0 + + IDSManager + wifidisplaydshal + + + IHDCPSession + wifidisplayhdcphal + + + + com.quicinc.cne.api + 1.0-1 + + IApiService + cnd + + + + com.quicinc.cne.server + 2.0-2 + + IServer + cnd + + + + interfaces.factoryAta + 1.0 + + IFactoryAta + default + + + + interfaces.factoryInterface + 1.0 + + IFactoryInterface + default + + + + vendor.display.color + 1.0-6 + + IDisplayColor + default + + + + vendor.display.config + 1.0-15 + 2.0 + + IDisplayConfig + default + + + + vendor.display.postproc + 1.0 + + IDisplayPostproc + default + + + + vendor.dolby.hardware.dms + 2.0 + + IDms + default + + + + vendor.goodix.hardware.biometrics.fingerprint + 2.0-1 + + IGoodixFingerprintDaemon + default + + + IGoodixFingerprintDaemonExt + default + + + + vendor.nxp.hardware.nfc + 1.0-1 + 2.0 + + INqNfc + default + + + + vendor.nxp.nxpnfc + 2.0 + + INxpNfc + default + + + + vendor.nxp.nxpnfclegacy + 1.0 + + INxpNfcLegacy + default + + + + vendor.qti.automotive.qcarcam + 1.0 + + IQcarCamera + default + + + + vendor.qti.data.factory + 1.0 + 2.0-3 + + IFactory + default + + + + vendor.qti.diaghal + 1.0 + + Idiag + default + + + + vendor.qti.gnss + 1.0-2 + 2.0-1 + 3.0 + 4.0-1 + + ILocHidlGnss + gnss_vendor + + + + vendor.qti.hardware.AGMIPC + 1.0 + + IAGM + default + + + + vendor.qti.hardware.alarm + 1.0 + + IAlarm + default + + + + vendor.qti.hardware.audiohalext + 1.0 + + IAudioHalExt + default + + + + vendor.qti.hardware.bluetooth_audio + 2.0-1 + + IBluetoothAudioProvidersFactory + default + + + + vendor.qti.hardware.bluetooth_sar + 1.0-1 + + IBluetoothSar + default + + + + vendor.qti.hardware.btconfigstore + 1.0 + 2.0 + + IBTConfigStore + default + + + + vendor.qti.hardware.cacert + 1.0 + + IService + default + + + + vendor.qti.hardware.camera.postproc + 1.0 + + IPostProcService + camerapostprocservice + + + + vendor.qti.hardware.capabilityconfigstore + 1.0 + + ICapabilityConfigStore + default + + + + vendor.qti.hardware.cryptfshw + 1.0 + + ICryptfsHw + default + + + + vendor.qti.hardware.cvp + 1.0 + + ICvp + cvphalservice + + + + vendor.qti.hardware.data.connection + 1.0-1 + + IDataConnection + slot1 + slot2 + + + + vendor.qti.hardware.data.iwlan + 1.0 + + IIWlan + slot1 + slot2 + + + + vendor.qti.hardware.data.latency + 1.0 + + ILinkLatency + default + + + + vendor.qti.hardware.debugutils + 1.0 + + IDebugUtils + default + + + + vendor.qti.hardware.display.allocator + 1.0 + 3.0 + 4.0 + + IQtiAllocator + default + + + + vendor.qti.hardware.display.composer + 2.0-1 + 3.0 + + IQtiComposer + default + + + + vendor.qti.hardware.display.demura + 1.0 + 2.0 + + IDemuraFileFinder + default + + + + vendor.qti.hardware.display.mapper + 2.0 + 3.0 + 4.0 + + IQtiMapper + default + + + + vendor.qti.hardware.dsp + 1.0 + + IDspService + dspservice + + + + vendor.qti.hardware.eid + 1.0 + + IEid + default + + + + vendor.qti.hardware.embmssl + 1.0-1 + + IEmbms + embmsslServer0 + + + + vendor.qti.hardware.factory + 1.0-1 + + IFactory + default + + + + vendor.qti.hardware.fingerprint + 1.0 + + IQtiExtendedFingerprint + default + + + + vendor.qti.hardware.fm + 1.0 + + IFmHci + default + + + + vendor.qti.hardware.fstman + 1.0 + + IFstManager + default + + + + vendor.qti.hardware.improvetouch.blobmanager + 1.0 + + IBlobManager + BlobManagerService + + + + vendor.qti.hardware.improvetouch.gesturemanager + 1.0 + + IGestureManager + GestureManagerService + + + + vendor.qti.hardware.improvetouch.touchcompanion + 1.0 + + ITouchCompanion + TouchCompanionService + + + + vendor.qti.hardware.iop + 2.0 + + IIop + default + + + + vendor.qti.hardware.limits + 1.0 + + ILimits + default + + + + vendor.qti.hardware.mwqemadapter + 1.0 + + IMwqemAdapter + MwqemAdapter + + + + vendor.qti.hardware.pal + 1.0 + + IPAL + default + + + + vendor.qti.hardware.perf + 2.0-2 + + IPerf + default + + + + vendor.qti.hardware.qccsyshal + 1.0 + + IQccsyshal + qccsyshal + + + + vendor.qti.hardware.qccvndhal + 1.0 + + IQccvndhal + qccvndhal + + + + vendor.qti.hardware.qconfig + 1.0 + + IQConfig + default + + + + vendor.qti.hardware.qdutils_disp + 1.0 + + IQdutilsDisp + default + + + + vendor.qti.hardware.qseecom + 1.0 + + IQSEECom + default + + + + vendor.qti.hardware.qteeconnector + 1.0 + + IAppConnector + default + + + IGPAppConnector + default + + + + vendor.qti.hardware.qxr + + IQXRCoreService + default + + + + vendor.qti.hardware.qxr + + IQXRCamService + default + + + + vendor.qti.hardware.qxr + + IQXRSplitService + default + + + + vendor.qti.hardware.qxr + + IQXRModService + default + + + + vendor.qti.hardware.qxr + + IQXRAudioService + default + + + + vendor.qti.hardware.radio.am + 1.0 + + IQcRilAudio + slot1 + slot2 + + + + vendor.qti.hardware.radio.ims + 1.0-7 + + IImsRadio + imsradio0 + imsradio1 + + + + vendor.qti.hardware.radio.internal.deviceinfo + 1.0 + + IDeviceInfo + deviceinfo + + + + vendor.qti.hardware.radio.lpa + 1.0-2 + + IUimLpa + UimLpa0 + UimLpa1 + + + + vendor.qti.hardware.radio.qcriNvOpt + 1.0 + + IqcriNvOpt + qcrinvopt0 + qcrinvopt1 + + + + vendor.qti.hardware.radio.qcrilhook + 1.0 + + IQtiOemHook + oemhook0 + oemhook1 + + + + vendor.qti.hardware.radio.qtiradio + 1.0 + 2.0-6 + + IQtiRadio + slot1 + slot2 + + + + vendor.qti.hardware.radio.uim + 1.1-2 + + IUim + Uim0 + Uim1 + + + + vendor.qti.hardware.radio.uim_remote_client + 1.0 + + IUimRemoteServiceClient + uimRemoteClient0 + uimRemoteClient1 + + + + vendor.qti.hardware.radio.uim_remote_server + 1.0 + + IUimRemoteServiceServer + uimRemoteServer0 + uimRemoteServer1 + + + + vendor.qti.hardware.scve.objecttracker + 1.0 + + IObjectTracker + objectTracker + + + + vendor.qti.hardware.scve.panorama + 1.0 + + IPanoramaStitching + panoStitching + + + IPanoramaTracking + panoTracking + + + + vendor.qti.hardware.seccam + 1.0 + + ISecCam + default + + + + vendor.qti.hardware.secureprocessor.device + 1.0 + + ISecureProcessor + qti-tee + + + + vendor.qti.hardware.sensorscalibrate + 1.0 + + ISensorsCalibrate + default + + + + vendor.qti.hardware.servicetracker + 1.0-2 + + IServicetracker + default + + + + vendor.qti.hardware.slmadapter + 1.0 + + ISlmAdapter + SlmAdapter + + + + vendor.qti.hardware.soter + 1.0 + + ISoter + default + + + + vendor.qti.hardware.sxrhal + 1.0 + + ISxrCrypto + sxrhalservice + + + + vendor.qti.hardware.systemhelper + 1.0 + + ISystemEvent + default + + + ISystemResource + default + + + + vendor.qti.hardware.trustedui + 1.0-2 + + ITrustedInput + default + qtee-vm + + + ITrustedUI + default + qtee-vm + + + + vendor.qti.hardware.tui_comm + 1.0 + + ITuiComm + default + + + + vendor.qti.hardware.vpp + 1.1-3 + 2.0 + + IHidlVppService + vppService + + + + vendor.qti.hardware.wifi.hostapd + 1.0-3 + + IHostapdVendor + default + wigighostapd + + + + vendor.qti.hardware.wifi.supplicant + 2.0-3 + + ISupplicantVendor + default + + + + vendor.qti.hardware.wifi.wificfr + 1.0 + + IWificfr + wificfr + + + + vendor.qti.hardware.wifi.wifilearner + 1.0 + + IWifiStats + wifiStats + + + + vendor.qti.hardware.wifi.wifimyftm + 1.0 + + IWifiMyFtm + default + + + + vendor.qti.hardware.wifidisplaysession + 1.0 + + IWifiDisplaySession + wifidisplaysession + + + IWifiDisplaySessionAudioTrack + wifidisplaysessionaudiotrack + + + IWifiDisplaySessionImageTrack + wifidisplaysessionimagetrack + + + IWifiDisplaySessionVideoTrack + wifidisplaysessionvideotrack + + + + vendor.qti.hardware.wigig.netperftuner + 1.0 + + INetPerfTuner + default + + + + vendor.qti.hardware.wigig.supptunnel + 1.0 + + ISuppTunnelProvider + default + + + + vendor.qti.hardware.wipower + 1.0 + + IWipower + default + + + + vendor.qti.ims.callinfo + 1.0 + + IService + default + + + + vendor.qti.ims.factory + 1.0-1 + + IImsFactory + default + + + + vendor.qti.imsrtpservice + 3.0 + + IRTPService + imsrtpservice + + + + vendor.qti.memory.pasrmanager + 1.0-1 + + IPasrManager + pasrhal + + + + vendor.qti.power.pasrmanager + 1.0 + + IPasrManager + default + + + + vendor.qti.qesdhal + 1.0-1 + + IQesdhal + default + + + + vendor.qti.qspmhal + 1.0 + + IQspmhal + default + + + + vendor.qti.spu + 1.0-1 + + ISPUManager + default + + + + vendor.qti.voiceprint + 1.0 + + IQtiVoicePrintService + default + + + + vendor.silead.hardware.fingerprintext + 1.0 + + ISileadFingerprint + default + + + + vendor.xiaomi.hardware.fingerprintextension + 1.0 + + IXiaomiFingerprint + default + + + + vendor.xiaomi.hardware.mfidoca + 1.0 + + IFidoService + default + + + + vendor.xiaomi.hardware.micharge + 1.0 + + IMiCharge + default + + + + vendor.xiaomi.hardware.misys + 1.0 + + IMiSys + default + + + + vendor.xiaomi.hardware.misys + 2.0 + + IMiSys + default + + + + vendor.xiaomi.hardware.misys + 3.0 + + IMiSys + default + + + + vendor.xiaomi.hardware.mlipay + 1.0-1 + + IMlipayService + default + + + + vendor.xiaomi.hardware.mtdservice + 1.0-2 + + IMTService + default + + + + vendor.xiaomi.hardware.tidaservice + 1.0-2 + + ITidaService + default + + + + vendor.xiaomi.hardware.vibratorfeature + 1.0 + + IVibratorFeature + default + + + + vendor.xiaomi.hardware.vsimapp + 1.0 + + IVSIMService + default + + + diff --git a/gps/Android.bp b/gps/Android.bp new file mode 100644 index 0000000..ea0d991 --- /dev/null +++ b/gps/Android.bp @@ -0,0 +1,45 @@ +GNSS_CFLAGS = [ + "-Werror", + "-Wno-error=unused-parameter", + "-Wno-error=macro-redefined", + "-Wno-error=reorder", + "-Wno-error=missing-braces", + "-Wno-error=self-assign", + "-Wno-error=enum-conversion", + "-Wno-error=logical-op-parentheses", + "-Wno-error=null-arithmetic", + "-Wno-error=null-conversion", + "-Wno-error=parentheses-equality", + "-Wno-error=undefined-bool-conversion", + "-Wno-error=tautological-compare", + "-Wno-error=switch", + "-Wno-error=date-time", +] + +/* Activate the following for regression testing */ +GNSS_SANITIZE = { +/* address: true,*/ + cfi: true, + misc_undefined: [ + "bounds", + "null", + "unreachable", + "integer", + ], +} + +/* Activate the following for debug purposes only, + comment out for production */ +GNSS_SANITIZE_DIAG = { +/* + diag: { + cfi: true, + misc_undefined: [ + "bounds", + "null", + "unreachable", + "integer", + ], + }, +*/ +} diff --git a/gps/Android.mk b/gps/Android.mk new file mode 100644 index 0000000..77d61c9 --- /dev/null +++ b/gps/Android.mk @@ -0,0 +1,44 @@ +ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),) + +# Set required flags +GNSS_CFLAGS := \ + -Werror \ + -Wno-error=unused-parameter \ + -Wno-error=macro-redefined \ + -Wno-error=reorder \ + -Wno-error=missing-braces \ + -Wno-error=self-assign \ + -Wno-error=enum-conversion \ + -Wno-error=logical-op-parentheses \ + -Wno-error=null-arithmetic \ + -Wno-error=null-conversion \ + -Wno-error=parentheses-equality \ + -Wno-error=undefined-bool-conversion \ + -Wno-error=tautological-compare \ + -Wno-error=switch \ + -Wno-error=date-time + +GNSS_HIDL_VERSION = 2.1 + +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += msm8937 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += msm8953 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += msm8998 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += apq8098_latv +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += sdm710 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += qcs605 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += sdm845 +GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST += sdm660 + +ifneq (,$(filter $(GNSS_HIDL_LEGACY_MEASURMENTS_TARGET_LIST),$(TARGET_BOARD_PLATFORM))) +GNSS_HIDL_LEGACY_MEASURMENTS = true +endif + +LOCAL_PATH := $(call my-dir) +include $(call all-makefiles-under,$(LOCAL_PATH)) + +GNSS_SANITIZE := cfi bounds null unreachable integer +# Activate the following two lines for regression testing +#GNSS_SANITIZE += address +#GNSS_SANITIZE_DIAG := $(GNSS_SANITIZE) + +endif # ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),) diff --git a/gps/CleanSpec.mk b/gps/CleanSpec.mk new file mode 100644 index 0000000..dd1849d --- /dev/null +++ b/gps/CleanSpec.mk @@ -0,0 +1,50 @@ +# Copyright (C) 2007 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# If you don't need to do a full clean build but would like to touch +# a file or delete some intermediate files, add a clean step to the end +# of the list. These steps will only be run once, if they haven't been +# run before. +# +# E.g.: +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) +# +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with +# files that are missing or have been moved. +# +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. +# Use $(OUT_DIR) to refer to the "out" directory. +# +# If you need to re-do something that's already mentioned, just copy +# the command and add it to the bottom of the list. E.g., if a change +# that you made last week required touching a file and a change you +# made today requires touching the same file, just copy the old +# touch step and add it to the end of the list. +# +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ + +# For example: +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) + +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libloc_api*) diff --git a/gps/Makefile.am b/gps/Makefile.am new file mode 100644 index 0000000..cd4a731 --- /dev/null +++ b/gps/Makefile.am @@ -0,0 +1,10 @@ +# Makefile.am - Automake script for gps loc_api +# + +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = gnss + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = loc-hal.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/android/1.0/AGnss.cpp b/gps/android/1.0/AGnss.cpp new file mode 100644 index 0000000..79f665c --- /dev/null +++ b/gps/android/1.0/AGnss.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_AGnssInterface" + +#include +#include "Gnss.h" +#include "AGnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +static AGnss* spAGnss = nullptr; + +AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { + spAGnss = this; +} + +AGnss::~AGnss() { + spAGnss = nullptr; +} + +void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){ + if (nullptr != spAGnss) { + spAGnss->statusIpV4Cb(status); + } +} + +void AGnss::statusIpV4Cb(AGnssExtStatusIpV4 status) { + IAGnssCallback::AGnssStatusIpV4 st = {}; + + switch (status.type) { + case LOC_AGPS_TYPE_SUPL: + st.type = IAGnssCallback::AGnssType::TYPE_SUPL; + break; + case LOC_AGPS_TYPE_C2K: + st.type = IAGnssCallback::AGnssType::TYPE_C2K; + break; + default: + LOC_LOGE("invalid type: %d", status.type); + return; + } + + switch (status.status) { + case LOC_GPS_REQUEST_AGPS_DATA_CONN: + st.status = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN; + break; + case LOC_GPS_RELEASE_AGPS_DATA_CONN: + st.status = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN; + break; + case LOC_GPS_AGPS_DATA_CONNECTED: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED; + break; + case LOC_GPS_AGPS_DATA_CONN_DONE: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE; + break; + case LOC_GPS_AGPS_DATA_CONN_FAILED: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED; + break; + default: + LOC_LOGE("invalid status: %d", status.status); + return; + } + st.ipV4Addr = status.ipV4Addr; + + if (mAGnssCbIface != nullptr) { + auto r = mAGnssCbIface->agnssStatusIpV4Cb(st); + if (!r.isOk()) { + LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +Return AGnss::setCallback(const sp& callback) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return Void(); + } + + // Save the interface + mAGnssCbIface = callback; + + AgpsCbInfo cbInfo = {}; + cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES; + + mGnss->getGnssInterface()->agpsInit(cbInfo); + return Void(); +} + +Return AGnss::dataConnClosed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnFailed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnOpen(const hidl_string& apn, + IAGnss::ApnIpType apnIpType) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + /* Validate */ + if(apn.empty()){ + LOC_LOGE("Invalid APN"); + return false; + } + + LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str()); + + AGpsBearerType bearerType; + switch (apnIpType) { + case IAGnss::ApnIpType::IPV4: + bearerType = AGPS_APN_BEARER_IPV4; + break; + case IAGnss::ApnIpType::IPV6: + bearerType = AGPS_APN_BEARER_IPV6; + break; + case IAGnss::ApnIpType::IPV4V6: + bearerType = AGPS_APN_BEARER_IPV4V6; + break; + default: + bearerType = AGPS_APN_BEARER_IPV4; + break; + } + + mGnss->getGnssInterface()->agpsDataConnOpen( + LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType); + return true; +} + +Return AGnss::setServer(IAGnssCallback::AGnssType type, + const hidl_string& hostname, + int32_t port) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + if (type == IAGnssCallback::AGnssType::TYPE_SUPL) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL; + } else if (type == IAGnssCallback::AGnssType::TYPE_C2K) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K; + } else { + LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast(type)); + return false; + } + config.assistanceServer.hostName = strdup(hostname.c_str()); + config.assistanceServer.port = port; + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/AGnss.h b/gps/android/1.0/AGnss.h new file mode 100644 index 0000000..cdd5931 --- /dev/null +++ b/gps/android/1.0/AGnss.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_AGNSS_H +#define ANDROID_HARDWARE_GNSS_V1_0_AGNSS_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IAGnss; +using ::android::hardware::gnss::V1_0::IAGnssCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct AGnss : public IAGnss { + + AGnss(Gnss* gnss); + ~AGnss(); + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow. + * These declarations were generated from IAGnss.hal. + */ + Return setCallback(const sp& callback) override; + + Return dataConnClosed() override; + + Return dataConnFailed() override; + + Return dataConnOpen(const hidl_string& apn, + IAGnss::ApnIpType apnIpType) override; + + Return setServer(IAGnssCallback::AGnssType type, + const hidl_string& hostname, int32_t port) override; + + void statusIpV4Cb(AGnssExtStatusIpV4 status); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); + + private: + Gnss* mGnss = nullptr; + sp mAGnssCbIface = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_AGNSS_H diff --git a/gps/android/1.0/AGnssRil.cpp b/gps/android/1.0/AGnssRil.cpp new file mode 100644 index 0000000..d7f30eb --- /dev/null +++ b/gps/android/1.0/AGnssRil.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc__AGnssRilInterface" + +#include +#include +#include +#include +#include +#include +#include +#include "Gnss.h" +#include "AGnssRil.h" +#include + +typedef void* (getLocationInterface)(); + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + + +AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) { + ENTRY_LOG_CALLFLOW(); +} + +AGnssRil::~AGnssRil() { + ENTRY_LOG_CALLFLOW(); +} + +Return AGnssRil::updateNetworkState(bool connected, NetworkType type, bool /*roaming*/) { + ENTRY_LOG_CALLFLOW(); + // Extra NetworkTypes not available in IAgnssRil enums + const int NetworkType_BLUETOOTH = 7; + const int NetworkType_ETHERNET = 9; + const int NetworkType_PROXY = 16; + std::string apn(""); + + // for XTRA + if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) { + int8_t typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; + switch(type) + { + case IAGnssRil::NetworkType::MOBILE: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_MOBILE; + break; + case IAGnssRil::NetworkType::WIFI: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIFI; + break; + case IAGnssRil::NetworkType::MMS: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_MMS; + break; + case IAGnssRil::NetworkType::SUPL: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_SUPL; + break; + case IAGnssRil::NetworkType::DUN: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_DUN; + break; + case IAGnssRil::NetworkType::HIPRI: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_HIPRI; + break; + case IAGnssRil::NetworkType::WIMAX: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIMAX; + break; + default: + { + int networkType = (int) type; + // Handling network types not available in IAgnssRil + switch(networkType) + { + case NetworkType_BLUETOOTH: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_BLUETOOTH; + break; + case NetworkType_ETHERNET: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_ETHERNET; + break; + case NetworkType_PROXY: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_PROXY; + break; + default: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; + } + } + break; + } + mGnss->getGnssInterface()->updateConnectionStatus(connected, typeout, false, 0, apn); + } + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/AGnssRil.h b/gps/android/1.0/AGnssRil.h new file mode 100644 index 0000000..7f18c57 --- /dev/null +++ b/gps/android/1.0/AGnssRil.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ +#define ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IAGnssRil; +using ::android::hardware::gnss::V1_0::IAGnssRilCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +/* + * Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface + * allows the GNSS chipset to request radio interface layer information from Android platform. + * Examples of such information are reference location, unique subscriber ID, phone number string + * and network availability changes. Also contains wrapper methods to allow methods from + * IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL. + */ +struct AGnssRil : public IAGnssRil { + AGnssRil(Gnss* gnss); + ~AGnssRil(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow. + * These declarations were generated from IAGnssRil.hal. + */ + Return setCallback(const sp& /*callback*/) override { + return Void(); + } + Return setRefLocation(const IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override { + return Void(); + } + Return setSetId(IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override { + return false; + } + Return updateNetworkAvailability(bool /*available*/, + const hidl_string& /*apn*/) override { + return false; + } + Return updateNetworkState(bool connected, NetworkType type, bool roaming) override; + + private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ diff --git a/gps/android/1.0/Android.mk b/gps/android/1.0/Android.mk new file mode 100644 index 0000000..797ecce --- /dev/null +++ b/gps/android/1.0/Android.mk @@ -0,0 +1,99 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@1.0-impl-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + AGnss.cpp \ + Gnss.cpp \ + GnssBatching.cpp \ + GnssGeofencing.cpp \ + GnssMeasurement.cpp \ + GnssNi.cpp \ + GnssConfiguration.cpp \ + GnssDebug.cpp \ + AGnssRil.cpp + +LOCAL_SRC_FILES += \ + location_api/LocationUtil.cpp \ + location_api/GnssAPIClient.cpp \ + location_api/GeofenceAPIClient.cpp \ + location_api/BatchingAPIClient.cpp \ + location_api/MeasurementAPIClient.cpp \ + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers \ + liblocbatterylistener_headers + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libhidlbase \ + libcutils \ + libutils \ + android.hardware.gnss@1.0 \ + android.hardware.health@1.0 \ + android.hardware.health@2.0 \ + android.hardware.power@1.2 \ + libbase + +LOCAL_SHARED_LIBRARIES += \ + libloc_core \ + libgps.utils \ + libdl \ + liblocation_api \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) +LOCAL_STATIC_LIBRARIES := liblocbatterylistener +LOCAL_STATIC_LIBRARIES += libhealthhalutils +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@1.0-service-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VINTF_FRAGMENTS := android.hardware.gnss@1.0-service-qti.xml +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_INIT_RC := android.hardware.gnss@1.0-service-qti.rc +LOCAL_SRC_FILES := \ + service.cpp \ + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers + + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils \ + libgps.utils \ + libqti_vndfwk_detect \ + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + android.hardware.gnss@1.0 \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) + +ifneq ($(LOC_HIDL_VERSION),) +LOCAL_CFLAGS += -DLOC_HIDL_VERSION='"$(LOC_HIDL_VERSION)"' +endif + +include $(BUILD_EXECUTABLE) diff --git a/gps/android/1.0/Gnss.cpp b/gps/android/1.0/Gnss.cpp new file mode 100644 index 0000000..308cc7c --- /dev/null +++ b/gps/android/1.0/Gnss.cpp @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssInterface" +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include "Gnss.h" +#include +#include "battery_listener.h" +#include "loc_misc_utils.h" + +typedef const GnssInterface* (getLocationInterface)(); + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +static sp sGnss; +void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnss != nullptr) { + mGnss->getGnssInterface()->resetNetworkInfo(); + mGnss->stop(); + mGnss->cleanup(); + } +} + +void location_on_battery_status_changed(bool charging) { + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not "); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } +} +Gnss::Gnss() { + ENTRY_LOG_CALLFLOW(); + sGnss = this; + // initilize gnss interface at first in case needing notify battery status + sGnss->getGnssInterface()->initialize(); + // register health client to listen on battery change + loc_extn_battery_properties_listener_init(location_on_battery_status_changed); + // clear pending GnssConfig + memset(&mPendingConfig, 0, sizeof(GnssConfig)); + + mGnssDeathRecipient = new GnssDeathRecipient(this); +} + +Gnss::~Gnss() { + ENTRY_LOG_CALLFLOW(); + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } + sGnss = nullptr; +} + +GnssAPIClient* Gnss::getApi() { + if (mApi == nullptr && (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr)) { + mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface); + if (mApi == nullptr) { + LOC_LOGE("%s] faild to create GnssAPIClient", __FUNCTION__); + return mApi; + } + + if (mPendingConfig.size == sizeof(GnssConfig)) { + // we have pending GnssConfig + mApi->gnssConfigurationUpdate(mPendingConfig); + // clear size to invalid mPendingConfig + mPendingConfig.size = 0; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + } + } + } + if (mApi == nullptr) { + LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__); + } + return mApi; +} + +const GnssInterface* Gnss::getGnssInterface() { + static bool getGnssInterfaceFailed = false; + if (nullptr == mGnssInterface && !getGnssInterfaceFailed) { + void * libHandle = nullptr; + getLocationInterface* getter = (getLocationInterface*) + dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface"); + + if (nullptr == getter) { + getGnssInterfaceFailed = true; + } else { + mGnssInterface = (const GnssInterface*)(*getter)(); + } + } + return mGnssInterface; +} + +Return Gnss::setCallback(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface = callback; + if (mGnssCbIface != nullptr) { + mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + return true; +} + +Return Gnss::setGnssNiCb(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + mGnssNiCbIface = callback; + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + } + return true; +} + +Return Gnss::updateConfiguration(GnssConfig& gnssConfig) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssConfigurationUpdate(gnssConfig); + } else if (gnssConfig.flags != 0) { + // api is not ready yet, update mPendingConfig with gnssConfig + mPendingConfig.size = sizeof(GnssConfig); + + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + mPendingConfig.gpsLock = gnssConfig.gpsLock; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + mPendingConfig.suplVersion = gnssConfig.suplVersion; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + mPendingConfig.assistanceServer.hostName = + strdup(gnssConfig.assistanceServer.hostName); + } + mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT; + mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT; + mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + mPendingConfig.suplModeMask = gnssConfig.suplModeMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds; + } + } + return true; +} + +Return Gnss::start() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStart(); + } + return retVal; +} + +Return Gnss::stop() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStop(); + } + return retVal; +} + +Return Gnss::cleanup() { + ENTRY_LOG_CALLFLOW(); + + if (mApi != nullptr) { + mApi->gnssDisable(); + } + + return Void(); +} + +Return Gnss::injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters); + return true; + } else { + return false; + } +} + +Return Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs, + int32_t uncertaintyMs) { + return true; +} + +Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssDeleteAidingData(aidingDataFlags); + } + return Void(); +} + +Return Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs); + } + return retVal; +} + +Return> Gnss::getExtensionAGnss() { + ENTRY_LOG_CALLFLOW(); + mAGnssIface = new AGnss(this); + return mAGnssIface; +} + +Return> Gnss::getExtensionGnssNi() { + ENTRY_LOG_CALLFLOW(); + mGnssNi = new GnssNi(this); + return mGnssNi; +} + +Return> Gnss::getExtensionGnssMeasurement() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +} + +Return> Gnss::getExtensionGnssConfiguration() { + ENTRY_LOG_CALLFLOW(); + mGnssConfig = new GnssConfiguration(this); + return mGnssConfig; +} + +Return> Gnss::getExtensionGnssGeofencing() { + ENTRY_LOG_CALLFLOW(); + mGnssGeofencingIface = new GnssGeofencing(); + return mGnssGeofencingIface; +} + +Return> Gnss::getExtensionGnssBatching() { + mGnssBatching = new GnssBatching(); + return mGnssBatching; +} + +Return> Gnss::getExtensionGnssDebug() { + ENTRY_LOG_CALLFLOW(); + mGnssDebug = new GnssDebug(this); + return mGnssDebug; +} + +Return> Gnss::getExtensionAGnssRil() { + mGnssRil = new AGnssRil(this); + return mGnssRil; +} + +IGnss* HIDL_FETCH_IGnss(const char* hal) { + ENTRY_LOG_CALLFLOW(); + IGnss* iface = nullptr; + iface = new Gnss(); + if (iface == nullptr) { + LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal); + } + return iface; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/Gnss.h b/gps/android/1.0/Gnss.h new file mode 100644 index 0000000..900a510 --- /dev/null +++ b/gps/android/1.0/Gnss.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSS_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSS_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; + +struct Gnss : public IGnss { + Gnss(); + ~Gnss(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnss follow. + * These declarations were generated from Gnss.hal. + */ + Return setCallback(const sp& callback) override; + Return start() override; + Return stop() override; + Return cleanup() override; + Return injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) override; + Return injectTime(int64_t timeMs, + int64_t timeReferenceMs, + int32_t uncertaintyMs) override; + Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; + Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) override; + Return> getExtensionAGnss() override; + Return> getExtensionGnssNi() override; + Return> getExtensionGnssMeasurement() override; + Return> getExtensionGnssConfiguration() override; + Return> getExtensionGnssGeofencing() override; + Return> getExtensionGnssBatching() override; + + Return> getExtensionAGnssRil() override; + + inline Return> getExtensionGnssNavigationMessage() override { + return nullptr; + } + + inline Return> getExtensionXtra() override { + return nullptr; + } + + Return> getExtensionGnssDebug() override; + + // These methods are not part of the IGnss base class. + GnssAPIClient* getApi(); + Return setGnssNiCb(const sp& niCb); + Return updateConfiguration(GnssConfig& gnssConfig); + const GnssInterface* getGnssInterface(); + + // Callback for ODCPI request + void odcpiRequestCb(const OdcpiRequestInfo& request); + + private: + struct GnssDeathRecipient : hidl_death_recipient { + GnssDeathRecipient(sp gnss) : mGnss(gnss) { + } + ~GnssDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnss; + }; + + private: + sp mGnssDeathRecipient = nullptr; + + sp mAGnssIface = nullptr; + sp mGnssNi = nullptr; + sp mGnssMeasurement = nullptr; + sp mGnssConfig = nullptr; + sp mGnssGeofencingIface = nullptr; + sp mGnssBatching = nullptr; + sp mGnssDebug = nullptr; + sp mGnssRil = nullptr; + + GnssAPIClient* mApi = nullptr; + sp mGnssCbIface = nullptr; + sp mGnssNiCbIface = nullptr; + GnssConfig mPendingConfig; + const GnssInterface* mGnssInterface = nullptr; +}; + +extern "C" IGnss* HIDL_FETCH_IGnss(const char* name); + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSS_H diff --git a/gps/android/1.0/GnssBatching.cpp b/gps/android/1.0/GnssBatching.cpp new file mode 100644 index 0000000..f92697f --- /dev/null +++ b/gps/android/1.0/GnssBatching.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssBatchingInterface" + +#include +#include +#include "GnssBatching.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +void GnssBatching::GnssBatchingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssBatching != nullptr) { + mGnssBatching->stop(); + mGnssBatching->cleanup(); + } +} + +GnssBatching::GnssBatching() : mApi(nullptr) { + mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this); +} + +GnssBatching::~GnssBatching() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + + +// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. +Return GnssBatching::init(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface = callback; + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +Return GnssBatching::getBatchSize() { + uint16_t ret = 0; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->getBatchSize(); + } + return ret; +} + +Return GnssBatching::start(const IGnssBatching::Options& options) { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->startSession(options); + } + return ret; +} + +Return GnssBatching::flush() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->flushBatchedLocations(); + } + return Void(); +} + +Return GnssBatching::stop() { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->stopSession(); + } + return ret; +} + +Return GnssBatching::cleanup() { + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/GnssBatching.h b/gps/android/1.0/GnssBatching.h new file mode 100644 index 0000000..8fab857 --- /dev/null +++ b/gps/android/1.0/GnssBatching.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H + +#include +#include + + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssBatching; +using ::android::hardware::gnss::V1_0::IGnssBatchingCallback; +using ::android::hidl::base::V1_0::IBase; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class BatchingAPIClient; +struct GnssBatching : public IGnssBatching { + GnssBatching(); + ~GnssBatching(); + + // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. + Return init(const sp& callback) override; + Return getBatchSize() override; + Return start(const IGnssBatching::Options& options ) override; + Return flush() override; + Return stop() override; + Return cleanup() override; + + private: + struct GnssBatchingDeathRecipient : hidl_death_recipient { + GnssBatchingDeathRecipient(sp gnssBatching) : + mGnssBatching(gnssBatching) { + } + ~GnssBatchingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssBatching; + }; + + private: + sp mGnssBatchingDeathRecipient = nullptr; + sp mGnssBatchingCbIface = nullptr; + BatchingAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSBATCHING_H diff --git a/gps/android/1.0/GnssConfiguration.cpp b/gps/android/1.0/GnssConfiguration.cpp new file mode 100644 index 0000000..a7f64fa --- /dev/null +++ b/gps/android/1.0/GnssConfiguration.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssConfigurationInterface" + +#include +#include "Gnss.h" +#include "GnssConfiguration.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::GnssConstellationType; + +GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) { +} + +// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow. +Return GnssConfiguration::setSuplEs(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + config.suplEmergencyServices = (enabled ? + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES : + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO); + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplVersion(uint32_t version) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; + case 0x00020002: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; + break; + case 0x00020000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0; + break; + case 0x00010000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0; + break; + default: + LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplMode(uint8_t mode) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + switch (mode) { + case 0: + config.suplModeMask = 0; // STANDALONE ONLY + break; + case 1: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT; + break; + case 2: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + case 3: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + default: + LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setLppProfile(uint8_t lppProfileMask) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default + + if (lppProfileMask & (1<<0)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT; + } + if (lppProfileMask & (1<<1)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT; + } + if (lppProfileMask & (1<<2)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT; + } + if (lppProfileMask & (1<<3)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + + config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + if (protocol & (1<<0)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT; + } + if (protocol & (1<<1)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT; + } + if (protocol & (1<<2)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT; + } + if (protocol & (1<<3)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGpsLock(uint8_t lock) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + switch (lock) { + case 0: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + break; + case 1: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO; + break; + case 2: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI; + break; + case 3: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; + break; + default: + LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setEmergencySuplPdn(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + config.emergencyPdnForEmergencySupl = (enabled ? + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES : + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO); + + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/GnssConfiguration.h b/gps/android/1.0/GnssConfiguration.h new file mode 100644 index 0000000..d0e2ba8 --- /dev/null +++ b/gps/android/1.0/GnssConfiguration.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ + + /* Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSCONFIGURATION_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSSCONFIGURATION_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssConfiguration; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* + * Interface for passing GNSS configuration info from platform to HAL. + */ +struct Gnss; +struct GnssConfiguration : public IGnssConfiguration { + GnssConfiguration(Gnss* gnss); + ~GnssConfiguration() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. + * These declarations were generated from IGnssConfiguration.hal. + */ + Return setSuplVersion(uint32_t version) override; + Return setSuplMode(uint8_t mode) override; + Return setSuplEs(bool enabled) override; + Return setLppProfile(uint8_t lppProfileMask) override; + Return setGlonassPositioningProtocol(uint8_t protocol) override; + Return setEmergencySuplPdn(bool enable) override; + Return setGpsLock(uint8_t lock) override; + + private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSCONFIGURATION_H diff --git a/gps/android/1.0/GnssDebug.cpp b/gps/android/1.0/GnssDebug.cpp new file mode 100644 index 0000000..ead72e1 --- /dev/null +++ b/gps/android/1.0/GnssDebug.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssDebugInterface" + +#include +#include +#include "Gnss.h" +#include "GnssDebug.h" +#include "LocationUtil.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_vec; + +#define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000) +#define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000) +#define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500) +#define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) + +#define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm + +GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) +{ +} + +/* + * This methods requests position, time and satellite ephemeris debug information + * from the HAL. + * + * @return void +*/ +Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0 || + data.time.timeUncertaintyNs > (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + SatelliteData s = { }; + std::vector s_array = { }; + + for (uint32_t i=0; i +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssDebug; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* Interface for GNSS Debug support. */ +struct Gnss; +struct GnssDebug : public IGnssDebug { + GnssDebug(Gnss* gnss); + ~GnssDebug() {}; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow. + * These declarations were generated from IGnssDebug.hal. + */ + Return getDebugData(getDebugData_cb _hidl_cb) override; + +private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSDEBUG_H diff --git a/gps/android/1.0/GnssGeofencing.cpp b/gps/android/1.0/GnssGeofencing.cpp new file mode 100644 index 0000000..4be6d8a --- /dev/null +++ b/gps/android/1.0/GnssGeofencing.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GnssHal_GnssGeofencing" + +#include +#include +#include "GnssGeofencing.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssGeofencing != nullptr) { + mGnssGeofencing->removeAllGeofences(); + } +} + +GnssGeofencing::GnssGeofencing() : mApi(nullptr) { + mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this); +} + +GnssGeofencing::~GnssGeofencing() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. +Return GnssGeofencing::setCallback(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGE("%s]: mApi is NOT nullptr", __FUNCTION__); + return Void(); + } + + mApi = new GeofenceAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + } + + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient); + } + mGnssGeofencingCbIface = callback; + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssGeofencing::addGeofence( + int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceAdd( + geofenceId, + latitudeDegrees, + longitudeDegrees, + radiusMeters, + static_cast(lastTransition), + monitorTransitions, + notificationResponsivenessMs, + unknownTimerMs); + } + return Void(); +} + +Return GnssGeofencing::pauseGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofencePause(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceResume(geofenceId, monitorTransitions); + } + return Void(); +} + +Return GnssGeofencing::removeGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceRemove(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::removeAllGeofences() { + if (mApi == nullptr) { + LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__); + } else { + mApi->geofenceRemoveAll(); + } + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/GnssGeofencing.h b/gps/android/1.0/GnssGeofencing.h new file mode 100644 index 0000000..db5f9d2 --- /dev/null +++ b/gps/android/1.0/GnssGeofencing.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSGEOFENCING_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSSGEOFENCING_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::IGnssGeofencing; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class GeofenceAPIClient; +struct GnssGeofencing : public IGnssGeofencing { + GnssGeofencing(); + ~GnssGeofencing(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. + * These declarations were generated from IGnssGeofencing.hal. + */ + Return setCallback(const sp& callback) override; + Return addGeofence(int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) override; + + Return pauseGeofence(int32_t geofenceId) override; + Return resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override; + Return removeGeofence(int32_t geofenceId) override; + + private: + // This method is not part of the IGnss base class. + // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far. + Return removeAllGeofences(); + + private: + struct GnssGeofencingDeathRecipient : hidl_death_recipient { + GnssGeofencingDeathRecipient(sp gnssGeofencing) : + mGnssGeofencing(gnssGeofencing) { + } + ~GnssGeofencingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssGeofencing; + }; + + private: + sp mGnssGeofencingDeathRecipient = nullptr; + sp mGnssGeofencingCbIface = nullptr; + GeofenceAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSGEOFENCING_H diff --git a/gps/android/1.0/GnssMeasurement.cpp b/gps/android/1.0/GnssMeasurement.cpp new file mode 100644 index 0000000..7af9e27 --- /dev/null +++ b/gps/android/1.0/GnssMeasurement.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssMeasurementInterface" + +#include +#include +#include "GnssMeasurement.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssMeasurement != nullptr) { + mGnssMeasurement->close(); + } +} + +GnssMeasurement::GnssMeasurement() { + mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this); + mApi = new MeasurementAPIClient(); +} + +GnssMeasurement::~GnssMeasurement() { + if (mApi) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + +Return GnssMeasurement::setCallback( + const sp& callback) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + mGnssMeasurementCbIface = callback; + mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + return mApi->measurementSetCallback(callback); + +} + +Return GnssMeasurement::close() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return Void(); + } + + if (mGnssMeasurementCbIface != nullptr) { + mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface = nullptr; + } + mApi->measurementClose(); + + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/GnssMeasurement.h b/gps/android/1.0/GnssMeasurement.h new file mode 100644 index 0000000..4247dbf --- /dev/null +++ b/gps/android/1.0/GnssMeasurement.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSMEASUREMENT_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSSMEASUREMENT_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssMeasurement; +using ::android::hardware::gnss::V1_0::IGnssMeasurementCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class MeasurementAPIClient; +struct GnssMeasurement : public IGnssMeasurement { + GnssMeasurement(); + ~GnssMeasurement(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + * These declarations were generated from IGnssMeasurement.hal. + */ + Return setCallback( + const sp& callback) override; + Return close() override; + + private: + struct GnssMeasurementDeathRecipient : hidl_death_recipient { + GnssMeasurementDeathRecipient(sp gnssMeasurement) : + mGnssMeasurement(gnssMeasurement) { + } + ~GnssMeasurementDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssMeasurement; + }; + + private: + sp mGnssMeasurementDeathRecipient = nullptr; + sp mGnssMeasurementCbIface = nullptr; + MeasurementAPIClient* mApi; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSMEASUREMENT_H diff --git a/gps/android/1.0/GnssNi.cpp b/gps/android/1.0/GnssNi.cpp new file mode 100644 index 0000000..d06cc20 --- /dev/null +++ b/gps/android/1.0/GnssNi.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssNiInterface" + +#include +#include "Gnss.h" +#include "GnssNi.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + // we do nothing here + // Gnss::GnssDeathRecipient will stop the session +} + +GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) { + mGnssNiDeathRecipient = new GnssNiDeathRecipient(this); +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. +Return GnssNi::setCallback(const sp& callback) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + mGnss->setGnssNiCb(callback); + + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient); + } + mGnssNiCbIface = callback; + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + GnssAPIClient* api = mGnss->getApi(); + if (api == nullptr) { + LOC_LOGE("%s]: api is nullptr", __FUNCTION__); + return Void(); + } + + api->gnssNiRespond(notifId, userResponse); + + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/GnssNi.h b/gps/android/1.0/GnssNi.h new file mode 100644 index 0000000..90f62d5 --- /dev/null +++ b/gps/android/1.0/GnssNi.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GNSSNI_H +#define ANDROID_HARDWARE_GNSS_V1_0_GNSSNI_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssNi; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct GnssNi : public IGnssNi { + GnssNi(Gnss* gnss); + ~GnssNi() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. + * These declarations were generated from IGnssNi.hal. + */ + Return setCallback(const sp& callback) override; + Return respond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) override; + + private: + struct GnssNiDeathRecipient : hidl_death_recipient { + GnssNiDeathRecipient(sp gnssNi) : mGnssNi(gnssNi) { + } + ~GnssNiDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssNi; + }; + + private: + sp mGnssNiDeathRecipient = nullptr; + sp mGnssNiCbIface = nullptr; + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GNSSNI_H diff --git a/gps/android/1.0/android.hardware.gnss@1.0-service-qti.rc b/gps/android/1.0/android.hardware.gnss@1.0-service-qti.rc new file mode 100644 index 0000000..1fbd893 --- /dev/null +++ b/gps/android/1.0/android.hardware.gnss@1.0-service-qti.rc @@ -0,0 +1,4 @@ +service gnss_service /vendor/bin/hw/android.hardware.gnss@1.0-service-qti + class hal + user gps + group system gps radio vendor_qti_diag diff --git a/gps/android/1.0/android.hardware.gnss@1.0-service-qti.xml b/gps/android/1.0/android.hardware.gnss@1.0-service-qti.xml new file mode 100644 index 0000000..46bcffb --- /dev/null +++ b/gps/android/1.0/android.hardware.gnss@1.0-service-qti.xml @@ -0,0 +1,35 @@ + + + + android.hardware.gnss + hwbinder + @1.0::IGnss/default + + + diff --git a/gps/android/1.0/location_api/BatchingAPIClient.cpp b/gps/android/1.0/location_api/BatchingAPIClient.cpp new file mode 100644 index 0000000..94a234d --- /dev/null +++ b/gps/android/1.0/location_api/BatchingAPIClient.cpp @@ -0,0 +1,197 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_BatchingAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "BatchingAPIClient.h" + +#include "limits.h" + + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssBatching; +using ::android::hardware::gnss::V1_0::IGnssBatchingCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask); + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(callback), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + if (mGnssBatchingCbIface != nullptr) { + locationCallbacks.batchingCb = [this](size_t count, Location* location, + BatchingOptions batchOptions) { + onBatchingCb(count, location, batchOptions); + }; + } + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +BatchingAPIClient::~BatchingAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +int BatchingAPIClient::getBatchSize() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + return locAPIGetBatchSize(); +} + +int BatchingAPIClient::startSession(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::updateSessionOptions(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::stopSession() +{ + LOC_LOGD("%s]: ", __FUNCTION__); + int retVal = -1; + if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +void BatchingAPIClient::getBatchedLocation(int last_n_locations) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations); + locAPIGetBatchedLocations(mDefaultId, last_n_locations); +} + +void BatchingAPIClient::flushBatchedLocations() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + locAPIGetBatchedLocations(mDefaultId, SIZE_MAX); +} + +void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; +} + +void BatchingAPIClient::onBatchingCb(size_t count, Location* location, + BatchingOptions /*batchOptions*/) +{ + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count); + if (mGnssBatchingCbIface != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = mGnssBatchingCbIface->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask) +{ + memset(&out, 0, sizeof(LocationOptions)); + out.size = sizeof(LocationOptions); + out.minInterval = (uint32_t)(in.periodNanos / 1000000L); + out.minDistance = 0; + out.mode = GNSS_SUPL_MODE_STANDALONE; + if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + out.mode = GNSS_SUPL_MODE_MSA; + if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + out.mode = GNSS_SUPL_MODE_MSB; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/location_api/BatchingAPIClient.h b/gps/android/1.0/location_api/BatchingAPIClient.h new file mode 100644 index 0000000..c3b0a7b --- /dev/null +++ b/gps/android/1.0/location_api/BatchingAPIClient.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef BATCHING_API_CLINET_H +#define BATCHING_API_CLINET_H + +#include +#include +#include + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +class BatchingAPIClient : public LocationAPIClientBase +{ +public: + BatchingAPIClient(const sp& callback); + int getBatchSize(); + int startSession(const V1_0::IGnssBatching::Options& options); + int updateSessionOptions(const V1_0::IGnssBatching::Options& options); + int stopSession(); + void getBatchedLocation(int last_n_locations); + void flushBatchedLocations(); + + inline LocationCapabilitiesMask getCapabilities() { return mLocationCapabilitiesMask; } + + // callbacks + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions) final; + +private: + ~BatchingAPIClient(); + + sp mGnssBatchingCbIface; + uint32_t mDefaultId; + LocationCapabilitiesMask mLocationCapabilitiesMask; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // BATCHING_API_CLINET_H diff --git a/gps/android/1.0/location_api/GeofenceAPIClient.cpp b/gps/android/1.0/location_api/GeofenceAPIClient.cpp new file mode 100644 index 0000000..774a049 --- /dev/null +++ b/gps/android/1.0/location_api/GeofenceAPIClient.cpp @@ -0,0 +1,275 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GeofenceApiClient" + +#include +#include + +#include "LocationUtil.h" +#include "GeofenceAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +GeofenceAPIClient::GeofenceAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssGeofencingCbIface(callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + + locationCallbacks.geofenceBreachCb = nullptr; + if (mGnssGeofencingCbIface != nullptr) { + locationCallbacks.geofenceBreachCb = + [this](GeofenceBreachNotification geofenceBreachNotification) { + onGeofenceBreachCb(geofenceBreachNotification); + }; + + locationCallbacks.geofenceStatusCb = + [this](GeofenceStatusNotification geofenceStatusNotification) { + onGeofenceStatusCb(geofenceStatusNotification); + }; + } + + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms) +{ + LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__, + geofence_id, latitude, longitude, radius_meters, + last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms); + + GeofenceOption options; + memset(&options, 0, sizeof(GeofenceOption)); + options.size = sizeof(GeofenceOption); + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + options.breachTypeMask |= GEOFENCE_BREACH_EXIT_BIT; + options.responsiveness = notification_responsiveness_ms; + + GeofenceInfo data; + data.size = sizeof(GeofenceInfo); + data.latitude = latitude; + data.longitude = longitude; + data.radius = radius_meters; + + LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data); + if (LOCATION_ERROR_SUCCESS != err) { + onAddGeofencesCb(1, &err, &geofence_id); + } +} + +void GeofenceAPIClient::geofencePause(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIPauseGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions); + GeofenceBreachTypeMask mask = 0; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + mask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + mask |= GEOFENCE_BREACH_EXIT_BIT; + locAPIResumeGeofences(1, &geofence_id, &mask); +} + +void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIRemoveGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceRemoveAll() +{ + LOC_LOGD("%s]", __FUNCTION__); + // TODO locAPIRemoveAllGeofences(); +} + +// callbacks +void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, geofenceBreachNotification.count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < geofenceBreachNotification.count; i++) { + GnssLocation gnssLocation; + convertGnssLocation(geofenceBreachNotification.location, gnssLocation); + + IGnssGeofenceCallback::GeofenceTransition transition; + if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER) + transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED; + else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT) + transition = IGnssGeofenceCallback::GeofenceTransition::EXITED; + else { + // continue with other breach if transition is + // nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED + continue; + } + + auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb( + geofenceBreachNotification.ids[i], gnssLocation, transition, + static_cast(geofenceBreachNotification.timestamp)); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available); + if (mGnssGeofencingCbIface != nullptr) { + IGnssGeofenceCallback::GeofenceAvailability status = + IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE; + if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) { + status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE; + } + GnssLocation gnssLocation; + memset(&gnssLocation, 0, sizeof(GnssLocation)); + auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_EXISTS) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS; + auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/location_api/GeofenceAPIClient.h b/gps/android/1.0/location_api/GeofenceAPIClient.h new file mode 100644 index 0000000..b6a009b --- /dev/null +++ b/gps/android/1.0/location_api/GeofenceAPIClient.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GEOFENCE_API_CLINET_H +#define GEOFENCE_API_CLINET_H + + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::sp; + +class GeofenceAPIClient : public LocationAPIClientBase +{ +public: + GeofenceAPIClient(const sp& callback); + + void geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms); + void geofencePause(uint32_t geofence_id); + void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions); + void geofenceRemove(uint32_t geofence_id); + void geofenceRemoveAll(); + + // callbacks + void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final; + void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final; + void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + +private: + virtual ~GeofenceAPIClient() = default; + + sp mGnssGeofencingCbIface; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GEOFENCE_API_CLINET_H diff --git a/gps/android/1.0/location_api/GnssAPIClient.cpp b/gps/android/1.0/location_api/GnssAPIClient.cpp new file mode 100644 index 0000000..4247258 --- /dev/null +++ b/gps/android/1.0/location_api/GnssAPIClient.cpp @@ -0,0 +1,565 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GnssAPIClient" +#define SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC (590 * 60 * 60 * 1000) // 590 hours + +#include +#include +#include + +#include "LocationUtil.h" +#include "GnssAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnss; +using ::android::hardware::gnss::V1_0::IGnssCallback; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out); + +GnssAPIClient::GnssAPIClient(const sp& gpsCb, + const sp& niCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + // set default LocationOptions. + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = 1000; + mTrackingOptions.minDistance = 0; + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + + gnssUpdateCallbacks(gpsCb, niCb); +} + +GnssAPIClient::~GnssAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient) { + delete mControlClient; + mControlClient = nullptr; + } +} + +// for GpsInterface +void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + mMutex.lock(); + mGnssCbIface = gpsCb; + mGnssNiCbIface = niCb; + mMutex.unlock(); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.trackingCb = [this](Location location) { + onTrackingCb(location); + }; + } + + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + + locationCallbacks.gnssNiCb = nullptr; + loc_core::ContextBase* context = + loc_core::LocContext::getLocContext(loc_core::LocContext::mLocationHalName); + if (mGnssNiCbIface != nullptr && !context->hasAgpsExtendedCapabilities()) { + LOC_LOGD("Registering NI CB"); + locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotification) { + onGnssNiCb(id, gnssNiNotification); + }; + } + + locationCallbacks.gnssSvCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) { + onGnssSvCb(gnssSvNotification); + }; + } + + locationCallbacks.gnssNmeaCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) { + onGnssNmeaCb(gnssNmeaNotification); + }; + } + + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +bool GnssAPIClient::gnssStart() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + bool retVal = true; + locAPIStartTracking(mTrackingOptions); + return retVal; +} + +bool GnssAPIClient::gnssStop() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + bool retVal = true; + locAPIStopTracking(); + return retVal; +} + +bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode, + IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%d %d %d %d %d %d %d)", __FUNCTION__, + (int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, + preferredTimeMs, (int)powerMode, timeBetweenMeasurement); + bool retVal = true; + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = minIntervalMs; + if (IGnss::GnssPositionMode::MS_ASSISTED == mode || + IGnss::GnssPositionRecurrence::RECURRENCE_SINGLE == recurrence) { + // We set a very large interval to simulate SINGLE mode. Once we report a fix, + // the caller should take the responsibility to stop the session. + // For MSA, we always treat it as SINGLE mode. + mTrackingOptions.minInterval = SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC; + } + if (mode == IGnss::GnssPositionMode::STANDALONE) + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + else if (mode == IGnss::GnssPositionMode::MS_BASED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSB; + else if (mode == IGnss::GnssPositionMode::MS_ASSISTED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSA; + else { + LOC_LOGD("%s]: invalid GnssPositionMode: %d", __FUNCTION__, (int)mode); + retVal = false; + } + if (GNSS_POWER_MODE_INVALID != powerMode) { + mTrackingOptions.powerMode = powerMode; + mTrackingOptions.tbm = timeBetweenMeasurement; + } + locAPIUpdateTrackingOptions(mTrackingOptions); + return retVal; +} + +// for GpsNiInterface +void GnssAPIClient::gnssNiRespond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast(userResponse)); + GnssNiResponse data; + switch (userResponse) { + case IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT: + data = GNSS_NI_RESPONSE_ACCEPT; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY: + data = GNSS_NI_RESPONSE_DENY; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP: + data = GNSS_NI_RESPONSE_NO_RESPONSE; + break; + default: + data = GNSS_NI_RESPONSE_IGNORE; + break; + } + + locAPIGnssNiResponse(notifId, data); +} + +// these apis using LocationAPIControlClient +void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags) +{ + LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags); + if (mControlClient == nullptr) { + return; + } + GnssAidingData data; + memset(&data, 0, sizeof (GnssAidingData)); + data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS_BIT | + GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT | + GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT | + GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT | + GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT; + data.posEngineMask = STANDARD_POSITIONING_ENGINE; + + if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL) + data.deleteAll = true; + else { + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS) + data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC) + data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION) + data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME) + data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO) + data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC) + data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH) + data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR) + data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER) + data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA) + data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI) + data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO) + data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB_BIT; + } + mControlClient->locAPIGnssDeleteAidingData(data); +} + +void GnssAPIClient::gnssEnable(LocationTechnologyType techType) +{ + LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIEnable(techType); +} + +void GnssAPIClient::gnssDisable() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIDisable(); +} + +void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig) +{ + LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIGnssUpdateConfig(gnssConfig); +} + +void GnssAPIClient::requestCapabilities() { + // only send capablities if it's already cached, otherwise the first time LocationAPI + // is initialized, capabilities will be sent by LocationAPI + if (mLocationCapabilitiesCached) { + onCapabilitiesCb(mLocationCapabilitiesMask); + } +} + +// callbacks +void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; + mLocationCapabilitiesCached = true; + + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + uint32_t data = 0; + if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT)) + data |= IGnssCallback::Capabilities::SCHEDULING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT) + data |= IGnssCallback::Capabilities::GEOFENCING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) + data |= IGnssCallback::Capabilities::MEASUREMENTS; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + data |= IGnssCallback::Capabilities::MSB; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + data |= IGnssCallback::Capabilities::MSA; + auto r = gnssCbIface->gnssSetCapabilitesCb(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s", + __func__, r.description().c_str()); + } + } + if (gnssCbIface != nullptr) { + IGnssCallback::GnssSystemInfo gnssInfo = { .yearOfHw = 2015 }; + + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) { + gnssInfo.yearOfHw++; // 2016 + if (capabilitiesMask & LOCATION_CAPABILITIES_DEBUG_NMEA_BIT) { + gnssInfo.yearOfHw++; // 2017 + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT || + capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) { + gnssInfo.yearOfHw++; // 2018 + } + } + } + LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw); + auto r = gnssCbIface->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onTrackingCb(Location location) +{ + LOC_LOGD("%s]: (flags: %02x)", __FUNCTION__, location.flags); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface->gnssLocationCb(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) +{ + LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id); + mMutex.lock(); + auto gnssNiCbIface(mGnssNiCbIface); + mMutex.unlock(); + + if (gnssNiCbIface == nullptr) { + LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__); + return; + } + + IGnssNiCallback::GnssNiNotification notificationGnss = {}; + + notificationGnss.notificationId = id; + + if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL; + else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_EMERGENCY_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::EMERGENCY_SUPL; + + if (gnssNiNotification.options & GNSS_NI_OPTIONS_NOTIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_VERIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE; + + notificationGnss.timeoutSec = gnssNiNotification.timeout; + + if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE || + gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP; + + notificationGnss.requestorId = gnssNiNotification.requestor; + + notificationGnss.notificationMessage = gnssNiNotification.message; + + if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + gnssNiCbIface->niNotifyCb(notificationGnss); +} + +void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification) +{ + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, gnssSvNotification.count); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + IGnssCallback::GnssSvStatus svStatus; + convertGnssSvStatus(gnssSvNotification, svStatus); + auto r = gnssCbIface->gnssSvStatusCb(svStatus); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + const std::string s(gnssNmeaNotification.nmea); + std::stringstream ss(s); + std::string each; + while(std::getline(ss, each, '\n')) { + each += '\n'; + android::hardware::hidl_string nmeaString; + nmeaString.setToExternal(each.c_str(), each.length()); + auto r = gnssCbIface->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%zu description=%s", __func__, + gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } + } +} + +void GnssAPIClient::onStartTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS && gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onStopTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS && gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out) +{ + memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus)); + out.numSvs = in.count; + if (out.numSvs > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many satellites %u. Clamps to %d.", + __FUNCTION__, out.numSvs, V1_0::GnssMax::SVS_COUNT); + out.numSvs = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.numSvs; i++) { + IGnssCallback::GnssSvInfo& info = out.gnssSvList[i]; + convertGnssSvid(in.gnssSvs[i], info.svid); + convertGnssConstellationType(in.gnssSvs[i].type, info.constellation); + info.cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + info.elevationDegrees = in.gnssSvs[i].elevation; + info.azimuthDegrees = in.gnssSvs[i].azimuth; + info.carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + info.svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/location_api/GnssAPIClient.h b/gps/android/1.0/location_api/GnssAPIClient.h new file mode 100644 index 0000000..427b0db --- /dev/null +++ b/gps/android/1.0/location_api/GnssAPIClient.h @@ -0,0 +1,110 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GNSS_API_CLINET_H +#define GNSS_API_CLINET_H + + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::sp; + +class GnssAPIClient : public LocationAPIClientBase +{ +public: + GnssAPIClient(const sp& gpsCb, + const sp& niCb); + GnssAPIClient(const GnssAPIClient&) = delete; + GnssAPIClient& operator=(const GnssAPIClient&) = delete; + + // for GpsInterface + void gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb); + bool gnssStart(); + bool gnssStop(); + bool gnssSetPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = 0); + + // for GpsNiInterface + void gnssNiRespond(int32_t notifId, V1_0::IGnssNiCallback::GnssUserResponseType userResponse); + + // these apis using LocationAPIControlClient + void gnssDeleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags); + void gnssEnable(LocationTechnologyType techType); + void gnssDisable(); + void gnssConfigurationUpdate(const GnssConfig& gnssConfig); + + inline LocationCapabilitiesMask gnssGetCapabilities() const { + return mLocationCapabilitiesMask; + } + void requestCapabilities(); + + // callbacks we are interested in + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onTrackingCb(Location location) final; + void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final; + void onGnssSvCb(GnssSvNotification gnssSvNotification) final; + void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final; + + void onStartTrackingCb(LocationError error) final; + void onStopTrackingCb(LocationError error) final; + +private: + virtual ~GnssAPIClient(); + + sp mGnssCbIface; + sp mGnssNiCbIface; + std::mutex mMutex; + LocationAPIControlClient* mControlClient; + LocationCapabilitiesMask mLocationCapabilitiesMask; + bool mLocationCapabilitiesCached; + TrackingOptions mTrackingOptions; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GNSS_API_CLINET_H diff --git a/gps/android/1.0/location_api/LocationUtil.cpp b/gps/android/1.0/location_api/LocationUtil.cpp new file mode 100644 index 0000000..870a8aa --- /dev/null +++ b/gps/android/1.0/location_api/LocationUtil.cpp @@ -0,0 +1,274 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::V1_0::GnssConstellationType; +using ::android::hardware::gnss::V1_0::GnssLocationFlags; + +void convertGnssLocation(Location& in, GnssLocation& out) +{ + memset(&out, 0, sizeof(GnssLocation)); + if (in.flags & LOCATION_HAS_LAT_LONG_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG; + out.latitudeDegrees = in.latitude; + out.longitudeDegrees = in.longitude; + } + if (in.flags & LOCATION_HAS_ALTITUDE_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE; + out.altitudeMeters = in.altitude; + } + if (in.flags & LOCATION_HAS_SPEED_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED; + out.speedMetersPerSec = in.speed; + } + if (in.flags & LOCATION_HAS_BEARING_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING; + out.bearingDegrees = in.bearing; + } + if (in.flags & LOCATION_HAS_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY; + out.horizontalAccuracyMeters = in.accuracy; + } + if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY; + out.verticalAccuracyMeters = in.verticalAccuracy; + } + if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY; + out.speedAccuracyMetersPerSecond = in.speedAccuracy; + } + if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY; + out.bearingAccuracyDegrees = in.bearingAccuracy; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(const GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) { + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + out.latitude = in.latitudeDegrees; + out.longitude = in.longitudeDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) { + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + out.altitude = in.altitudeMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) { + out.flags |= LOCATION_HAS_SPEED_BIT; + out.speed = in.speedMetersPerSec; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { + out.flags |= LOCATION_HAS_BEARING_BIT; + out.bearing = in.bearingDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) { + out.flags |= LOCATION_HAS_ACCURACY_BIT; + out.accuracy = in.horizontalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + out.verticalAccuracy = in.verticalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) { + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + out.speedAccuracy = in.speedAccuracyMetersPerSecond; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) { + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.bearingAccuracy = in.bearingAccuracyDegrees; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssSvid(GnssSv& in, int16_t& out) +{ + switch(in.type){ + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out) +{ + switch (in.svType) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out) +{ + switch(in) { + case GNSS_EPH_TYPE_EPHEMERIS: + out = GnssDebug::SatelliteEphemerisType::EPHEMERIS; + break; + case GNSS_EPH_TYPE_ALMANAC: + out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY; + break; + case GNSS_EPH_TYPE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE; + break; + } +} + +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out) +{ + switch(in) { + case GNSS_EPH_SOURCE_DEMODULATED: + out = GnssDebug::SatelliteEphemerisSource::DEMODULATED; + break; + case GNSS_EPH_SOURCE_SUPL_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED; + break; + case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED; + break; + case GNSS_EPH_SOURCE_LOCAL: + case GNSS_EPH_SOURCE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisSource::OTHER; + break; + } +} + +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out) +{ + switch(in) { + case GNSS_EPH_HEALTH_GOOD: + out = GnssDebug::SatelliteEphemerisHealth::GOOD; + break; + case GNSS_EPH_HEALTH_BAD: + out = GnssDebug::SatelliteEphemerisHealth::BAD; + break; + case GNSS_EPH_HEALTH_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN; + break; + } +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/location_api/LocationUtil.h b/gps/android/1.0/location_api/LocationUtil.h new file mode 100644 index 0000000..f6760e5 --- /dev/null +++ b/gps/android/1.0/location_api/LocationUtil.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOCATION_UTIL_H +#define LOCATION_UTIL_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out); +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out); +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out); +void convertGnssSvid(GnssSv& in, int16_t& out); +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out); +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out); +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out); +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out); + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // LOCATION_UTIL_H diff --git a/gps/android/1.0/location_api/MeasurementAPIClient.cpp b/gps/android/1.0/location_api/MeasurementAPIClient.cpp new file mode 100644 index 0000000..9b23308 --- /dev/null +++ b/gps/android/1.0/location_api/MeasurementAPIClient.cpp @@ -0,0 +1,276 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_MeasurementAPIClient" + +#include +#include + +#include "LocationUtil.h" +#include "MeasurementAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssMeasurement; +using ::android::hardware::gnss::V1_0::IGnssMeasurementCallback; + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out); +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out); + +MeasurementAPIClient::MeasurementAPIClient() : + mGnssMeasurementCbIface(nullptr), + mTracking(false) +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +MeasurementAPIClient::~MeasurementAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +// for GpsInterface +Return +MeasurementAPIClient::measurementSetCallback(const sp& callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + mMutex.lock(); + mGnssMeasurementCbIface = callback; + mMutex.unlock(); + + return startTracking(); +} + +Return +MeasurementAPIClient::startTracking() +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + + locationCallbacks.gnssMeasurementsCb = nullptr; + if (mGnssMeasurementCbIface != nullptr) { + locationCallbacks.gnssMeasurementsCb = + [this](GnssMeasurementsNotification gnssMeasurementsNotification) { + onGnssMeasurementsCb(gnssMeasurementsNotification); + }; + } + + locAPISetCallbacks(locationCallbacks); + + TrackingOptions options = {}; + memset(&options, 0, sizeof(TrackingOptions)); + options.size = sizeof(TrackingOptions); + options.minInterval = 1000; + options.mode = GNSS_SUPL_MODE_STANDALONE; + + mTracking = true; + LOC_LOGD("%s]: start tracking session", __FUNCTION__); + locAPIStartTracking(options); + return IGnssMeasurement::GnssMeasurementStatus::SUCCESS; +} + +// for GpsMeasurementInterface +void MeasurementAPIClient::measurementClose() { + LOC_LOGD("%s]: ()", __FUNCTION__); + mTracking = false; + locAPIStopTracking(); +} + +// callbacks +void MeasurementAPIClient::onGnssMeasurementsCb( + GnssMeasurementsNotification gnssMeasurementsNotification) +{ + LOC_LOGD("%s]: (count: %zu active: %d)", + __FUNCTION__, gnssMeasurementsNotification.count, mTracking); + if (mTracking) { + mMutex.lock(); + sp gnssMeasurementCbIface = nullptr; + if (mGnssMeasurementCbIface != nullptr) { + gnssMeasurementCbIface = mGnssMeasurementCbIface; + } + mMutex.unlock(); + + if (gnssMeasurementCbIface != nullptr) { + V1_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from GnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out) +{ + memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssMeasurement)); + if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL; + convertGnssSvid(in, out.svid); + convertGnssConstellationType(in.svType, out.constellation); + out.timeOffsetNs = in.timeOffsetNs; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + out.receivedSvTimeInNs = in.receivedSvTimeNs; + out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs; + out.cN0DbHz = in.carrierToNoiseDbHz; + out.pseudorangeRateMps = in.pseudorangeRateMps; + out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + out.accumulatedDeltaRangeM = in.adrMeters; + out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters; + out.carrierFrequencyHz = in.carrierFrequencyHz; + out.carrierCycles = in.carrierCycles; + out.carrierPhase = in.carrierPhase; + out.carrierPhaseUncertainty = in.carrierPhaseUncertainty; + uint8_t indicator = + static_cast(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN); + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT; + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT; + out.multipathIndicator = + static_cast(indicator); + out.snrDb = in.signalToNoiseRatioDb; + out.agcLevelDb = in.agcLevelDb; +} + +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out) +{ + memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssClock)); + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY; + out.leapSecond = in.leapSecond; + out.timeNs = in.timeNs; + out.timeUncertaintyNs = in.timeUncertaintyNs; + out.fullBiasNs = in.fullBiasNs; + out.biasNs = in.biasNs; + out.biasUncertaintyNs = in.biasUncertaintyNs; + out.driftNsps = in.driftNsps; + out.driftUncertaintyNsps = in.driftUncertaintyNsps; + out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount; +} + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out) +{ + out.measurementCount = in.count; + if (out.measurementCount > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.", + __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT); + out.measurementCount = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.measurementCount; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i]); + } + convertGnssClock(in.clock, out.clock); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.0/location_api/MeasurementAPIClient.h b/gps/android/1.0/location_api/MeasurementAPIClient.h new file mode 100644 index 0000000..225deac --- /dev/null +++ b/gps/android/1.0/location_api/MeasurementAPIClient.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef MEASUREMENT_API_CLINET_H +#define MEASUREMENT_API_CLINET_H + +#include +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_0 { +namespace implementation { + +using ::android::sp; + +class MeasurementAPIClient : public LocationAPIClientBase +{ +public: + MeasurementAPIClient(); + MeasurementAPIClient(const MeasurementAPIClient&) = delete; + MeasurementAPIClient& operator=(const MeasurementAPIClient&) = delete; + + // for GpsMeasurementInterface + Return measurementSetCallback( + const sp& callback); + void measurementClose(); + Return startTracking(); + + // callbacks we are interested in + void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final; + +private: + virtual ~MeasurementAPIClient(); + + std::mutex mMutex; + sp mGnssMeasurementCbIface; + + bool mTracking; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // MEASUREMENT_API_CLINET_H diff --git a/gps/android/1.0/service.cpp b/gps/android/1.0/service.cpp new file mode 100644 index 0000000..2a6f60f --- /dev/null +++ b/gps/android/1.0/service.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.gnss@1.0-service-qti" + +#include +#include +#include "loc_cfg.h" +#include "loc_misc_utils.h" + +extern "C" { +#include "vndfwk-detect.h" +} + +#ifdef ARCH_ARM_32 +#define DEFAULT_HW_BINDER_MEM_SIZE 65536 +#endif + +using android::hardware::gnss::V1_0::IGnss; + +using android::hardware::configureRpcThreadpool; +using android::hardware::registerPassthroughServiceImplementation; +using android::hardware::joinRpcThreadpool; + +using android::status_t; +using android::OK; + +typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []); + +int main() { + + ALOGI("%s", __FUNCTION__); + + int vendorInfo = getVendorEnhancedInfo(); + bool vendorEnhanced = ( 1 == vendorInfo || 3 == vendorInfo ); + setVendorEnhanced(vendorEnhanced); + +#ifdef ARCH_ARM_32 + android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE)); +#endif + configureRpcThreadpool(1, true); + status_t status; + + status = registerPassthroughServiceImplementation(); + if (status == OK) { + if (vendorEnhanced) { + #ifdef LOC_HIDL_VERSION + #define VENDOR_ENHANCED_LIB "vendor.qti.gnss@" LOC_HIDL_VERSION "-service.so" + + void* libHandle = NULL; + vendorEnhancedServiceMain* vendorEnhancedMainMethod = (vendorEnhancedServiceMain*) + dlGetSymFromLib(libHandle, VENDOR_ENHANCED_LIB, "main"); + if (NULL != vendorEnhancedMainMethod) { + (*vendorEnhancedMainMethod)(0, NULL); + } + #else + ALOGE("LOC_HIDL_VERSION not defined."); + #endif + } + + joinRpcThreadpool(); + + } else { + ALOGE("Error while registering IGnss 1.0 service: %d", status); + } + + return 0; +} diff --git a/gps/android/1.1/AGnss.cpp b/gps/android/1.1/AGnss.cpp new file mode 100644 index 0000000..d8f9706 --- /dev/null +++ b/gps/android/1.1/AGnss.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_AGnssInterface" + +#include +#include "Gnss.h" +#include "AGnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +static AGnss* spAGnss = nullptr; + +AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { + spAGnss = this; +} + +AGnss::~AGnss() { + spAGnss = nullptr; +} + +void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){ + if (nullptr != spAGnss) { + spAGnss->statusIpV4Cb(status); + } +} + +void AGnss::statusIpV4Cb(AGnssExtStatusIpV4 status) { + IAGnssCallback::AGnssStatusIpV4 st = {}; + + switch (status.type) { + case LOC_AGPS_TYPE_SUPL: + st.type = IAGnssCallback::AGnssType::TYPE_SUPL; + break; + case LOC_AGPS_TYPE_C2K: + st.type = IAGnssCallback::AGnssType::TYPE_C2K; + break; + default: + LOC_LOGE("invalid type: %d", status.type); + return; + } + + switch (status.status) { + case LOC_GPS_REQUEST_AGPS_DATA_CONN: + st.status = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN; + break; + case LOC_GPS_RELEASE_AGPS_DATA_CONN: + st.status = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN; + break; + case LOC_GPS_AGPS_DATA_CONNECTED: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED; + break; + case LOC_GPS_AGPS_DATA_CONN_DONE: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE; + break; + case LOC_GPS_AGPS_DATA_CONN_FAILED: + st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED; + break; + default: + LOC_LOGE("invalid status: %d", status.status); + return; + } + st.ipV4Addr = status.ipV4Addr; + + if (mAGnssCbIface != nullptr) { + auto r = mAGnssCbIface->agnssStatusIpV4Cb(st); + if (!r.isOk()) { + LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +Return AGnss::setCallback(const sp& callback) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return Void(); + } + + // Save the interface + mAGnssCbIface = callback; + + AgpsCbInfo cbInfo = {}; + cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES; + + mGnss->getGnssInterface()->agpsInit(cbInfo); + return Void(); +} + +Return AGnss::dataConnClosed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnFailed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnOpen(const hidl_string& apn, + IAGnss::ApnIpType apnIpType) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + /* Validate */ + if(apn.empty()){ + LOC_LOGE("Invalid APN"); + return false; + } + + LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str()); + + AGpsBearerType bearerType; + switch (apnIpType) { + case IAGnss::ApnIpType::IPV4: + bearerType = AGPS_APN_BEARER_IPV4; + break; + case IAGnss::ApnIpType::IPV6: + bearerType = AGPS_APN_BEARER_IPV6; + break; + case IAGnss::ApnIpType::IPV4V6: + bearerType = AGPS_APN_BEARER_IPV4V6; + break; + default: + bearerType = AGPS_APN_BEARER_IPV4; + break; + } + + mGnss->getGnssInterface()->agpsDataConnOpen( + LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType); + return true; +} + +Return AGnss::setServer(IAGnssCallback::AGnssType type, + const hidl_string& hostname, + int32_t port) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + if (type == IAGnssCallback::AGnssType::TYPE_SUPL) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL; + } else if (type == IAGnssCallback::AGnssType::TYPE_C2K) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K; + } else { + LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast(type)); + return false; + } + config.assistanceServer.hostName = strdup(hostname.c_str()); + config.assistanceServer.port = port; + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/AGnss.h b/gps/android/1.1/AGnss.h new file mode 100644 index 0000000..4b599b9 --- /dev/null +++ b/gps/android/1.1/AGnss.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H +#define ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IAGnss; +using ::android::hardware::gnss::V1_0::IAGnssCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct AGnss : public IAGnss { + + AGnss(Gnss* gnss); + ~AGnss(); + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow. + * These declarations were generated from IAGnss.hal. + */ + Return setCallback(const sp& callback) override; + + Return dataConnClosed() override; + + Return dataConnFailed() override; + + Return dataConnOpen(const hidl_string& apn, + IAGnss::ApnIpType apnIpType) override; + + Return setServer(IAGnssCallback::AGnssType type, + const hidl_string& hostname, int32_t port) override; + + void statusIpV4Cb(AGnssExtStatusIpV4 status); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); + + private: + Gnss* mGnss = nullptr; + sp mAGnssCbIface = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H diff --git a/gps/android/1.1/AGnssRil.cpp b/gps/android/1.1/AGnssRil.cpp new file mode 100644 index 0000000..95c8d63 --- /dev/null +++ b/gps/android/1.1/AGnssRil.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc__AGnssRilInterface" + +#include +#include +#include +#include +#include +#include +#include +#include "Gnss.h" +#include "AGnssRil.h" +#include + +typedef void* (getLocationInterface)(); + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + + +AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) { + ENTRY_LOG_CALLFLOW(); +} + +AGnssRil::~AGnssRil() { + ENTRY_LOG_CALLFLOW(); +} + +Return AGnssRil::updateNetworkState(bool connected, NetworkType type, bool /*roaming*/) { + ENTRY_LOG_CALLFLOW(); + // Extra NetworkTypes not available in IAgnssRil enums + const int NetworkType_BLUETOOTH = 7; + const int NetworkType_ETHERNET = 9; + const int NetworkType_PROXY = 16; + std::string apn(""); + + // for XTRA + if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) { + int8_t typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; + switch(type) + { + case IAGnssRil::NetworkType::MOBILE: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_MOBILE; + break; + case IAGnssRil::NetworkType::WIFI: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIFI; + break; + case IAGnssRil::NetworkType::MMS: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_MMS; + break; + case IAGnssRil::NetworkType::SUPL: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_SUPL; + break; + case IAGnssRil::NetworkType::DUN: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_DUN; + break; + case IAGnssRil::NetworkType::HIPRI: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_HIPRI; + break; + case IAGnssRil::NetworkType::WIMAX: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_WIMAX; + break; + default: + { + int networkType = (int) type; + // Handling network types not available in IAgnssRil + switch(networkType) + { + case NetworkType_BLUETOOTH: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_BLUETOOTH; + break; + case NetworkType_ETHERNET: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_ETHERNET; + break; + case NetworkType_PROXY: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_PROXY; + break; + default: + typeout = loc_core::NetworkInfoDataItemBase::TYPE_UNKNOWN; + } + } + break; + } + mGnss->getGnssInterface()->updateConnectionStatus(connected, typeout, false, 0, apn); + } + return true; +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/AGnssRil.h b/gps/android/1.1/AGnssRil.h new file mode 100644 index 0000000..5c9298a --- /dev/null +++ b/gps/android/1.1/AGnssRil.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ +#define ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IAGnssRil; +using ::android::hardware::gnss::V1_0::IAGnssRilCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +/* + * Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface + * allows the GNSS chipset to request radio interface layer information from Android platform. + * Examples of such information are reference location, unique subscriber ID, phone number string + * and network availability changes. Also contains wrapper methods to allow methods from + * IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL. + */ +struct AGnssRil : public IAGnssRil { + AGnssRil(Gnss* gnss); + ~AGnssRil(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow. + * These declarations were generated from IAGnssRil.hal. + */ + Return setCallback(const sp& /*callback*/) override { + return Void(); + } + Return setRefLocation(const IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override { + return Void(); + } + Return setSetId(IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override { + return false; + } + Return updateNetworkAvailability(bool /*available*/, + const hidl_string& /*apn*/) override { + return false; + } + Return updateNetworkState(bool connected, NetworkType type, bool roaming) override; + + private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_ diff --git a/gps/android/1.1/Android.mk b/gps/android/1.1/Android.mk new file mode 100644 index 0000000..66abd06 --- /dev/null +++ b/gps/android/1.1/Android.mk @@ -0,0 +1,101 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@1.1-impl-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + AGnss.cpp \ + Gnss.cpp \ + GnssBatching.cpp \ + GnssGeofencing.cpp \ + GnssMeasurement.cpp \ + GnssNi.cpp \ + GnssConfiguration.cpp \ + GnssDebug.cpp \ + AGnssRil.cpp + +LOCAL_SRC_FILES += \ + location_api/LocationUtil.cpp \ + location_api/GnssAPIClient.cpp \ + location_api/GeofenceAPIClient.cpp \ + location_api/BatchingAPIClient.cpp \ + location_api/MeasurementAPIClient.cpp \ + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers \ + liblocbatterylistener_headers + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libhidlbase \ + libcutils \ + libutils \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + android.hardware.health@1.0 \ + android.hardware.health@2.0 \ + android.hardware.power@1.2 \ + libbase + +LOCAL_SHARED_LIBRARIES += \ + libloc_core \ + libgps.utils \ + libdl \ + liblocation_api \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) +LOCAL_STATIC_LIBRARIES := liblocbatterylistener +LOCAL_STATIC_LIBRARIES += libhealthhalutils +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@1.1-service-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VINTF_FRAGMENTS := android.hardware.gnss@1.1-service-qti.xml +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_INIT_RC := android.hardware.gnss@1.1-service-qti.rc +LOCAL_SRC_FILES := \ + service.cpp \ + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers + + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils \ + libgps.utils \ + libqti_vndfwk_detect \ + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) + +ifneq ($(LOC_HIDL_VERSION),) +LOCAL_CFLAGS += -DLOC_HIDL_VERSION='"$(LOC_HIDL_VERSION)"' +endif + +include $(BUILD_EXECUTABLE) diff --git a/gps/android/1.1/Gnss.cpp b/gps/android/1.1/Gnss.cpp new file mode 100644 index 0000000..537f6a6 --- /dev/null +++ b/gps/android/1.1/Gnss.cpp @@ -0,0 +1,466 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssInterface" +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include "Gnss.h" +#include + +#include "battery_listener.h" +#include "loc_misc_utils.h" + +typedef const GnssInterface* (getLocationInterface)(); + +#define IMAGES_INFO_FILE "/sys/devices/soc0/images" +#define DELIMITER ";" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +static sp sGnss; +static std::string getVersionString() { + static std::string version; + if (!version.empty()) + return version; + + char value[PROPERTY_VALUE_MAX] = {0}; + property_get("ro.hardware", value, "unknown"); + version.append(value).append(DELIMITER); + + std::ifstream in(IMAGES_INFO_FILE); + std::string s; + while(getline(in, s)) { + std::size_t found = s.find("CRM:"); + if (std::string::npos == found) { + continue; + } + + // skip over space characters after "CRM:" + const char* substr = s.c_str(); + found += 4; + while (0 != substr[found] && isspace(substr[found])) { + found++; + } + if (s.find("11:") != found) { + continue; + } + s.erase(0, found + 3); + + found = s.find_first_of("\r\n"); + if (std::string::npos != found) { + s.erase(s.begin() + found, s.end()); + } + version.append(s).append(DELIMITER); + } + return version; +} + +void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnss != nullptr) { + mGnss->getGnssInterface()->resetNetworkInfo(); + mGnss->stop(); + mGnss->cleanup(); + } +} + +void location_on_battery_status_changed(bool charging) { + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not"); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } +} +Gnss::Gnss() { + ENTRY_LOG_CALLFLOW(); + sGnss = this; + // initilize gnss interface at first in case needing notify battery status + sGnss->getGnssInterface()->initialize(); + // register health client to listen on battery change + loc_extn_battery_properties_listener_init(location_on_battery_status_changed); + // clear pending GnssConfig + memset(&mPendingConfig, 0, sizeof(GnssConfig)); + + mGnssDeathRecipient = new GnssDeathRecipient(this); +} + +Gnss::~Gnss() { + ENTRY_LOG_CALLFLOW(); + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } + sGnss = nullptr; +} + +GnssAPIClient* Gnss::getApi() { + if (mApi == nullptr && (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr)) { + mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface); + if (mApi == nullptr) { + LOC_LOGE("%s] faild to create GnssAPIClient", __FUNCTION__); + return mApi; + } + + if (mPendingConfig.size == sizeof(GnssConfig)) { + // we have pending GnssConfig + mApi->gnssConfigurationUpdate(mPendingConfig); + // clear size to invalid mPendingConfig + mPendingConfig.size = 0; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + } + } + } + if (mApi == nullptr) { + LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__); + } + return mApi; +} + +const GnssInterface* Gnss::getGnssInterface() { + static bool getGnssInterfaceFailed = false; + if (nullptr == mGnssInterface && !getGnssInterfaceFailed) { + void * libHandle = nullptr; + getLocationInterface* getter = (getLocationInterface*) + dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface"); + + if (nullptr == getter) { + getGnssInterfaceFailed = true; + } else { + mGnssInterface = (const GnssInterface*)(*getter)(); + } + } + return mGnssInterface; +} + +Return Gnss::setCallback(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface = callback; + if (mGnssCbIface != nullptr) { + mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + return true; +} + +Return Gnss::setGnssNiCb(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + mGnssNiCbIface = callback; + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + } + return true; +} + +Return Gnss::updateConfiguration(GnssConfig& gnssConfig) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssConfigurationUpdate(gnssConfig); + } else if (gnssConfig.flags != 0) { + // api is not ready yet, update mPendingConfig with gnssConfig + mPendingConfig.size = sizeof(GnssConfig); + + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + mPendingConfig.gpsLock = gnssConfig.gpsLock; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + mPendingConfig.suplVersion = gnssConfig.suplVersion; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + mPendingConfig.assistanceServer.hostName = + strdup(gnssConfig.assistanceServer.hostName); + } + mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT; + mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT; + mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + mPendingConfig.suplModeMask = gnssConfig.suplModeMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds; + } + } + return true; +} + +Return Gnss::start() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStart(); + } + return retVal; +} + +Return Gnss::stop() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStop(); + } + return retVal; +} + +Return Gnss::cleanup() { + ENTRY_LOG_CALLFLOW(); + + if (mApi != nullptr) { + mApi->gnssDisable(); + } + + return Void(); +} + +Return Gnss::injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters); + return true; + } else { + return false; + } +} + +Return Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs, + int32_t uncertaintyMs) { + return true; +} + +Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssDeleteAidingData(aidingDataFlags); + } + return Void(); +} + +Return Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs); + } + return retVal; +} + +Return> Gnss::getExtensionAGnss() { + ENTRY_LOG_CALLFLOW(); + mAGnssIface = new AGnss(this); + return mAGnssIface; +} + +Return> Gnss::getExtensionGnssNi() { + ENTRY_LOG_CALLFLOW(); + mGnssNi = new GnssNi(this); + return mGnssNi; +} + +Return> Gnss::getExtensionGnssMeasurement() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +} + +Return> Gnss::getExtensionGnssConfiguration() { + ENTRY_LOG_CALLFLOW(); + mGnssConfig = new GnssConfiguration(this); + return mGnssConfig; +} + +Return> Gnss::getExtensionGnssGeofencing() { + ENTRY_LOG_CALLFLOW(); + mGnssGeofencingIface = new GnssGeofencing(); + return mGnssGeofencingIface; +} + +Return> Gnss::getExtensionGnssBatching() { + mGnssBatching = new GnssBatching(); + return mGnssBatching; +} + +Return> Gnss::getExtensionGnssDebug() { + ENTRY_LOG_CALLFLOW(); + mGnssDebug = new GnssDebug(this); + return mGnssDebug; +} + +Return> Gnss::getExtensionAGnssRil() { + mGnssRil = new AGnssRil(this); + return mGnssRil; +} + +// Methods from ::android::hardware::gnss::V1_1::IGnss follow. +Return Gnss::setCallback_1_1(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + callback->gnssNameCb(getVersionString()); + mGnssCbIface_1_1 = callback; + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + return setCallback(callback); +} + +Return Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + bool lowPowerMode) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + GnssPowerMode powerMode = lowPowerMode? + GNSS_POWER_MODE_M4 : GNSS_POWER_MODE_M2; + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs, powerMode, minIntervalMs); + } + return retVal; +} + +Return> Gnss::getExtensionGnssMeasurement_1_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +} + +Return> Gnss::getExtensionGnssConfiguration_1_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) + mGnssConfig = new GnssConfiguration(this); + return mGnssConfig; +} + +Return Gnss::injectBestLocation(const GnssLocation& gnssLocation) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } + return true; +} + +void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) { + ENTRY_LOG_CALLFLOW(); + if (ODCPI_REQUEST_TYPE_STOP == request.type) { + return; + } + if (mGnssCbIface_1_1 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + auto r = mGnssCbIface_1_1->gnssRequestLocationCb(!request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else { + LOC_LOGe("ODCPI request not supported."); + } +} + +V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) { + ENTRY_LOG_CALLFLOW(); + V1_0::IGnss* iface = nullptr; + iface = new Gnss(); + if (iface == nullptr) { + LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal); + } + return iface; +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/Gnss.h b/gps/android/1.1/Gnss.h new file mode 100644 index 0000000..15645eb --- /dev/null +++ b/gps/android/1.1/Gnss.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2017-2018-2018-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSS_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; + +struct Gnss : public IGnss { + Gnss(); + ~Gnss(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnss follow. + * These declarations were generated from Gnss.hal. + */ + Return setCallback(const sp& callback) override; + Return start() override; + Return stop() override; + Return cleanup() override; + Return injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) override; + Return injectTime(int64_t timeMs, + int64_t timeReferenceMs, + int32_t uncertaintyMs) override; + Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; + Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) override; + Return> getExtensionAGnss() override; + Return> getExtensionGnssNi() override; + Return> getExtensionGnssMeasurement() override; + Return> getExtensionGnssConfiguration() override; + Return> getExtensionGnssGeofencing() override; + Return> getExtensionGnssBatching() override; + + Return> getExtensionAGnssRil() override; + + inline Return> getExtensionGnssNavigationMessage() override { + return nullptr; + } + + inline Return> getExtensionXtra() override { + return nullptr; + } + + Return> getExtensionGnssDebug() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnss follow. + Return setCallback_1_1(const sp& callback) override; + Return setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, bool lowPowerMode) override; + Return> getExtensionGnssMeasurement_1_1() override; + Return> getExtensionGnssConfiguration_1_1() override; + Return injectBestLocation(const GnssLocation& location) override; + + // These methods are not part of the IGnss base class. + GnssAPIClient* getApi(); + Return setGnssNiCb(const sp& niCb); + Return updateConfiguration(GnssConfig& gnssConfig); + const GnssInterface* getGnssInterface(); + + // Callback for ODCPI request + void odcpiRequestCb(const OdcpiRequestInfo& request); + + private: + struct GnssDeathRecipient : hidl_death_recipient { + GnssDeathRecipient(sp gnss) : mGnss(gnss) { + } + ~GnssDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnss; + }; + + private: + sp mGnssDeathRecipient = nullptr; + + sp mAGnssIface = nullptr; + sp mGnssNi = nullptr; + sp mGnssMeasurement = nullptr; + sp mGnssConfig = nullptr; + sp mGnssGeofencingIface = nullptr; + sp mGnssBatching = nullptr; + sp mGnssDebug = nullptr; + sp mGnssRil = nullptr; + + GnssAPIClient* mApi = nullptr; + sp mGnssCbIface = nullptr; + sp mGnssCbIface_1_1 = nullptr; + sp mGnssNiCbIface = nullptr; + GnssConfig mPendingConfig; + const GnssInterface* mGnssInterface = nullptr; +}; + +extern "C" V1_0::IGnss* HIDL_FETCH_IGnss(const char* name); + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSS_H diff --git a/gps/android/1.1/GnssBatching.cpp b/gps/android/1.1/GnssBatching.cpp new file mode 100644 index 0000000..8ab264d --- /dev/null +++ b/gps/android/1.1/GnssBatching.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssBatchingInterface" + +#include +#include +#include "GnssBatching.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +void GnssBatching::GnssBatchingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssBatching != nullptr) { + mGnssBatching->stop(); + mGnssBatching->cleanup(); + } +} + +GnssBatching::GnssBatching() : mApi(nullptr) { + mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this); +} + +GnssBatching::~GnssBatching() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + + +// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. +Return GnssBatching::init(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface = callback; + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +Return GnssBatching::getBatchSize() { + uint16_t ret = 0; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->getBatchSize(); + } + return ret; +} + +Return GnssBatching::start(const IGnssBatching::Options& options) { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->startSession(options); + } + return ret; +} + +Return GnssBatching::flush() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->flushBatchedLocations(); + } + return Void(); +} + +Return GnssBatching::stop() { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->stopSession(); + } + return ret; +} + +Return GnssBatching::cleanup() { + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + return Void(); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/GnssBatching.h b/gps/android/1.1/GnssBatching.h new file mode 100644 index 0000000..8e235d8 --- /dev/null +++ b/gps/android/1.1/GnssBatching.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H + +#include +#include + + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssBatching; +using ::android::hardware::gnss::V1_0::IGnssBatchingCallback; +using ::android::hidl::base::V1_0::IBase; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class BatchingAPIClient; +struct GnssBatching : public IGnssBatching { + GnssBatching(); + ~GnssBatching(); + + // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. + Return init(const sp& callback) override; + Return getBatchSize() override; + Return start(const IGnssBatching::Options& options ) override; + Return flush() override; + Return stop() override; + Return cleanup() override; + + private: + struct GnssBatchingDeathRecipient : hidl_death_recipient { + GnssBatchingDeathRecipient(sp gnssBatching) : + mGnssBatching(gnssBatching) { + } + ~GnssBatchingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssBatching; + }; + + private: + sp mGnssBatchingDeathRecipient = nullptr; + sp mGnssBatchingCbIface = nullptr; + BatchingAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H diff --git a/gps/android/1.1/GnssConfiguration.cpp b/gps/android/1.1/GnssConfiguration.cpp new file mode 100644 index 0000000..ad255d1 --- /dev/null +++ b/gps/android/1.1/GnssConfiguration.cpp @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssConfigurationInterface" + +#include +#include "Gnss.h" +#include "GnssConfiguration.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::GnssConstellationType; + +GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) { +} + +// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow. +Return GnssConfiguration::setSuplEs(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + config.suplEmergencyServices = (enabled ? + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES : + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO); + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplVersion(uint32_t version) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; + case 0x00020002: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; + break; + case 0x00020000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0; + break; + case 0x00010000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0; + break; + default: + LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplMode(uint8_t mode) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + switch (mode) { + case 0: + config.suplModeMask = 0; // STANDALONE ONLY + break; + case 1: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT; + break; + case 2: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + case 3: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + default: + LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setLppProfile(uint8_t lppProfileMask) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default + + if (lppProfileMask & (1<<0)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT; + } + if (lppProfileMask & (1<<1)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT; + } + if (lppProfileMask & (1<<2)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT; + } + if (lppProfileMask & (1<<3)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + + config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + if (protocol & (1<<0)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT; + } + if (protocol & (1<<1)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT; + } + if (protocol & (1<<2)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT; + } + if (protocol & (1<<3)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGpsLock(uint8_t lock) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + switch (lock) { + case 0: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + break; + case 1: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO; + break; + case 2: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI; + break; + case 3: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; + break; + default: + LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setEmergencySuplPdn(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + config.emergencyPdnForEmergencySupl = (enabled ? + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES : + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO); + + return mGnss->updateConfiguration(config); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. +Return GnssConfiguration::setBlacklist( + const hidl_vec& blacklist) { + + ENTRY_LOG_CALLFLOW(); + if (nullptr == mGnss) { + LOC_LOGe("mGnss is null"); + return false; + } + + // blValid is true if blacklist is empty, i.e. clearing the BL; + // if blacklist is not empty, blValid is initialied to false, and later + // updated in the for loop to become true only if there is at least + // one {constellation, svid} in the list that is valid. + bool blValid = (0 == blacklist.size()); + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + config.blacklistedSvIds.clear(); + + GnssSvIdSource source = {}; + for (int idx = 0; idx < (int)blacklist.size(); idx++) { + // Set blValid true if any one source is valid + blValid = setBlacklistedSource(source, blacklist[idx]) || blValid; + config.blacklistedSvIds.push_back(source); + } + + // Update configuration only if blValid is true + // i.e. only if atleast one source is valid for blacklisting + return (blValid && mGnss->updateConfiguration(config)); +} + +bool GnssConfiguration::setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource) { + + bool retVal = true; + uint16_t svIdOffset = 0; + copyToSource.size = sizeof(GnssSvIdSource); + copyToSource.svId = copyFromSource.svid; + + switch(copyFromSource.constellation) { + case GnssConstellationType::GPS: + copyToSource.constellation = GNSS_SV_TYPE_GPS; + LOC_LOGe("GPS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::SBAS: + copyToSource.constellation = GNSS_SV_TYPE_SBAS; + LOC_LOGe("SBAS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::GLONASS: + copyToSource.constellation = GNSS_SV_TYPE_GLONASS; + svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::QZSS: + copyToSource.constellation = GNSS_SV_TYPE_QZSS; + svIdOffset = 0; + break; + case GnssConstellationType::BEIDOU: + copyToSource.constellation = GNSS_SV_TYPE_BEIDOU; + svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::GALILEO: + copyToSource.constellation = GNSS_SV_TYPE_GALILEO; + svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1; + break; + default: + copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; + LOC_LOGe("Invalid constellation %d", copyFromSource.constellation); + retVal = false; + break; + } + + if (copyToSource.svId > 0 && svIdOffset > 0) { + copyToSource.svId += svIdOffset; + } + + return retVal; +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/GnssConfiguration.h b/gps/android/1.1/GnssConfiguration.h new file mode 100644 index 0000000..daea159 --- /dev/null +++ b/gps/android/1.1/GnssConfiguration.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ + + /* Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_1::IGnssConfiguration; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* + * Interface for passing GNSS configuration info from platform to HAL. + */ +struct Gnss; +struct GnssConfiguration : public IGnssConfiguration { + GnssConfiguration(Gnss* gnss); + ~GnssConfiguration() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. + * These declarations were generated from IGnssConfiguration.hal. + */ + Return setSuplVersion(uint32_t version) override; + Return setSuplMode(uint8_t mode) override; + Return setSuplEs(bool enabled) override; + Return setLppProfile(uint8_t lppProfileMask) override; + Return setGlonassPositioningProtocol(uint8_t protocol) override; + Return setEmergencySuplPdn(bool enable) override; + Return setGpsLock(uint8_t lock) override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. + Return setBlacklist( + const hidl_vec& blacklist) override; + + private: + Gnss* mGnss = nullptr; + bool setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource); +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H diff --git a/gps/android/1.1/GnssDebug.cpp b/gps/android/1.1/GnssDebug.cpp new file mode 100644 index 0000000..f164c54 --- /dev/null +++ b/gps/android/1.1/GnssDebug.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssDebugInterface" + +#include +#include +#include "Gnss.h" +#include "GnssDebug.h" +#include "LocationUtil.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::hidl_vec; + +#define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000) +#define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000) +#define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500) +#define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) + +#define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm + +GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) +{ +} + +/* + * This methods requests position, time and satellite ephemeris debug information + * from the HAL. + * + * @return void +*/ +Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + SatelliteData s = { }; + std::vector s_array = { }; + + for (uint32_t i=0; i +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssDebug; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* Interface for GNSS Debug support. */ +struct Gnss; +struct GnssDebug : public IGnssDebug { + GnssDebug(Gnss* gnss); + ~GnssDebug() {}; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow. + * These declarations were generated from IGnssDebug.hal. + */ + Return getDebugData(getDebugData_cb _hidl_cb) override; + +private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSDEBUG_H diff --git a/gps/android/1.1/GnssGeofencing.cpp b/gps/android/1.1/GnssGeofencing.cpp new file mode 100644 index 0000000..a4aaf88 --- /dev/null +++ b/gps/android/1.1/GnssGeofencing.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GnssHal_GnssGeofencing" + +#include +#include +#include "GnssGeofencing.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssGeofencing != nullptr) { + mGnssGeofencing->removeAllGeofences(); + } +} + +GnssGeofencing::GnssGeofencing() : mApi(nullptr) { + mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this); +} + +GnssGeofencing::~GnssGeofencing() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. +Return GnssGeofencing::setCallback(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGd("mApi is NOT nullptr"); + return Void(); + } + + mApi = new GeofenceAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + } + + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient); + } + mGnssGeofencingCbIface = callback; + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssGeofencing::addGeofence( + int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceAdd( + geofenceId, + latitudeDegrees, + longitudeDegrees, + radiusMeters, + static_cast(lastTransition), + monitorTransitions, + notificationResponsivenessMs, + unknownTimerMs); + } + return Void(); +} + +Return GnssGeofencing::pauseGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofencePause(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceResume(geofenceId, monitorTransitions); + } + return Void(); +} + +Return GnssGeofencing::removeGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceRemove(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::removeAllGeofences() { + if (mApi == nullptr) { + LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__); + } else { + mApi->geofenceRemoveAll(); + } + return Void(); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/GnssGeofencing.h b/gps/android/1.1/GnssGeofencing.h new file mode 100644 index 0000000..94a73de --- /dev/null +++ b/gps/android/1.1/GnssGeofencing.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::IGnssGeofencing; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class GeofenceAPIClient; +struct GnssGeofencing : public IGnssGeofencing { + GnssGeofencing(); + ~GnssGeofencing(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. + * These declarations were generated from IGnssGeofencing.hal. + */ + Return setCallback(const sp& callback) override; + Return addGeofence(int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) override; + + Return pauseGeofence(int32_t geofenceId) override; + Return resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override; + Return removeGeofence(int32_t geofenceId) override; + + private: + // This method is not part of the IGnss base class. + // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far. + Return removeAllGeofences(); + + private: + struct GnssGeofencingDeathRecipient : hidl_death_recipient { + GnssGeofencingDeathRecipient(sp gnssGeofencing) : + mGnssGeofencing(gnssGeofencing) { + } + ~GnssGeofencingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssGeofencing; + }; + + private: + sp mGnssGeofencingDeathRecipient = nullptr; + sp mGnssGeofencingCbIface = nullptr; + GeofenceAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H diff --git a/gps/android/1.1/GnssMeasurement.cpp b/gps/android/1.1/GnssMeasurement.cpp new file mode 100644 index 0000000..6f8c14d --- /dev/null +++ b/gps/android/1.1/GnssMeasurement.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssMeasurementInterface" + +#include +#include +#include "GnssMeasurement.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssMeasurement != nullptr) { + mGnssMeasurement->close(); + } +} + +GnssMeasurement::GnssMeasurement() { + mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this); + mApi = new MeasurementAPIClient(); +} + +GnssMeasurement::~GnssMeasurement() { + if (mApi) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + +Return GnssMeasurement::setCallback( + const sp& callback) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + mGnssMeasurementCbIface = callback; + mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + return mApi->measurementSetCallback(callback); + +} + +Return GnssMeasurement::close() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return Void(); + } + + if (mGnssMeasurementCbIface != nullptr) { + mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface = nullptr; + } + if (mGnssMeasurementCbIface_1_1 != nullptr) { + mGnssMeasurementCbIface_1_1->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_1_1 = nullptr; + } + mApi->measurementClose(); + + return Void(); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_1_1( + const sp& callback, bool enableFullTracking) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_1_1 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + mGnssMeasurementCbIface_1_1 = callback; + mGnssMeasurementCbIface_1_1->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_1_1(callback, powerMode); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/GnssMeasurement.h b/gps/android/1.1/GnssMeasurement.h new file mode 100644 index 0000000..373f0d0 --- /dev/null +++ b/gps/android/1.1/GnssMeasurement.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_1::IGnssMeasurement; +using ::android::hardware::gnss::V1_1::IGnssMeasurementCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class MeasurementAPIClient; +struct GnssMeasurement : public IGnssMeasurement { + GnssMeasurement(); + ~GnssMeasurement(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + * These declarations were generated from IGnssMeasurement.hal. + */ + Return setCallback( + const sp& callback) override; + Return close() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. + Return setCallback_1_1( + const sp& callback, + bool enableFullTracking) override; + + private: + struct GnssMeasurementDeathRecipient : hidl_death_recipient { + GnssMeasurementDeathRecipient(sp gnssMeasurement) : + mGnssMeasurement(gnssMeasurement) { + } + ~GnssMeasurementDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssMeasurement; + }; + + private: + sp mGnssMeasurementDeathRecipient = nullptr; + sp mGnssMeasurementCbIface = nullptr; + sp mGnssMeasurementCbIface_1_1 = nullptr; + MeasurementAPIClient* mApi; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H diff --git a/gps/android/1.1/GnssNi.cpp b/gps/android/1.1/GnssNi.cpp new file mode 100644 index 0000000..5ce9569 --- /dev/null +++ b/gps/android/1.1/GnssNi.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssNiInterface" + +#include +#include "Gnss.h" +#include "GnssNi.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + // we do nothing here + // Gnss::GnssDeathRecipient will stop the session +} + +GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) { + mGnssNiDeathRecipient = new GnssNiDeathRecipient(this); +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. +Return GnssNi::setCallback(const sp& callback) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + mGnss->setGnssNiCb(callback); + + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient); + } + mGnssNiCbIface = callback; + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + GnssAPIClient* api = mGnss->getApi(); + if (api == nullptr) { + LOC_LOGE("%s]: api is nullptr", __FUNCTION__); + return Void(); + } + + api->gnssNiRespond(notifId, userResponse); + + return Void(); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/GnssNi.h b/gps/android/1.1/GnssNi.h new file mode 100644 index 0000000..6733e5b --- /dev/null +++ b/gps/android/1.1/GnssNi.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H +#define ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssNi; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct GnssNi : public IGnssNi { + GnssNi(Gnss* gnss); + ~GnssNi() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. + * These declarations were generated from IGnssNi.hal. + */ + Return setCallback(const sp& callback) override; + Return respond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) override; + + private: + struct GnssNiDeathRecipient : hidl_death_recipient { + GnssNiDeathRecipient(sp gnssNi) : mGnssNi(gnssNi) { + } + ~GnssNiDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssNi; + }; + + private: + sp mGnssNiDeathRecipient = nullptr; + sp mGnssNiCbIface = nullptr; + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H diff --git a/gps/android/1.1/android.hardware.gnss@1.1-service-qti.rc b/gps/android/1.1/android.hardware.gnss@1.1-service-qti.rc new file mode 100644 index 0000000..bd65584 --- /dev/null +++ b/gps/android/1.1/android.hardware.gnss@1.1-service-qti.rc @@ -0,0 +1,4 @@ +service gnss_service /vendor/bin/hw/android.hardware.gnss@1.1-service-qti + class hal + user gps + group system gps radio vendor_qti_diag diff --git a/gps/android/1.1/android.hardware.gnss@1.1-service-qti.xml b/gps/android/1.1/android.hardware.gnss@1.1-service-qti.xml new file mode 100644 index 0000000..c9c83fb --- /dev/null +++ b/gps/android/1.1/android.hardware.gnss@1.1-service-qti.xml @@ -0,0 +1,35 @@ + + + + android.hardware.gnss + hwbinder + @1.1::IGnss/default + + + diff --git a/gps/android/1.1/location_api/BatchingAPIClient.cpp b/gps/android/1.1/location_api/BatchingAPIClient.cpp new file mode 100644 index 0000000..6ec27a9 --- /dev/null +++ b/gps/android/1.1/location_api/BatchingAPIClient.cpp @@ -0,0 +1,197 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_BatchingAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "BatchingAPIClient.h" + +#include "limits.h" + + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssBatching; +using ::android::hardware::gnss::V1_0::IGnssBatchingCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask); + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(callback), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + if (mGnssBatchingCbIface != nullptr) { + locationCallbacks.batchingCb = [this](size_t count, Location* location, + BatchingOptions batchOptions) { + onBatchingCb(count, location, batchOptions); + }; + } + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +BatchingAPIClient::~BatchingAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +int BatchingAPIClient::getBatchSize() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + return locAPIGetBatchSize(); +} + +int BatchingAPIClient::startSession(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::updateSessionOptions(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::stopSession() +{ + LOC_LOGD("%s]: ", __FUNCTION__); + int retVal = -1; + if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +void BatchingAPIClient::getBatchedLocation(int last_n_locations) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations); + locAPIGetBatchedLocations(mDefaultId, last_n_locations); +} + +void BatchingAPIClient::flushBatchedLocations() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + locAPIGetBatchedLocations(mDefaultId, SIZE_MAX); +} + +void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; +} + +void BatchingAPIClient::onBatchingCb(size_t count, Location* location, + BatchingOptions /*batchOptions*/) +{ + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count); + if (mGnssBatchingCbIface != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = mGnssBatchingCbIface->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask) +{ + memset(&out, 0, sizeof(LocationOptions)); + out.size = sizeof(LocationOptions); + out.minInterval = (uint32_t)(in.periodNanos / 1000000L); + out.minDistance = 0; + out.mode = GNSS_SUPL_MODE_STANDALONE; + if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + out.mode = GNSS_SUPL_MODE_MSA; + if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + out.mode = GNSS_SUPL_MODE_MSB; +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/location_api/BatchingAPIClient.h b/gps/android/1.1/location_api/BatchingAPIClient.h new file mode 100644 index 0000000..4c90626 --- /dev/null +++ b/gps/android/1.1/location_api/BatchingAPIClient.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef BATCHING_API_CLINET_H +#define BATCHING_API_CLINET_H + +#include +#include +#include + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +class BatchingAPIClient : public LocationAPIClientBase +{ +public: + BatchingAPIClient(const sp& callback); + int getBatchSize(); + int startSession(const V1_0::IGnssBatching::Options& options); + int updateSessionOptions(const V1_0::IGnssBatching::Options& options); + int stopSession(); + void getBatchedLocation(int last_n_locations); + void flushBatchedLocations(); + + inline LocationCapabilitiesMask getCapabilities() { return mLocationCapabilitiesMask; } + + // callbacks + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions) final; + +private: + ~BatchingAPIClient(); + + sp mGnssBatchingCbIface; + uint32_t mDefaultId; + LocationCapabilitiesMask mLocationCapabilitiesMask; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // BATCHING_API_CLINET_H diff --git a/gps/android/1.1/location_api/GeofenceAPIClient.cpp b/gps/android/1.1/location_api/GeofenceAPIClient.cpp new file mode 100644 index 0000000..93d175e --- /dev/null +++ b/gps/android/1.1/location_api/GeofenceAPIClient.cpp @@ -0,0 +1,275 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GeofenceApiClient" + +#include +#include + +#include "LocationUtil.h" +#include "GeofenceAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +GeofenceAPIClient::GeofenceAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssGeofencingCbIface(callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + + locationCallbacks.geofenceBreachCb = nullptr; + if (mGnssGeofencingCbIface != nullptr) { + locationCallbacks.geofenceBreachCb = + [this](GeofenceBreachNotification geofenceBreachNotification) { + onGeofenceBreachCb(geofenceBreachNotification); + }; + + locationCallbacks.geofenceStatusCb = + [this](GeofenceStatusNotification geofenceStatusNotification) { + onGeofenceStatusCb(geofenceStatusNotification); + }; + } + + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms) +{ + LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__, + geofence_id, latitude, longitude, radius_meters, + last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms); + + GeofenceOption options; + memset(&options, 0, sizeof(GeofenceOption)); + options.size = sizeof(GeofenceOption); + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + options.breachTypeMask |= GEOFENCE_BREACH_EXIT_BIT; + options.responsiveness = notification_responsiveness_ms; + + GeofenceInfo data; + data.size = sizeof(GeofenceInfo); + data.latitude = latitude; + data.longitude = longitude; + data.radius = radius_meters; + + LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data); + if (LOCATION_ERROR_SUCCESS != err) { + onAddGeofencesCb(1, &err, &geofence_id); + } +} + +void GeofenceAPIClient::geofencePause(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIPauseGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions); + GeofenceBreachTypeMask mask = 0; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + mask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + mask |= GEOFENCE_BREACH_EXIT_BIT; + locAPIResumeGeofences(1, &geofence_id, &mask); +} + +void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIRemoveGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceRemoveAll() +{ + LOC_LOGD("%s]", __FUNCTION__); + // TODO locAPIRemoveAllGeofences(); +} + +// callbacks +void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, geofenceBreachNotification.count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < geofenceBreachNotification.count; i++) { + GnssLocation gnssLocation; + convertGnssLocation(geofenceBreachNotification.location, gnssLocation); + + IGnssGeofenceCallback::GeofenceTransition transition; + if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER) + transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED; + else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT) + transition = IGnssGeofenceCallback::GeofenceTransition::EXITED; + else { + // continue with other breach if transition is + // nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED + continue; + } + + auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb( + geofenceBreachNotification.ids[i], gnssLocation, transition, + static_cast(geofenceBreachNotification.timestamp)); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available); + if (mGnssGeofencingCbIface != nullptr) { + IGnssGeofenceCallback::GeofenceAvailability status = + IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE; + if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) { + status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE; + } + GnssLocation gnssLocation; + memset(&gnssLocation, 0, sizeof(GnssLocation)); + auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_EXISTS) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS; + auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/location_api/GeofenceAPIClient.h b/gps/android/1.1/location_api/GeofenceAPIClient.h new file mode 100644 index 0000000..0ffff91 --- /dev/null +++ b/gps/android/1.1/location_api/GeofenceAPIClient.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GEOFENCE_API_CLINET_H +#define GEOFENCE_API_CLINET_H + + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::sp; + +class GeofenceAPIClient : public LocationAPIClientBase +{ +public: + GeofenceAPIClient(const sp& callback); + + void geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms); + void geofencePause(uint32_t geofence_id); + void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions); + void geofenceRemove(uint32_t geofence_id); + void geofenceRemoveAll(); + + // callbacks + void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final; + void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final; + void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + +private: + virtual ~GeofenceAPIClient() = default; + + sp mGnssGeofencingCbIface; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GEOFENCE_API_CLINET_H diff --git a/gps/android/1.1/location_api/GnssAPIClient.cpp b/gps/android/1.1/location_api/GnssAPIClient.cpp new file mode 100644 index 0000000..a2c4eec --- /dev/null +++ b/gps/android/1.1/location_api/GnssAPIClient.cpp @@ -0,0 +1,565 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GnssAPIClient" +#define SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC (590 * 60 * 60 * 1000) // 590 hours + +#include +#include +#include + +#include "LocationUtil.h" +#include "GnssAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnss; +using ::android::hardware::gnss::V1_0::IGnssCallback; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out); + +GnssAPIClient::GnssAPIClient(const sp& gpsCb, + const sp& niCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + // set default LocationOptions. + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = 1000; + mTrackingOptions.minDistance = 0; + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + + gnssUpdateCallbacks(gpsCb, niCb); +} + +GnssAPIClient::~GnssAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient) { + delete mControlClient; + mControlClient = nullptr; + } +} + +// for GpsInterface +void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + mMutex.lock(); + mGnssCbIface = gpsCb; + mGnssNiCbIface = niCb; + mMutex.unlock(); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.trackingCb = [this](Location location) { + onTrackingCb(location); + }; + } + + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + + locationCallbacks.gnssNiCb = nullptr; + loc_core::ContextBase* context = + loc_core::LocContext::getLocContext(loc_core::LocContext::mLocationHalName); + if (mGnssNiCbIface != nullptr && !context->hasAgpsExtendedCapabilities()) { + LOC_LOGD("Registering NI CB"); + locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotification) { + onGnssNiCb(id, gnssNiNotification); + }; + } + + locationCallbacks.gnssSvCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) { + onGnssSvCb(gnssSvNotification); + }; + } + + locationCallbacks.gnssNmeaCb = nullptr; + if (mGnssCbIface != nullptr) { + locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) { + onGnssNmeaCb(gnssNmeaNotification); + }; + } + + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +bool GnssAPIClient::gnssStart() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + bool retVal = true; + locAPIStartTracking(mTrackingOptions); + return retVal; +} + +bool GnssAPIClient::gnssStop() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + bool retVal = true; + locAPIStopTracking(); + return retVal; +} + +bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode, + IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%d %d %d %d %d %d %d)", __FUNCTION__, + (int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, + preferredTimeMs, (int)powerMode, timeBetweenMeasurement); + bool retVal = true; + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = minIntervalMs; + if (IGnss::GnssPositionMode::MS_ASSISTED == mode || + IGnss::GnssPositionRecurrence::RECURRENCE_SINGLE == recurrence) { + // We set a very large interval to simulate SINGLE mode. Once we report a fix, + // the caller should take the responsibility to stop the session. + // For MSA, we always treat it as SINGLE mode. + mTrackingOptions.minInterval = SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC; + } + if (mode == IGnss::GnssPositionMode::STANDALONE) + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + else if (mode == IGnss::GnssPositionMode::MS_BASED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSB; + else if (mode == IGnss::GnssPositionMode::MS_ASSISTED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSA; + else { + LOC_LOGD("%s]: invalid GnssPositionMode: %d", __FUNCTION__, (int)mode); + retVal = false; + } + if (GNSS_POWER_MODE_INVALID != powerMode) { + mTrackingOptions.powerMode = powerMode; + mTrackingOptions.tbm = timeBetweenMeasurement; + } + locAPIUpdateTrackingOptions(mTrackingOptions); + return retVal; +} + +// for GpsNiInterface +void GnssAPIClient::gnssNiRespond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast(userResponse)); + GnssNiResponse data; + switch (userResponse) { + case IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT: + data = GNSS_NI_RESPONSE_ACCEPT; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY: + data = GNSS_NI_RESPONSE_DENY; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP: + data = GNSS_NI_RESPONSE_NO_RESPONSE; + break; + default: + data = GNSS_NI_RESPONSE_IGNORE; + break; + } + + locAPIGnssNiResponse(notifId, data); +} + +// these apis using LocationAPIControlClient +void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags) +{ + LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags); + if (mControlClient == nullptr) { + return; + } + GnssAidingData data; + memset(&data, 0, sizeof (GnssAidingData)); + data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS_BIT | + GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT | + GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT | + GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT | + GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT; + data.posEngineMask = STANDARD_POSITIONING_ENGINE; + + if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL) + data.deleteAll = true; + else { + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS) + data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC) + data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION) + data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME) + data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO) + data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC) + data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH) + data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR) + data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER) + data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA) + data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI) + data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO) + data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB_BIT; + } + mControlClient->locAPIGnssDeleteAidingData(data); +} + +void GnssAPIClient::gnssEnable(LocationTechnologyType techType) +{ + LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIEnable(techType); +} + +void GnssAPIClient::gnssDisable() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIDisable(); +} + +void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig) +{ + LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIGnssUpdateConfig(gnssConfig); +} + +void GnssAPIClient::requestCapabilities() { + // only send capablities if it's already cached, otherwise the first time LocationAPI + // is initialized, capabilities will be sent by LocationAPI + if (mLocationCapabilitiesCached) { + onCapabilitiesCb(mLocationCapabilitiesMask); + } +} + +// callbacks +void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; + mLocationCapabilitiesCached = true; + + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + uint32_t data = 0; + if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT)) + data |= IGnssCallback::Capabilities::SCHEDULING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT) + data |= IGnssCallback::Capabilities::GEOFENCING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) + data |= IGnssCallback::Capabilities::MEASUREMENTS; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + data |= IGnssCallback::Capabilities::MSB; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + data |= IGnssCallback::Capabilities::MSA; + auto r = gnssCbIface->gnssSetCapabilitesCb(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s", + __func__, r.description().c_str()); + } + } + if (gnssCbIface != nullptr) { + IGnssCallback::GnssSystemInfo gnssInfo = { .yearOfHw = 2015 }; + + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) { + gnssInfo.yearOfHw++; // 2016 + if (capabilitiesMask & LOCATION_CAPABILITIES_DEBUG_NMEA_BIT) { + gnssInfo.yearOfHw++; // 2017 + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT || + capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) { + gnssInfo.yearOfHw++; // 2018 + } + } + } + LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw); + auto r = gnssCbIface->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onTrackingCb(Location location) +{ + LOC_LOGD("%s]: (flags: %02x)", __FUNCTION__, location.flags); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface->gnssLocationCb(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) +{ + LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id); + mMutex.lock(); + auto gnssNiCbIface(mGnssNiCbIface); + mMutex.unlock(); + + if (gnssNiCbIface == nullptr) { + LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__); + return; + } + + IGnssNiCallback::GnssNiNotification notificationGnss = {}; + + notificationGnss.notificationId = id; + + if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL; + else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_EMERGENCY_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::EMERGENCY_SUPL; + + if (gnssNiNotification.options & GNSS_NI_OPTIONS_NOTIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_VERIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE; + + notificationGnss.timeoutSec = gnssNiNotification.timeout; + + if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE || + gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP; + + notificationGnss.requestorId = gnssNiNotification.requestor; + + notificationGnss.notificationMessage = gnssNiNotification.message; + + if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + gnssNiCbIface->niNotifyCb(notificationGnss); +} + +void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification) +{ + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, gnssSvNotification.count); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + IGnssCallback::GnssSvStatus svStatus; + convertGnssSvStatus(gnssSvNotification, svStatus); + auto r = gnssCbIface->gnssSvStatusCb(svStatus); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (gnssCbIface != nullptr) { + const std::string s(gnssNmeaNotification.nmea); + std::stringstream ss(s); + std::string each; + while(std::getline(ss, each, '\n')) { + each += '\n'; + android::hardware::hidl_string nmeaString; + nmeaString.setToExternal(each.c_str(), each.length()); + auto r = gnssCbIface->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%zu description=%s", __func__, + gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } + } +} + +void GnssAPIClient::onStartTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS && gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onStopTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS && gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out) +{ + memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus)); + out.numSvs = in.count; + if (out.numSvs > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many satellites %u. Clamps to %d.", + __FUNCTION__, out.numSvs, V1_0::GnssMax::SVS_COUNT); + out.numSvs = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.numSvs; i++) { + IGnssCallback::GnssSvInfo& info = out.gnssSvList[i]; + convertGnssSvid(in.gnssSvs[i], info.svid); + convertGnssConstellationType(in.gnssSvs[i].type, info.constellation); + info.cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + info.elevationDegrees = in.gnssSvs[i].elevation; + info.azimuthDegrees = in.gnssSvs[i].azimuth; + info.carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + info.svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + info.svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + } +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/location_api/GnssAPIClient.h b/gps/android/1.1/location_api/GnssAPIClient.h new file mode 100644 index 0000000..3829265 --- /dev/null +++ b/gps/android/1.1/location_api/GnssAPIClient.h @@ -0,0 +1,110 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GNSS_API_CLINET_H +#define GNSS_API_CLINET_H + + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::sp; + +class GnssAPIClient : public LocationAPIClientBase +{ +public: + GnssAPIClient(const sp& gpsCb, + const sp& niCb); + GnssAPIClient(const GnssAPIClient&) = delete; + GnssAPIClient& operator=(const GnssAPIClient&) = delete; + + // for GpsInterface + void gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb); + bool gnssStart(); + bool gnssStop(); + bool gnssSetPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = 0); + + // for GpsNiInterface + void gnssNiRespond(int32_t notifId, V1_0::IGnssNiCallback::GnssUserResponseType userResponse); + + // these apis using LocationAPIControlClient + void gnssDeleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags); + void gnssEnable(LocationTechnologyType techType); + void gnssDisable(); + void gnssConfigurationUpdate(const GnssConfig& gnssConfig); + + inline LocationCapabilitiesMask gnssGetCapabilities() const { + return mLocationCapabilitiesMask; + } + void requestCapabilities(); + + // callbacks we are interested in + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onTrackingCb(Location location) final; + void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final; + void onGnssSvCb(GnssSvNotification gnssSvNotification) final; + void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final; + + void onStartTrackingCb(LocationError error) final; + void onStopTrackingCb(LocationError error) final; + +private: + virtual ~GnssAPIClient(); + + sp mGnssCbIface; + sp mGnssNiCbIface; + std::mutex mMutex; + LocationAPIControlClient* mControlClient; + LocationCapabilitiesMask mLocationCapabilitiesMask; + bool mLocationCapabilitiesCached; + TrackingOptions mTrackingOptions; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GNSS_API_CLINET_H diff --git a/gps/android/1.1/location_api/LocationUtil.cpp b/gps/android/1.1/location_api/LocationUtil.cpp new file mode 100644 index 0000000..26fd920 --- /dev/null +++ b/gps/android/1.1/location_api/LocationUtil.cpp @@ -0,0 +1,274 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::V1_0::GnssConstellationType; +using ::android::hardware::gnss::V1_0::GnssLocationFlags; + +void convertGnssLocation(Location& in, GnssLocation& out) +{ + memset(&out, 0, sizeof(GnssLocation)); + if (in.flags & LOCATION_HAS_LAT_LONG_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG; + out.latitudeDegrees = in.latitude; + out.longitudeDegrees = in.longitude; + } + if (in.flags & LOCATION_HAS_ALTITUDE_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE; + out.altitudeMeters = in.altitude; + } + if (in.flags & LOCATION_HAS_SPEED_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED; + out.speedMetersPerSec = in.speed; + } + if (in.flags & LOCATION_HAS_BEARING_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING; + out.bearingDegrees = in.bearing; + } + if (in.flags & LOCATION_HAS_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY; + out.horizontalAccuracyMeters = in.accuracy; + } + if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY; + out.verticalAccuracyMeters = in.verticalAccuracy; + } + if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY; + out.speedAccuracyMetersPerSecond = in.speedAccuracy; + } + if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY; + out.bearingAccuracyDegrees = in.bearingAccuracy; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(const GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) { + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + out.latitude = in.latitudeDegrees; + out.longitude = in.longitudeDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) { + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + out.altitude = in.altitudeMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) { + out.flags |= LOCATION_HAS_SPEED_BIT; + out.speed = in.speedMetersPerSec; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { + out.flags |= LOCATION_HAS_BEARING_BIT; + out.bearing = in.bearingDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) { + out.flags |= LOCATION_HAS_ACCURACY_BIT; + out.accuracy = in.horizontalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + out.verticalAccuracy = in.verticalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) { + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + out.speedAccuracy = in.speedAccuracyMetersPerSecond; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) { + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.bearingAccuracy = in.bearingAccuracyDegrees; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssSvid(GnssSv& in, int16_t& out) +{ + switch(in.type){ + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { //OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out) +{ + switch (in.svType) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out) +{ + switch(in) { + case GNSS_EPH_TYPE_EPHEMERIS: + out = GnssDebug::SatelliteEphemerisType::EPHEMERIS; + break; + case GNSS_EPH_TYPE_ALMANAC: + out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY; + break; + case GNSS_EPH_TYPE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE; + break; + } +} + +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out) +{ + switch(in) { + case GNSS_EPH_SOURCE_DEMODULATED: + out = GnssDebug::SatelliteEphemerisSource::DEMODULATED; + break; + case GNSS_EPH_SOURCE_SUPL_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED; + break; + case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED; + break; + case GNSS_EPH_SOURCE_LOCAL: + case GNSS_EPH_SOURCE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisSource::OTHER; + break; + } +} + +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out) +{ + switch(in) { + case GNSS_EPH_HEALTH_GOOD: + out = GnssDebug::SatelliteEphemerisHealth::GOOD; + break; + case GNSS_EPH_HEALTH_BAD: + out = GnssDebug::SatelliteEphemerisHealth::BAD; + break; + case GNSS_EPH_HEALTH_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN; + break; + } +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/location_api/LocationUtil.h b/gps/android/1.1/location_api/LocationUtil.h new file mode 100644 index 0000000..af3c93f --- /dev/null +++ b/gps/android/1.1/location_api/LocationUtil.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOCATION_UTIL_H +#define LOCATION_UTIL_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out); +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out); +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out); +void convertGnssSvid(GnssSv& in, int16_t& out); +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out); +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out); +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out); +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out); + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // LOCATION_UTIL_H diff --git a/gps/android/1.1/location_api/MeasurementAPIClient.cpp b/gps/android/1.1/location_api/MeasurementAPIClient.cpp new file mode 100644 index 0000000..a87ae6d --- /dev/null +++ b/gps/android/1.1/location_api/MeasurementAPIClient.cpp @@ -0,0 +1,332 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_MeasurementAPIClient" + +#include +#include + +#include "LocationUtil.h" +#include "MeasurementAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssMeasurement; +using ::android::hardware::gnss::V1_1::IGnssMeasurementCallback; + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + IGnssMeasurementCallback::GnssData& out); +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out); +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out); + +MeasurementAPIClient::MeasurementAPIClient() : + mGnssMeasurementCbIface(nullptr), + mGnssMeasurementCbIface_1_1(nullptr), + mTracking(false) +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +MeasurementAPIClient::~MeasurementAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +// for GpsInterface +Return +MeasurementAPIClient::measurementSetCallback(const sp& callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + mMutex.lock(); + mGnssMeasurementCbIface = callback; + mMutex.unlock(); + + return startTracking(); +} + +Return +MeasurementAPIClient::measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + mGnssMeasurementCbIface_1_1 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} + +Return +MeasurementAPIClient::startTracking( + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + + locationCallbacks.gnssMeasurementsCb = nullptr; + if (mGnssMeasurementCbIface_1_1 != nullptr || mGnssMeasurementCbIface != nullptr) { + locationCallbacks.gnssMeasurementsCb = + [this](GnssMeasurementsNotification gnssMeasurementsNotification) { + onGnssMeasurementsCb(gnssMeasurementsNotification); + }; + } + + locAPISetCallbacks(locationCallbacks); + + TrackingOptions options = {}; + memset(&options, 0, sizeof(TrackingOptions)); + options.size = sizeof(TrackingOptions); + options.minInterval = 1000; + options.mode = GNSS_SUPL_MODE_STANDALONE; + if (GNSS_POWER_MODE_INVALID != powerMode) { + options.powerMode = powerMode; + options.tbm = timeBetweenMeasurement; + } + + mTracking = true; + LOC_LOGD("%s]: start tracking session", __FUNCTION__); + locAPIStartTracking(options); + return IGnssMeasurement::GnssMeasurementStatus::SUCCESS; +} + +// for GpsMeasurementInterface +void MeasurementAPIClient::measurementClose() { + LOC_LOGD("%s]: ()", __FUNCTION__); + mTracking = false; + locAPIStopTracking(); +} + +// callbacks +void MeasurementAPIClient::onGnssMeasurementsCb( + GnssMeasurementsNotification gnssMeasurementsNotification) +{ + LOC_LOGD("%s]: (count: %zu active: %d)", + __FUNCTION__, gnssMeasurementsNotification.count, mTracking); + if (mTracking) { + mMutex.lock(); + sp gnssMeasurementCbIface = nullptr; + sp gnssMeasurementCbIface_1_1 = nullptr; + if (mGnssMeasurementCbIface_1_1 != nullptr) { + gnssMeasurementCbIface_1_1 = mGnssMeasurementCbIface_1_1; + } else if (mGnssMeasurementCbIface != nullptr) { + gnssMeasurementCbIface = mGnssMeasurementCbIface; + } + mMutex.unlock(); + + if (gnssMeasurementCbIface_1_1 != nullptr) { + IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_1_1(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_1_1->gnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface != nullptr) { + V1_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from GnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out) +{ + memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssMeasurement)); + if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL; + convertGnssSvid(in, out.svid); + convertGnssConstellationType(in.svType, out.constellation); + out.timeOffsetNs = in.timeOffsetNs; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + out.receivedSvTimeInNs = in.receivedSvTimeNs; + out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs; + out.cN0DbHz = in.carrierToNoiseDbHz; + out.pseudorangeRateMps = in.pseudorangeRateMps; + out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + out.accumulatedDeltaRangeM = in.adrMeters; + out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters; + out.carrierFrequencyHz = in.carrierFrequencyHz; + out.carrierCycles = in.carrierCycles; + out.carrierPhase = in.carrierPhase; + out.carrierPhaseUncertainty = in.carrierPhaseUncertainty; + uint8_t indicator = + static_cast(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN); + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT; + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT; + out.multipathIndicator = + static_cast(indicator); + out.snrDb = in.signalToNoiseRatioDb; + out.agcLevelDb = in.agcLevelDb; +} + +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out) +{ + memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssClock)); + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY; + out.leapSecond = in.leapSecond; + out.timeNs = in.timeNs; + out.timeUncertaintyNs = in.timeUncertaintyNs; + out.fullBiasNs = in.fullBiasNs; + out.biasNs = in.biasNs; + out.biasUncertaintyNs = in.biasUncertaintyNs; + out.driftNsps = in.driftNsps; + out.driftUncertaintyNsps = in.driftUncertaintyNsps; + out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount; +} + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out) +{ + out.measurementCount = in.count; + if (out.measurementCount > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.", + __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT); + out.measurementCount = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.measurementCount; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i]); + } + convertGnssClock(in.clock, out.clock); +} + +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + IGnssMeasurementCallback::GnssData& out) +{ + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_0); + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED; + } + convertGnssClock(in.clock, out.clock); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/1.1/location_api/MeasurementAPIClient.h b/gps/android/1.1/location_api/MeasurementAPIClient.h new file mode 100644 index 0000000..5fb307c --- /dev/null +++ b/gps/android/1.1/location_api/MeasurementAPIClient.h @@ -0,0 +1,85 @@ +/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef MEASUREMENT_API_CLINET_H +#define MEASUREMENT_API_CLINET_H + +#include +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V1_1 { +namespace implementation { + +using ::android::sp; + +class MeasurementAPIClient : public LocationAPIClientBase +{ +public: + MeasurementAPIClient(); + MeasurementAPIClient(const MeasurementAPIClient&) = delete; + MeasurementAPIClient& operator=(const MeasurementAPIClient&) = delete; + + // for GpsMeasurementInterface + Return measurementSetCallback( + const sp& callback); + Return measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + void measurementClose(); + Return startTracking( + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + + // callbacks we are interested in + void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final; + +private: + virtual ~MeasurementAPIClient(); + + std::mutex mMutex; + sp mGnssMeasurementCbIface; + sp mGnssMeasurementCbIface_1_1; + + bool mTracking; +}; + +} // namespace implementation +} // namespace V1_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // MEASUREMENT_API_CLINET_H diff --git a/gps/android/1.1/service.cpp b/gps/android/1.1/service.cpp new file mode 100644 index 0000000..0cb91f7 --- /dev/null +++ b/gps/android/1.1/service.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.gnss@1.1-service-qti" + +#include +#include +#include "loc_cfg.h" +#include "loc_misc_utils.h" + +extern "C" { +#include "vndfwk-detect.h" +} + +#ifdef ARCH_ARM_32 +#define DEFAULT_HW_BINDER_MEM_SIZE 65536 +#endif + +using android::hardware::gnss::V1_1::IGnss; + +using android::hardware::configureRpcThreadpool; +using android::hardware::registerPassthroughServiceImplementation; +using android::hardware::joinRpcThreadpool; + +using android::status_t; +using android::OK; + +typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []); + +int main() { + + ALOGI("%s", __FUNCTION__); + + int vendorInfo = getVendorEnhancedInfo(); + bool vendorEnhanced = ( 1 == vendorInfo || 3 == vendorInfo ); + setVendorEnhanced(vendorEnhanced); + +#ifdef ARCH_ARM_32 + android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE)); +#endif + configureRpcThreadpool(1, true); + status_t status; + + status = registerPassthroughServiceImplementation(); + if (status == OK) { + if (vendorEnhanced) { + #ifdef LOC_HIDL_VERSION + #define VENDOR_ENHANCED_LIB "vendor.qti.gnss@" LOC_HIDL_VERSION "-service.so" + + void* libHandle = NULL; + vendorEnhancedServiceMain* vendorEnhancedMainMethod = (vendorEnhancedServiceMain*) + dlGetSymFromLib(libHandle, VENDOR_ENHANCED_LIB, "main"); + if (NULL != vendorEnhancedMainMethod) { + (*vendorEnhancedMainMethod)(0, NULL); + } + #else + ALOGE("LOC_HIDL_VERSION not defined."); + #endif + } + + joinRpcThreadpool(); + + } else { + ALOGE("Error while registering IGnss 1.1 service: %d", status); + } + + return 0; +} diff --git a/gps/android/2.0/AGnss.cpp b/gps/android/2.0/AGnss.cpp new file mode 100644 index 0000000..a48f1a0 --- /dev/null +++ b/gps/android/2.0/AGnss.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_AGnssInterface" + +#include +#include "Gnss.h" +#include "AGnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +static AGnss* spAGnss = nullptr; + +AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { + spAGnss = this; +} + +AGnss::~AGnss() { + spAGnss = nullptr; +} + +void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status) { + if (nullptr != spAGnss) { + spAGnss->statusCb(status.type, status.status); + } +} + +void AGnss::statusCb(AGpsExtType type, LocAGpsStatusValue status) { + + V2_0::IAGnssCallback::AGnssType aType; + IAGnssCallback::AGnssStatusValue aStatus; + + switch (type) { + case LOC_AGPS_TYPE_SUPL: + aType = IAGnssCallback::AGnssType::SUPL; + break; + case LOC_AGPS_TYPE_SUPL_ES: + aType = IAGnssCallback::AGnssType::SUPL_EIMS; + break; + default: + LOC_LOGE("invalid type: %d", type); + return; + } + + switch (status) { + case LOC_GPS_REQUEST_AGPS_DATA_CONN: + aStatus = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN; + break; + case LOC_GPS_RELEASE_AGPS_DATA_CONN: + aStatus = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN; + break; + case LOC_GPS_AGPS_DATA_CONNECTED: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED; + break; + case LOC_GPS_AGPS_DATA_CONN_DONE: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE; + break; + case LOC_GPS_AGPS_DATA_CONN_FAILED: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED; + break; + default: + LOC_LOGE("invalid status: %d", status); + return; + } + + if (mAGnssCbIface != nullptr) { + auto r = mAGnssCbIface->agnssStatusCb(aType, aStatus); + if (!r.isOk()) { + LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str()); + } + } + else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +Return AGnss::setCallback(const sp& callback) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return Void(); + } + + // Save the interface + mAGnssCbIface = callback; + + AgpsCbInfo cbInfo = {}; + cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES; + + mGnss->getGnssInterface()->agpsInit(cbInfo); + return Void(); +} + +Return AGnss::dataConnClosed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnFailed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnOpen(uint64_t /*networkHandle*/, const hidl_string& apn, + V2_0::IAGnss::ApnIpType apnIpType) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + /* Validate */ + if(apn.empty()){ + LOC_LOGE("Invalid APN"); + return false; + } + + LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str()); + + AGpsBearerType bearerType; + switch (apnIpType) { + case IAGnss::ApnIpType::IPV4: + bearerType = AGPS_APN_BEARER_IPV4; + break; + case IAGnss::ApnIpType::IPV6: + bearerType = AGPS_APN_BEARER_IPV6; + break; + case IAGnss::ApnIpType::IPV4V6: + bearerType = AGPS_APN_BEARER_IPV4V6; + break; + default: + bearerType = AGPS_APN_BEARER_IPV4; + break; + } + + mGnss->getGnssInterface()->agpsDataConnOpen( + LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType); + return true; +} + +Return AGnss::setServer(V2_0::IAGnssCallback::AGnssType type, + const hidl_string& hostname, + int32_t port) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + if (type == IAGnssCallback::AGnssType::SUPL) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL; + } else if (type == IAGnssCallback::AGnssType::C2K) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K; + } else if (type == IAGnssCallback::AGnssType::SUPL_EIMS) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_EIMS; + } else if (type == IAGnssCallback::AGnssType::SUPL_IMS) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_IMS; + } else { + LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast(type)); + return false; + } + config.assistanceServer.hostName = strdup(hostname.c_str()); + config.assistanceServer.port = port; + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/AGnss.h b/gps/android/2.0/AGnss.h new file mode 100644 index 0000000..c442327 --- /dev/null +++ b/gps/android/2.0/AGnss.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H +#define ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct AGnss : public V2_0::IAGnss { + + AGnss(Gnss* gnss); + ~AGnss(); + /* + * Methods from ::android::hardware::gnss::V2_0::IAGnss interface follow. + * These declarations were generated from IAGnss.hal. + */ + Return setCallback(const sp& callback) override; + + Return dataConnClosed() override; + + Return dataConnFailed() override; + + Return dataConnOpen(uint64_t networkHandle, const hidl_string& apn, + V2_0::IAGnss::ApnIpType apnIpType) override; + + Return setServer(V2_0::IAGnssCallback::AGnssType type, + const hidl_string& hostname, int32_t port) override; + + void statusCb(AGpsExtType type, LocAGpsStatusValue status); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); + + private: + Gnss* mGnss = nullptr; + sp mAGnssCbIface = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H diff --git a/gps/android/2.0/AGnssRil.cpp b/gps/android/2.0/AGnssRil.cpp new file mode 100644 index 0000000..d8005e4 --- /dev/null +++ b/gps/android/2.0/AGnssRil.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc__AGnssRilInterface" + +#include +#include +#include +#include +#include +#include +#include +#include "Gnss.h" +#include "AGnssRil.h" +#include + +typedef void* (getLocationInterface)(); + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + + +AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) { + ENTRY_LOG_CALLFLOW(); +} + +AGnssRil::~AGnssRil() { + ENTRY_LOG_CALLFLOW(); +} + +Return AGnssRil::updateNetworkState(bool connected, NetworkType type, bool /*roaming*/) { + ENTRY_LOG_CALLFLOW(); + // Extra NetworkTypes not available in IAgnssRil enums + const int NetworkType_BLUETOOTH = 7; + const int NetworkType_ETHERNET = 9; + const int NetworkType_PROXY = 16; + std::string apn(""); + + // for XTRA + if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) { + int8_t typeout = loc_core::TYPE_UNKNOWN; + switch(type) + { + case IAGnssRil::NetworkType::MOBILE: + typeout = loc_core::TYPE_MOBILE; + break; + case IAGnssRil::NetworkType::WIFI: + typeout = loc_core::TYPE_WIFI; + break; + case IAGnssRil::NetworkType::MMS: + typeout = loc_core::TYPE_MMS; + break; + case IAGnssRil::NetworkType::SUPL: + typeout = loc_core::TYPE_SUPL; + break; + case IAGnssRil::NetworkType::DUN: + typeout = loc_core::TYPE_DUN; + break; + case IAGnssRil::NetworkType::HIPRI: + typeout = loc_core::TYPE_HIPRI; + break; + case IAGnssRil::NetworkType::WIMAX: + typeout = loc_core::TYPE_WIMAX; + break; + default: + { + int networkType = (int) type; + // Handling network types not available in IAgnssRil + switch(networkType) + { + case NetworkType_BLUETOOTH: + typeout = loc_core::TYPE_BLUETOOTH; + break; + case NetworkType_ETHERNET: + typeout = loc_core::TYPE_ETHERNET; + break; + case NetworkType_PROXY: + typeout = loc_core::TYPE_PROXY; + break; + default: + typeout = loc_core::TYPE_UNKNOWN; + } + } + break; + } + mGnss->getGnssInterface()->updateConnectionStatus(connected, typeout, false, 0, apn); + } + return true; +} +Return AGnssRil::updateNetworkState_2_0(const V2_0::IAGnssRil::NetworkAttributes& attributes) { + ENTRY_LOG_CALLFLOW(); + std::string apn = attributes.apn; + if (nullptr != mGnss && (nullptr != mGnss->getGnssInterface())) { + int8_t typeout = loc_core::TYPE_UNKNOWN; + bool roaming = false; + if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_METERED) { + typeout = loc_core::TYPE_WIFI; + } else { + typeout = loc_core::TYPE_MOBILE; + } + if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_ROAMING) { + roaming = false; + } + LOC_LOGd("apn string received is: %s", apn.c_str()); + mGnss->getGnssInterface()->updateConnectionStatus(attributes.isConnected, + typeout, roaming, (NetworkHandle) attributes.networkHandle, apn); + } + return true; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/AGnssRil.h b/gps/android/2.0/AGnssRil.h new file mode 100644 index 0000000..a04d8aa --- /dev/null +++ b/gps/android/2.0/AGnssRil.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ +#define ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +/* + * Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface + * allows the GNSS chipset to request radio interface layer information from Android platform. + * Examples of such information are reference location, unique subscriber ID, phone number string + * and network availability changes. Also contains wrapper methods to allow methods from + * IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL. + */ +struct AGnssRil : public V2_0::IAGnssRil { + AGnssRil(Gnss* gnss); + ~AGnssRil(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow. + * These declarations were generated from IAGnssRil.hal. + */ + Return setCallback(const sp& /*callback*/) override { + return Void(); + } + Return setRefLocation(const V1_0::IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override { + return Void(); + } + Return setSetId(V1_0::IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override { + return false; + } + Return updateNetworkAvailability(bool /*available*/, + const hidl_string& /*apn*/) override { + return false; + } + Return updateNetworkState(bool connected, V1_0::IAGnssRil::NetworkType type, bool roaming) override; + + // Methods from ::android::hardware::gnss::V2_0::IAGnssRil follow + Return updateNetworkState_2_0(const V2_0::IAGnssRil::NetworkAttributes& attributes) override; + + private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ diff --git a/gps/android/2.0/Android.mk b/gps/android/2.0/Android.mk new file mode 100644 index 0000000..c0b91ae --- /dev/null +++ b/gps/android/2.0/Android.mk @@ -0,0 +1,112 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@2.0-impl-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + AGnss.cpp \ + Gnss.cpp \ + AGnssRil.cpp \ + GnssMeasurement.cpp \ + GnssConfiguration.cpp \ + GnssBatching.cpp \ + GnssGeofencing.cpp \ + GnssNi.cpp \ + GnssDebug.cpp \ + MeasurementCorrections.cpp \ + GnssVisibilityControl.cpp + +LOCAL_SRC_FILES += \ + location_api/GnssAPIClient.cpp \ + location_api/MeasurementAPIClient.cpp \ + location_api/GeofenceAPIClient.cpp \ + location_api/BatchingAPIClient.cpp \ + location_api/LocationUtil.cpp \ + +ifeq ($(GNSS_HIDL_LEGACY_MEASURMENTS),true) +LOCAL_CFLAGS += \ + -DGNSS_HIDL_LEGACY_MEASURMENTS +endif + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api + +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers \ + liblocbatterylistener_headers + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libhidlbase \ + libcutils \ + libutils \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + android.hardware.gnss@2.0 \ + android.hardware.gnss.measurement_corrections@1.0 \ + android.hardware.gnss.visibility_control@1.0 \ + android.hardware.health@1.0 \ + android.hardware.health@2.0 \ + android.hardware.health@2.1 \ + android.hardware.power@1.2 \ + libbase + +LOCAL_SHARED_LIBRARIES += \ + libloc_core \ + libgps.utils \ + libdl \ + liblocation_api \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) +LOCAL_STATIC_LIBRARIES := liblocbatterylistener +LOCAL_STATIC_LIBRARIES += libhealthhalutils +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@2.0-service-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VINTF_FRAGMENTS := android.hardware.gnss@2.0-service-qti.xml +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_INIT_RC := android.hardware.gnss@2.0-service-qti.rc +LOCAL_SRC_FILES := \ + service.cpp \ + +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers + + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils \ + libgps.utils \ + libqti_vndfwk_detect \ + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + android.hardware.gnss@2.0 \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) + +ifneq ($(LOC_HIDL_VERSION),) +LOCAL_CFLAGS += -DLOC_HIDL_VERSION='"$(LOC_HIDL_VERSION)"' +endif + +include $(BUILD_EXECUTABLE) diff --git a/gps/android/2.0/Gnss.cpp b/gps/android/2.0/Gnss.cpp new file mode 100644 index 0000000..823ef6e --- /dev/null +++ b/gps/android/2.0/Gnss.cpp @@ -0,0 +1,677 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssInterface" +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include "Gnss.h" +#include "LocationUtil.h" +#include "battery_listener.h" +#include "loc_misc_utils.h" + +typedef const GnssInterface* (getLocationInterface)(); + +#define IMAGES_INFO_FILE "/sys/devices/soc0/images" +#define DELIMITER ";" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::visibility_control::V1_0::implementation::GnssVisibilityControl; +static sp sGnss; +static std::string getVersionString() { + static std::string version; + if (!version.empty()) + return version; + + char value[PROPERTY_VALUE_MAX] = {0}; + property_get("ro.hardware", value, "unknown"); + version.append(value).append(DELIMITER); + + std::ifstream in(IMAGES_INFO_FILE); + std::string s; + while(getline(in, s)) { + std::size_t found = s.find("CRM:"); + if (std::string::npos == found) { + continue; + } + + // skip over space characters after "CRM:" + const char* substr = s.c_str(); + found += 4; + while (0 != substr[found] && isspace(substr[found])) { + found++; + } + if (s.find("11:") != found) { + continue; + } + s.erase(0, found + 3); + + found = s.find_first_of("\r\n"); + if (std::string::npos != found) { + s.erase(s.begin() + found, s.end()); + } + version.append(s).append(DELIMITER); + } + return version; +} + +void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnss != nullptr) { + mGnss->getGnssInterface()->resetNetworkInfo(); + mGnss->cleanup(); + } +} + +void location_on_battery_status_changed(bool charging) { + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not"); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } +} +Gnss::Gnss() { + ENTRY_LOG_CALLFLOW(); + sGnss = this; + // initilize gnss interface at first in case needing notify battery status + sGnss->getGnssInterface()->initialize(); + // register health client to listen on battery change + loc_extn_battery_properties_listener_init(location_on_battery_status_changed); + // clear pending GnssConfig + memset(&mPendingConfig, 0, sizeof(GnssConfig)); + mGnssDeathRecipient = new GnssDeathRecipient(this); +} + +Gnss::~Gnss() { + ENTRY_LOG_CALLFLOW(); + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } + sGnss = nullptr; +} + +GnssAPIClient* Gnss::getApi() { + if (mApi != nullptr) { + return mApi; + } + + if (mGnssCbIface_2_0 != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface_2_0); + } else if (mGnssCbIface_1_1 != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface_1_1, mGnssNiCbIface); + } else if (mGnssCbIface != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface); + } else { + LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__); + return mApi; + } + + if (mPendingConfig.size == sizeof(GnssConfig)) { + // we have pending GnssConfig + mApi->gnssConfigurationUpdate(mPendingConfig); + // clear size to invalid mPendingConfig + mPendingConfig.size = 0; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + } + } + + return mApi; +} + +const GnssInterface* Gnss::getGnssInterface() { + static bool getGnssInterfaceFailed = false; + + if (nullptr == mGnssInterface && !getGnssInterfaceFailed) { + void * libHandle = nullptr; + getLocationInterface* getter = (getLocationInterface*) + dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface"); + + if (nullptr == getter) { + getGnssInterfaceFailed = true; + } else { + mGnssInterface = (GnssInterface*)(*getter)(); + } + } + return mGnssInterface; +} + +Return Gnss::setCallback(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + + // In case where previous call to setCallback_1_1 or setCallback_2_0, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks_2_0(nullptr); + } + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_1_1 = nullptr; + } + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_0 = nullptr; + } + + + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface = callback; + if (mGnssCbIface != nullptr) { + mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + return true; +} + +Return Gnss::setGnssNiCb(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + mGnssNiCbIface = callback; + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + } + return true; +} + +Return Gnss::updateConfiguration(GnssConfig& gnssConfig) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssConfigurationUpdate(gnssConfig); + } else if (gnssConfig.flags != 0) { + // api is not ready yet, update mPendingConfig with gnssConfig + mPendingConfig.size = sizeof(GnssConfig); + + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + mPendingConfig.gpsLock = gnssConfig.gpsLock; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + mPendingConfig.suplVersion = gnssConfig.suplVersion; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + mPendingConfig.assistanceServer.hostName = + strdup(gnssConfig.assistanceServer.hostName); + } + mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT; + mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT; + mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + mPendingConfig.suplModeMask = gnssConfig.suplModeMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT; + mPendingConfig.emergencyExtensionSeconds = gnssConfig.emergencyExtensionSeconds; + } + } + return true; +} + +Return Gnss::start() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStart(); + } + return retVal; +} + +Return Gnss::stop() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStop(); + } + return retVal; +} + +Return Gnss::cleanup() { + ENTRY_LOG_CALLFLOW(); + + if (mApi != nullptr) { + mApi->gnssStop(); + mApi->gnssDisable(); + } + + return Void(); +} + +Return Gnss::injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters); + return true; + } else { + return false; + } +} + +Return Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs, + int32_t uncertaintyMs) { + return true; +} + +Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssDeleteAidingData(aidingDataFlags); + } + return Void(); +} + +Return Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs); + } + return retVal; +} + +Return> Gnss::getExtensionAGnss() { + ENTRY_LOG_CALLFLOW(); + // deprecated function. Must return nullptr to pass VTS + return nullptr; +} + +Return> Gnss::getExtensionGnssNi() { + ENTRY_LOG_CALLFLOW(); + // deprecated function. Must return nullptr to pass VTS + return nullptr; +} + +Return> Gnss::getExtensionGnssMeasurement() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +} + +Return> Gnss::getExtensionGnssConfiguration() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) { + mGnssConfig = new GnssConfiguration(this); + } + return mGnssConfig; +} + +Return> Gnss::getExtensionGnssGeofencing() { + ENTRY_LOG_CALLFLOW(); + if (mGnssGeofencingIface == nullptr) { + mGnssGeofencingIface = new GnssGeofencing(); + } + return mGnssGeofencingIface; +} + +Return> Gnss::getExtensionGnssBatching() { + ENTRY_LOG_CALLFLOW(); + if (mGnssBatching == nullptr) { + mGnssBatching = new GnssBatching(); + } + return mGnssBatching; +} + +Return> Gnss::getExtensionGnssDebug() { + ENTRY_LOG_CALLFLOW(); + if (mGnssDebug == nullptr) { + mGnssDebug = new GnssDebug(this); + } + return mGnssDebug; +} + +Return> Gnss::getExtensionAGnssRil() { + ENTRY_LOG_CALLFLOW(); + if (mGnssRil == nullptr) { + mGnssRil = new AGnssRil(this); + } + return mGnssRil; +} + +// Methods from ::android::hardware::gnss::V1_1::IGnss follow. +Return Gnss::setCallback_1_1(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + auto r = callback->gnssNameCb(getVersionString()); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNameCb description=%s", + __func__, r.description().c_str()); + } + + // In case where previous call to setCallback or setCallback_2_1, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks_2_0(nullptr); + } + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface = nullptr; + } + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_0 = nullptr; + } + + + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface_1_1 = callback; + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface_1_1, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + + return true; +} + +Return Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + bool lowPowerMode) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + GnssPowerMode powerMode = lowPowerMode? + GNSS_POWER_MODE_M4 : GNSS_POWER_MODE_M2; + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs, powerMode, minIntervalMs); + } + return retVal; +} + +Return> Gnss::getExtensionGnssMeasurement_1_1() { + ENTRY_LOG_CALLFLOW(); +#ifdef GNSS_HIDL_LEGACY_MEASURMENTS + return nullptr; +#else + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +#endif +} + +Return> Gnss::getExtensionGnssConfiguration_1_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) + mGnssConfig = new GnssConfiguration(this); + return mGnssConfig; +} + +Return Gnss::injectBestLocation(const GnssLocation& gnssLocation) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } + return true; +} + +void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) { + ENTRY_LOG_CALLFLOW(); + + if (ODCPI_REQUEST_TYPE_STOP == request.type) { + return; + } + if (mGnssCbIface_2_0 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + LOC_LOGd("gnssRequestLocationCb_2_0 isUserEmergency = %d", request.isEmergencyMode); + auto r = mGnssCbIface_2_0->gnssRequestLocationCb_2_0(!request.isEmergencyMode, + request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb_2_0 %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else if (mGnssCbIface_1_1 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + auto r = mGnssCbIface_1_1->gnssRequestLocationCb(!request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else { + LOC_LOGe("ODCPI request not supported."); + } +} + +// Methods from ::android::hardware::gnss::V2_0::IGnss follow. +Return Gnss::setCallback_2_0(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + auto r = callback->gnssNameCb(getVersionString()); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNameCb description=%s", + __func__, r.description().c_str()); + } + + // In case where previous call to setCallback or setCallback_1_1, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks(nullptr, nullptr); + } + mGnssNiCbIface = nullptr; + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface = nullptr; + } + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_1_1 = nullptr; + } + + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface_2_0 = callback; + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks_2_0(mGnssCbIface_2_0); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + + return true; +} + +Return> Gnss::getExtensionAGnss_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mAGnssIface_2_0 == nullptr) { + mAGnssIface_2_0 = new AGnss(this); + } + return mAGnssIface_2_0; +} +Return> Gnss::getExtensionAGnssRil_2_0() { + if (mGnssRil == nullptr) { + mGnssRil = new AGnssRil(this); + } + return mGnssRil; +} + +Return> Gnss::getExtensionGnssConfiguration_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) { + mGnssConfig = new GnssConfiguration(this); + } + return mGnssConfig; +} +Return> Gnss::getExtensionGnssMeasurement_2_0() { + ENTRY_LOG_CALLFLOW(); +#ifdef GNSS_HIDL_LEGACY_MEASURMENTS + return nullptr; +#else + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +#endif +} +Return> + Gnss::getExtensionMeasurementCorrections() { + // We do not support, so return nullptr to pass VTS + return nullptr; +} +Return> + Gnss::getExtensionVisibilityControl() { + ENTRY_LOG_CALLFLOW(); + if (mVisibCtrl == nullptr) { + mVisibCtrl = new GnssVisibilityControl(this); + } + return mVisibCtrl; +} + +Return Gnss::injectBestLocation_2_0(const V2_0::GnssLocation& gnssLocation) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } + return true; +} + +Return> Gnss::getExtensionGnssDebug_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mGnssDebug == nullptr) { + mGnssDebug = new GnssDebug(this); + } + return mGnssDebug; +} + +Return> Gnss::getExtensionGnssBatching_2_0() { + return nullptr; +} + +V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) { + ENTRY_LOG_CALLFLOW(); + V1_0::IGnss* iface = nullptr; + iface = new Gnss(); + if (iface == nullptr) { + LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal); + } + return iface; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/Gnss.h b/gps/android/2.0/Gnss.h new file mode 100644 index 0000000..a403d61 --- /dev/null +++ b/gps/android/2.0/Gnss.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSS_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSS_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "GnssAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections; +using ::android::hardware::gnss::measurement_corrections::V1_0::implementation::MeasurementCorrections; +using ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl; + +struct Gnss : public IGnss { + Gnss(); + ~Gnss(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnss follow. + * These declarations were generated from Gnss.hal. + */ + Return setCallback(const sp& callback) override; + Return start() override; + Return stop() override; + Return cleanup() override; + Return injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) override; + Return injectTime(int64_t timeMs, + int64_t timeReferenceMs, + int32_t uncertaintyMs) override; + Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; + Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) override; + Return> getExtensionAGnss() override; + Return> getExtensionGnssNi() override; + Return> getExtensionGnssMeasurement() override; + Return> getExtensionGnssConfiguration() override; + Return> getExtensionGnssGeofencing() override; + Return> getExtensionGnssBatching() override; + + Return> getExtensionAGnssRil() override; + + inline Return> getExtensionGnssNavigationMessage() override { + return nullptr; + } + + inline Return> getExtensionXtra() override { + return nullptr; + } + + Return> getExtensionGnssDebug() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnss follow. + Return setCallback_1_1(const sp& callback) override; + Return setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, bool lowPowerMode) override; + Return> getExtensionGnssMeasurement_1_1() override; + Return> getExtensionGnssConfiguration_1_1() override; + Return injectBestLocation(const GnssLocation& location) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnss follow. + Return setCallback_2_0(const sp& callback) override; + Return> getExtensionAGnss_2_0() override; + Return> getExtensionAGnssRil_2_0() override; + + Return> getExtensionGnssConfiguration_2_0() override; + Return> + getExtensionMeasurementCorrections() override; + Return> getExtensionGnssMeasurement_2_0() override; + + Return injectBestLocation_2_0(const ::android::hardware::gnss::V2_0::GnssLocation& location) override; + + Return> getExtensionGnssBatching_2_0() override; + Return> getExtensionGnssDebug_2_0() override; + + + /** + * This method returns the IGnssVisibilityControl interface. + * + * @return visibilityControlIface Handle to the IGnssVisibilityControl interface. + */ + Return> + getExtensionVisibilityControl() override; + + + // These methods are not part of the IGnss base class. + GnssAPIClient* getApi(); + Return setGnssNiCb(const sp& niCb); + Return updateConfiguration(GnssConfig& gnssConfig); + const GnssInterface* getGnssInterface(); + + // Callback for ODCPI request + void odcpiRequestCb(const OdcpiRequestInfo& request); + + private: + struct GnssDeathRecipient : hidl_death_recipient { + GnssDeathRecipient(sp gnss) : mGnss(gnss) { + } + ~GnssDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnss; + }; + + private: + sp mGnssDeathRecipient = nullptr; + + sp mGnssNi = nullptr; + sp mGnssGeofencingIface = nullptr; + sp mAGnssIface = nullptr; + sp mGnssCbIface = nullptr; + sp mGnssNiCbIface = nullptr; + sp mGnssCbIface_1_1 = nullptr; + sp mAGnssIface_2_0 = nullptr; + sp mGnssRil = nullptr; + sp mGnssMeasurement = nullptr; + sp mGnssConfig = nullptr; + sp mGnssBatching = nullptr; + sp mGnssDebug = nullptr; + sp mGnssCbIface_2_0 = nullptr; + sp mGnssMeasCorr = nullptr; + sp mVisibCtrl = nullptr; + + GnssAPIClient* mApi = nullptr; + GnssConfig mPendingConfig; + const GnssInterface* mGnssInterface = nullptr; +}; + +extern "C" V1_0::IGnss* HIDL_FETCH_IGnss(const char* name); + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSS_H diff --git a/gps/android/2.0/GnssBatching.cpp b/gps/android/2.0/GnssBatching.cpp new file mode 100644 index 0000000..6a2a09e --- /dev/null +++ b/gps/android/2.0/GnssBatching.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssBatchingInterface" + +#include +#include +#include "GnssBatching.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +void GnssBatching::GnssBatchingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssBatching != nullptr) { + mGnssBatching->stop(); + mGnssBatching->cleanup(); + } +} + +GnssBatching::GnssBatching() : mApi(nullptr) { + mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this); +} + +GnssBatching::~GnssBatching() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + + +// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. +Return GnssBatching::init(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface = callback; + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +Return GnssBatching::getBatchSize() { + uint16_t ret = 0; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->getBatchSize(); + } + return ret; +} + +Return GnssBatching::start(const IGnssBatching::Options& options) { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->startSession(options); + } + return ret; +} + +Return GnssBatching::flush() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->flushBatchedLocations(); + } + return Void(); +} + +Return GnssBatching::stop() { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->stopSession(); + } + return ret; +} + +Return GnssBatching::cleanup() { + if (mApi != nullptr) { + mApi->stopSession(); + } + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + mGnssBatchingCbIface = nullptr; + } + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->unlinkToDeath(mGnssBatchingDeathRecipient); + mGnssBatchingCbIface_2_0 = nullptr; + } + return Void(); +} + +// Methods from ::android::hardware::gnss::V2_0::IGnssBatching follow. +Return GnssBatching::init_2_0(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface_2_0 = callback; + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssBatching.h b/gps/android/2.0/GnssBatching.h new file mode 100644 index 0000000..4c8d1db --- /dev/null +++ b/gps/android/2.0/GnssBatching.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H + +#include +#include + + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssBatching; +using ::android::hardware::gnss::V2_0::IGnssBatchingCallback; +using ::android::hidl::base::V1_0::IBase; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class BatchingAPIClient; +struct GnssBatching : public IGnssBatching { + GnssBatching(); + ~GnssBatching(); + + // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. + Return init(const sp& callback) override; + Return getBatchSize() override; + Return start(const IGnssBatching::Options& options ) override; + Return flush() override; + Return stop() override; + Return cleanup() override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssBatching follow. + Return init_2_0(const sp& callback) override; + + private: + struct GnssBatchingDeathRecipient : hidl_death_recipient { + GnssBatchingDeathRecipient(sp gnssBatching) : + mGnssBatching(gnssBatching) { + } + ~GnssBatchingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssBatching; + }; + + private: + sp mGnssBatchingDeathRecipient = nullptr; + sp mGnssBatchingCbIface = nullptr; + BatchingAPIClient* mApi = nullptr; + sp mGnssBatchingCbIface_2_0 = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H diff --git a/gps/android/2.0/GnssConfiguration.cpp b/gps/android/2.0/GnssConfiguration.cpp new file mode 100644 index 0000000..55a70dc --- /dev/null +++ b/gps/android/2.0/GnssConfiguration.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssConfigurationInterface" + +#include +#include "Gnss.h" +#include "GnssConfiguration.h" +#include "ContextBase.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::GnssConstellationType; +using namespace loc_core; + +GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) { +} + +// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow. +Return GnssConfiguration::setSuplEs(bool enabled) { + // deprecated function. Must return false to pass VTS + return false; +} + +Return GnssConfiguration::setSuplVersion(uint32_t version) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; + case 0x00020002: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; + break; + case 0x00020000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0; + break; + case 0x00010000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0; + break; + default: + LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplMode(uint8_t mode) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + switch (mode) { + case 0: + config.suplModeMask = 0; // STANDALONE ONLY + break; + case 1: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT; + break; + case 2: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + case 3: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + default: + LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setLppProfile(uint8_t lppProfileMask) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default + + if (lppProfileMask & (1<<0)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT; + } + if (lppProfileMask & (1<<1)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT; + } + if (lppProfileMask & (1<<2)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT; + } + if (lppProfileMask & (1<<3)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + + config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + if (protocol & (1<<0)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT; + } + if (protocol & (1<<1)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT; + } + if (protocol & (1<<2)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT; + } + if (protocol & (1<<3)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGpsLock(uint8_t lock) { + + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + switch (lock) { + case 0: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + break; + case 1: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO; + break; + case 2: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI; + break; + case 3: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; + break; + default: + LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock); + return false; + } + + mGnss->updateConfiguration(config); + // Must return false to pass VTS + return false; +} + +Return GnssConfiguration::setEmergencySuplPdn(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + config.emergencyPdnForEmergencySupl = (enabled ? + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES : + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO); + + return mGnss->updateConfiguration(config); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. +Return GnssConfiguration::setBlacklist( + const hidl_vec& blacklist) { + + ENTRY_LOG_CALLFLOW(); + if (nullptr == mGnss) { + LOC_LOGe("mGnss is null"); + return false; + } + + // blValid is true if blacklist is empty, i.e. clearing the BL; + // if blacklist is not empty, blValid is initialied to false, and later + // updated in the for loop to become true only if there is at least + // one {constellation, svid} in the list that is valid. + bool blValid = (0 == blacklist.size()); + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + config.blacklistedSvIds.clear(); + + GnssSvIdSource source = {}; + for (int idx = 0; idx < (int)blacklist.size(); idx++) { + // Set blValid true if any one source is valid + blValid = setBlacklistedSource(source, blacklist[idx]) || blValid; + config.blacklistedSvIds.push_back(source); + } + + // Update configuration only if blValid is true + // i.e. only if atleast one source is valid for blacklisting + return (blValid && mGnss->updateConfiguration(config)); +} + +bool GnssConfiguration::setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource) { + + bool retVal = true; + uint16_t svIdOffset = 0; + copyToSource.size = sizeof(GnssSvIdSource); + copyToSource.svId = copyFromSource.svid; + + switch(copyFromSource.constellation) { + case GnssConstellationType::GPS: + copyToSource.constellation = GNSS_SV_TYPE_GPS; + LOC_LOGe("GPS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::SBAS: + copyToSource.constellation = GNSS_SV_TYPE_SBAS; + LOC_LOGe("SBAS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::GLONASS: + copyToSource.constellation = GNSS_SV_TYPE_GLONASS; + svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::QZSS: + copyToSource.constellation = GNSS_SV_TYPE_QZSS; + svIdOffset = 0; + break; + case GnssConstellationType::BEIDOU: + copyToSource.constellation = GNSS_SV_TYPE_BEIDOU; + svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::GALILEO: + copyToSource.constellation = GNSS_SV_TYPE_GALILEO; + svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1; + break; + default: + copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; + LOC_LOGe("Invalid constellation %hhu", copyFromSource.constellation); + retVal = false; + break; + } + + if (copyToSource.svId > 0 && svIdOffset > 0) { + copyToSource.svId += svIdOffset; + } + + return retVal; +} + +// Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow. +Return GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) { + ENTRY_LOG_CALLFLOW(); + if (mGnss == nullptr) { + LOC_LOGe("mGnss is nullptr"); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT; + config.emergencyExtensionSeconds = emergencyExtensionSeconds; + + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssConfiguration.h b/gps/android/2.0/GnssConfiguration.h new file mode 100644 index 0000000..c3de2c9 --- /dev/null +++ b/gps/android/2.0/GnssConfiguration.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ + + /* Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSCONFIGURATION_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSCONFIGURATION_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* + * Interface for passing GNSS configuration info from platform to HAL. + */ +struct Gnss; +struct GnssConfiguration : public V2_0::IGnssConfiguration { + GnssConfiguration(Gnss* gnss); + ~GnssConfiguration() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. + * These declarations were generated from IGnssConfiguration.hal. + */ + Return setSuplVersion(uint32_t version) override; + Return setSuplMode(uint8_t mode) override; + Return setSuplEs(bool enabled) override; + Return setLppProfile(uint8_t lppProfileMask) override; + Return setGlonassPositioningProtocol(uint8_t protocol) override; + Return setEmergencySuplPdn(bool enable) override; + Return setGpsLock(uint8_t lock) override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. + Return setBlacklist( + const hidl_vec& blacklist) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow. + Return setEsExtensionSec(uint32_t emergencyExtensionSeconds) override; + + private: + Gnss* mGnss = nullptr; + bool setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSCONFIGURATION_H diff --git a/gps/android/2.0/GnssDebug.cpp b/gps/android/2.0/GnssDebug.cpp new file mode 100644 index 0000000..dc0d9f4 --- /dev/null +++ b/gps/android/2.0/GnssDebug.cpp @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssDebugInterface" + +#include +#include +#include "Gnss.h" +#include "GnssDebug.h" +#include "LocationUtil.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::hidl_vec; +using ::android::hardware::gnss::V2_0::IGnssDebug; + +#define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000) +#define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000) +#define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500) +#define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) + +#define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm + +GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) +{ +} + +/* + * This methods requests position, time and satellite ephemeris debug information + * from the HAL. + * + * @return void +*/ +Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + V1_0::IGnssDebug::DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + V1_0::IGnssDebug::SatelliteData s = { }; + std::vector s_array; + + for (uint32_t i=0; i GnssDebug::getDebugData_2_0(getDebugData_2_0_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + V2_0::IGnssDebug::DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } + else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + V2_0::IGnssDebug::SatelliteData s = { }; + std::vector s_array; + + for (uint32_t i=0; i +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssDebug; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* Interface for GNSS Debug support. */ +struct Gnss; +struct GnssDebug : public IGnssDebug { + GnssDebug(Gnss* gnss); + ~GnssDebug() {}; + + // Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow + Return getDebugData(getDebugData_cb _hidl_cb) override; + // Methods from ::android::hardware::gnss::V2_0::IGnssDebug follow. + Return getDebugData_2_0(getDebugData_2_0_cb _hidl_cb) override; + +private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSDEBUG_H diff --git a/gps/android/2.0/GnssGeofencing.cpp b/gps/android/2.0/GnssGeofencing.cpp new file mode 100644 index 0000000..b6fc94b --- /dev/null +++ b/gps/android/2.0/GnssGeofencing.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GnssHal_GnssGeofencing" + +#include +#include +#include "GnssGeofencing.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssGeofencing != nullptr) { + mGnssGeofencing->removeAllGeofences(); + } +} + +GnssGeofencing::GnssGeofencing() : mApi(nullptr) { + mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this); +} + +GnssGeofencing::~GnssGeofencing() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. +Return GnssGeofencing::setCallback(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGd("mApi is NOT nullptr"); + return Void(); + } + + mApi = new GeofenceAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + } + + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient); + } + mGnssGeofencingCbIface = callback; + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssGeofencing::addGeofence( + int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceAdd( + geofenceId, + latitudeDegrees, + longitudeDegrees, + radiusMeters, + static_cast(lastTransition), + monitorTransitions, + notificationResponsivenessMs, + unknownTimerMs); + } + return Void(); +} + +Return GnssGeofencing::pauseGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofencePause(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceResume(geofenceId, monitorTransitions); + } + return Void(); +} + +Return GnssGeofencing::removeGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceRemove(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::removeAllGeofences() { + if (mApi == nullptr) { + LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__); + } else { + mApi->geofenceRemoveAll(); + } + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssGeofencing.h b/gps/android/2.0/GnssGeofencing.h new file mode 100644 index 0000000..caa56d0 --- /dev/null +++ b/gps/android/2.0/GnssGeofencing.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::IGnssGeofencing; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class GeofenceAPIClient; +struct GnssGeofencing : public IGnssGeofencing { + GnssGeofencing(); + ~GnssGeofencing(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. + * These declarations were generated from IGnssGeofencing.hal. + */ + Return setCallback(const sp& callback) override; + Return addGeofence(int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) override; + + Return pauseGeofence(int32_t geofenceId) override; + Return resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override; + Return removeGeofence(int32_t geofenceId) override; + + private: + // This method is not part of the IGnss base class. + // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far. + Return removeAllGeofences(); + + private: + struct GnssGeofencingDeathRecipient : hidl_death_recipient { + GnssGeofencingDeathRecipient(sp gnssGeofencing) : + mGnssGeofencing(gnssGeofencing) { + } + ~GnssGeofencingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssGeofencing; + }; + + private: + sp mGnssGeofencingDeathRecipient = nullptr; + sp mGnssGeofencingCbIface = nullptr; + GeofenceAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H diff --git a/gps/android/2.0/GnssMeasurement.cpp b/gps/android/2.0/GnssMeasurement.cpp new file mode 100644 index 0000000..6cb55ca --- /dev/null +++ b/gps/android/2.0/GnssMeasurement.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssMeasurementInterface" + +#include +#include "GnssMeasurement.h" +#include "MeasurementAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssMeasurement != nullptr) { + mGnssMeasurement->close(); + } +} + +GnssMeasurement::GnssMeasurement() { + mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this); + mApi = new MeasurementAPIClient(); +} + +GnssMeasurement::~GnssMeasurement() { + if (mApi) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. +Return GnssMeasurement::setCallback( + const sp& callback) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface = callback; + mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + return mApi->measurementSetCallback(callback); +} + +void GnssMeasurement::clearInterfaces() { + if (mGnssMeasurementCbIface != nullptr) { + mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface = nullptr; + } + if (mGnssMeasurementCbIface_1_1 != nullptr) { + mGnssMeasurementCbIface_1_1->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_1_1 = nullptr; + } + if (mGnssMeasurementCbIface_2_0 != nullptr) { + mGnssMeasurementCbIface_2_0->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_2_0 = nullptr; + } +} + +Return GnssMeasurement::close() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return Void(); + } + + clearInterfaces(); + mApi->measurementClose(); + + return Void(); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_1_1( + const sp& callback, bool enableFullTracking) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_1_1 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface_1_1 = callback; + mGnssMeasurementCbIface_1_1->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_1_1(callback, powerMode); +} +// Methods from ::android::hardware::gnss::V2_0::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_2_0( + const sp& callback, + bool enableFullTracking) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_2_0 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface_2_0 = callback; + mGnssMeasurementCbIface_2_0->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking ? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_2_0(callback, powerMode); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssMeasurement.h b/gps/android/2.0/GnssMeasurement.h new file mode 100644 index 0000000..7fa66b4 --- /dev/null +++ b/gps/android/2.0/GnssMeasurement.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class MeasurementAPIClient; +struct GnssMeasurement : public V2_0::IGnssMeasurement { + GnssMeasurement(); + ~GnssMeasurement(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + * These declarations were generated from IGnssMeasurement.hal. + */ + Return setCallback( + const sp& callback) override; + Return close() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. + Return setCallback_1_1( + const sp& callback, + bool enableFullTracking) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssMeasurement follow. + Return setCallback_2_0( + const sp& callback, + bool enableFullTracking) override; + private: + struct GnssMeasurementDeathRecipient : hidl_death_recipient { + GnssMeasurementDeathRecipient(sp gnssMeasurement) : + mGnssMeasurement(gnssMeasurement) { + } + ~GnssMeasurementDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssMeasurement; + }; + + private: + sp mGnssMeasurementDeathRecipient = nullptr; + sp mGnssMeasurementCbIface = nullptr; + sp mGnssMeasurementCbIface_1_1 = nullptr; + sp mGnssMeasurementCbIface_2_0 = nullptr; + MeasurementAPIClient* mApi; + void clearInterfaces(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H diff --git a/gps/android/2.0/GnssNi.cpp b/gps/android/2.0/GnssNi.cpp new file mode 100644 index 0000000..d65a488 --- /dev/null +++ b/gps/android/2.0/GnssNi.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssNiInterface" + +#include +#include "Gnss.h" +#include "GnssNi.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + // we do nothing here + // Gnss::GnssDeathRecipient will stop the session +} + +GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) { + mGnssNiDeathRecipient = new GnssNiDeathRecipient(this); +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. +Return GnssNi::setCallback(const sp& callback) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + mGnss->setGnssNiCb(callback); + + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient); + } + mGnssNiCbIface = callback; + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + GnssAPIClient* api = mGnss->getApi(); + if (api == nullptr) { + LOC_LOGE("%s]: api is nullptr", __FUNCTION__); + return Void(); + } + + api->gnssNiRespond(notifId, userResponse); + + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssNi.h b/gps/android/2.0/GnssNi.h new file mode 100644 index 0000000..26e281f --- /dev/null +++ b/gps/android/2.0/GnssNi.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssNi; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct GnssNi : public IGnssNi { + GnssNi(Gnss* gnss); + ~GnssNi() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. + * These declarations were generated from IGnssNi.hal. + */ + Return setCallback(const sp& callback) override; + Return respond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) override; + + private: + struct GnssNiDeathRecipient : hidl_death_recipient { + GnssNiDeathRecipient(sp gnssNi) : mGnssNi(gnssNi) { + } + ~GnssNiDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssNi; + }; + + private: + sp mGnssNiDeathRecipient = nullptr; + sp mGnssNiCbIface = nullptr; + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H diff --git a/gps/android/2.0/GnssVisibilityControl.cpp b/gps/android/2.0/GnssVisibilityControl.cpp new file mode 100644 index 0000000..5a8c697 --- /dev/null +++ b/gps/android/2.0/GnssVisibilityControl.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include "GnssVisibilityControl.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace visibility_control { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +static GnssVisibilityControl* spGnssVisibilityControl = nullptr; + +static void convertGnssNfwNotification(GnssNfwNotification& in, + IGnssVisibilityControlCallback::NfwNotification& out); + +GnssVisibilityControl::GnssVisibilityControl(Gnss* gnss) : mGnss(gnss) { + spGnssVisibilityControl = this; +} +GnssVisibilityControl::~GnssVisibilityControl() { + spGnssVisibilityControl = nullptr; +} + +void GnssVisibilityControl::nfwStatusCb(GnssNfwNotification notification) { + if (nullptr != spGnssVisibilityControl) { + spGnssVisibilityControl->statusCb(notification); + } +} + +bool GnssVisibilityControl::isInEmergencySession() { + if (nullptr != spGnssVisibilityControl) { + return spGnssVisibilityControl->isE911Session(); + } + return false; +} + +static void convertGnssNfwNotification(GnssNfwNotification& in, + IGnssVisibilityControlCallback::NfwNotification& out) +{ + memset(&out, 0, sizeof(IGnssVisibilityControlCallback::NfwNotification)); + out.proxyAppPackageName = in.proxyAppPackageName; + out.protocolStack = (IGnssVisibilityControlCallback::NfwProtocolStack)in.protocolStack; + out.otherProtocolStackName = in.otherProtocolStackName; + out.requestor = (IGnssVisibilityControlCallback::NfwRequestor)in.requestor; + out.requestorId = in.requestorId; + out.responseType = (IGnssVisibilityControlCallback::NfwResponseType)in.responseType; + out.inEmergencyMode = in.inEmergencyMode; + out.isCachedLocation = in.isCachedLocation; +} + +void GnssVisibilityControl::statusCb(GnssNfwNotification notification) { + + if (mGnssVisibilityControlCbIface != nullptr) { + IGnssVisibilityControlCallback::NfwNotification nfwNotification; + + // Convert from one structure to another + convertGnssNfwNotification(notification, nfwNotification); + + auto r = mGnssVisibilityControlCbIface->nfwNotifyCb(nfwNotification); + if (!r.isOk()) { + LOC_LOGw("Error invoking NFW status cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +bool GnssVisibilityControl::isE911Session() { + + if (mGnssVisibilityControlCbIface != nullptr) { + auto r = mGnssVisibilityControlCbIface->isInEmergencySession(); + if (!r.isOk()) { + LOC_LOGw("Error invoking NFW status cb %s", r.description().c_str()); + return false; + } else { + return (r); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + return false; + } +} + +// Methods from ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl follow. +Return GnssVisibilityControl::enableNfwLocationAccess(const hidl_vec<::android::hardware::hidl_string>& proxyApps) { + + if (nullptr == mGnss || nullptr == mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return false; + } + + /* If the vector is empty we need to disable all NFW clients + If there is at least one app in the vector we need to enable + all NFW clients */ + if (0 == proxyApps.size()) { + mGnss->getGnssInterface()->enableNfwLocationAccess(false); + } else { + mGnss->getGnssInterface()->enableNfwLocationAccess(true); + } + + return true; +} +/** + * Registers the callback for HAL implementation to use. + * + * @param callback Handle to IGnssVisibilityControlCallback interface. + */ +Return GnssVisibilityControl::setCallback(const ::android::sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback>& callback) { + + if (nullptr == mGnss || nullptr == mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return false; + } + mGnssVisibilityControlCbIface = callback; + + NfwCbInfo cbInfo = {}; + cbInfo.visibilityControlCb = (void*)nfwStatusCb; + cbInfo.isInEmergencySession = (void*)isInEmergencySession; + + mGnss->getGnssInterface()->nfwInit(cbInfo); + + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace visibility_control +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/GnssVisibilityControl.h b/gps/android/2.0/GnssVisibilityControl.h new file mode 100644 index 0000000..9c26e38 --- /dev/null +++ b/gps/android/2.0/GnssVisibilityControl.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H +#define ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H + +#include +#include +#include + +#include +#include +#include "Gnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace visibility_control { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V2_0::implementation::Gnss; + +struct GnssVisibilityControl : public IGnssVisibilityControl { + GnssVisibilityControl(Gnss* gnss); + ~GnssVisibilityControl(); + + // Methods from ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl follow. + Return enableNfwLocationAccess(const hidl_vec<::android::hardware::hidl_string>& proxyApps) override; + /** + * Registers the callback for HAL implementation to use. + * + * @param callback Handle to IGnssVisibilityControlCallback interface. + */ + Return setCallback(const ::android::sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback>& callback) override; + + void statusCb(GnssNfwNotification notification); + bool isE911Session(); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void nfwStatusCb(GnssNfwNotification notification); + static bool isInEmergencySession(); + +private: + Gnss* mGnss = nullptr; + sp mGnssVisibilityControlCbIface = nullptr; +}; + + +} // namespace implementation +} // namespace V1_0 +} // namespace visibility_control +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H diff --git a/gps/android/2.0/MeasurementCorrections.cpp b/gps/android/2.0/MeasurementCorrections.cpp new file mode 100644 index 0000000..bb75073 --- /dev/null +++ b/gps/android/2.0/MeasurementCorrections.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "LocSvc_MeasurementCorrectionsInterface" + +#include +#include "MeasurementCorrections.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; + +MeasurementCorrections::MeasurementCorrections() { +} + +MeasurementCorrections::~MeasurementCorrections() { +} + +Return MeasurementCorrections::setCorrections( + const ::android::hardware::gnss::measurement_corrections:: + V1_0::MeasurementCorrections& /*corrections*/) { + return true; +} + +Return MeasurementCorrections::setCallback( + const sp& /*callback*/) { + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/MeasurementCorrections.h b/gps/android/2.0/MeasurementCorrections.h new file mode 100644 index 0000000..96b1120 --- /dev/null +++ b/gps/android/2.0/MeasurementCorrections.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_MeasurementCorrections_H +#define ANDROID_HARDWARE_GNSS_V1_0_MeasurementCorrections_H + +#include +#include +#include +#include + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; + +struct MeasurementCorrections : public IMeasurementCorrections { + MeasurementCorrections(); + ~MeasurementCorrections(); + +// Methods from ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections follow. +Return setCorrections( + const ::android::hardware::gnss::measurement_corrections:: + V1_0::MeasurementCorrections& corrections) override; + +Return setCallback(const sp& callback) override; +}; + + +} // namespace implementation +} // namespace V1_0 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_MeasurementCorrections_H diff --git a/gps/android/2.0/android.hardware.gnss@2.0-service-qti.rc b/gps/android/2.0/android.hardware.gnss@2.0-service-qti.rc new file mode 100644 index 0000000..ad46d5d --- /dev/null +++ b/gps/android/2.0/android.hardware.gnss@2.0-service-qti.rc @@ -0,0 +1,4 @@ +service gnss_service /vendor/bin/hw/android.hardware.gnss@2.0-service-qti + class hal + user gps + group system gps radio vendor_qti_diag diff --git a/gps/android/2.0/android.hardware.gnss@2.0-service-qti.xml b/gps/android/2.0/android.hardware.gnss@2.0-service-qti.xml new file mode 100644 index 0000000..ff9fb2c --- /dev/null +++ b/gps/android/2.0/android.hardware.gnss@2.0-service-qti.xml @@ -0,0 +1,36 @@ + + + + android.hardware.gnss + hwbinder + @1.1::IGnss/default + @2.0::IGnss/default + + + diff --git a/gps/android/2.0/location_api/BatchingAPIClient.cpp b/gps/android/2.0/location_api/BatchingAPIClient.cpp new file mode 100644 index 0000000..766c37a --- /dev/null +++ b/gps/android/2.0/location_api/BatchingAPIClient.cpp @@ -0,0 +1,251 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_BatchingAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "BatchingAPIClient.h" + +#include "limits.h" + + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssBatching; +using ::android::hardware::gnss::V2_0::IGnssBatchingCallback; +using ::android::hardware::gnss::V2_0::GnssLocation; + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask); + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(nullptr), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + gnssUpdateCallbacks(callback); +} + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(nullptr), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + gnssUpdateCallbacks_2_0(callback); +} + +BatchingAPIClient::~BatchingAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +int BatchingAPIClient::getBatchSize() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + return locAPIGetBatchSize(); +} + +void BatchingAPIClient::setCallbacks() +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.batchingCb = [this](size_t count, Location* location, + BatchingOptions batchOptions) { + onBatchingCb(count, location, batchOptions); + }; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void BatchingAPIClient::gnssUpdateCallbacks(const sp& callback) +{ + mMutex.lock(); + mGnssBatchingCbIface = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface != nullptr) { + setCallbacks(); + } +} + +void BatchingAPIClient::gnssUpdateCallbacks_2_0(const sp& callback) +{ + mMutex.lock(); + mGnssBatchingCbIface_2_0 = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface_2_0 != nullptr) { + setCallbacks(); + } +} + +int BatchingAPIClient::startSession(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::updateSessionOptions(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::stopSession() +{ + LOC_LOGD("%s]: ", __FUNCTION__); + int retVal = -1; + if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +void BatchingAPIClient::getBatchedLocation(int last_n_locations) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations); + locAPIGetBatchedLocations(mDefaultId, last_n_locations); +} + +void BatchingAPIClient::flushBatchedLocations() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + locAPIGetBatchedLocations(mDefaultId, SIZE_MAX); +} + +void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; +} + +void BatchingAPIClient::onBatchingCb(size_t count, Location* location, + BatchingOptions /*batchOptions*/) +{ + mMutex.lock(); + auto gnssBatchingCbIface(mGnssBatchingCbIface); + auto gnssBatchingCbIface_2_0(mGnssBatchingCbIface_2_0); + mMutex.unlock(); + + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count); + if (gnssBatchingCbIface_2_0 != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = gnssBatchingCbIface_2_0->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb 2.0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssBatchingCbIface != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = gnssBatchingCbIface->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb 1.0 description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask) +{ + memset(&out, 0, sizeof(LocationOptions)); + out.size = sizeof(LocationOptions); + out.minInterval = (uint32_t)(in.periodNanos / 1000000L); + out.minDistance = 0; + out.mode = GNSS_SUPL_MODE_STANDALONE; + if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + out.mode = GNSS_SUPL_MODE_MSA; + if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + out.mode = GNSS_SUPL_MODE_MSB; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/location_api/BatchingAPIClient.h b/gps/android/2.0/location_api/BatchingAPIClient.h new file mode 100644 index 0000000..d2d9b4a --- /dev/null +++ b/gps/android/2.0/location_api/BatchingAPIClient.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef BATCHING_API_CLINET_H +#define BATCHING_API_CLINET_H + +#include +#include +#include +#include + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +class BatchingAPIClient : public LocationAPIClientBase +{ +public: + BatchingAPIClient(const sp& callback); + BatchingAPIClient(const sp& callback); + void gnssUpdateCallbacks(const sp& callback); + void gnssUpdateCallbacks_2_0(const sp& callback); + int getBatchSize(); + int startSession(const V1_0::IGnssBatching::Options& options); + int updateSessionOptions(const V1_0::IGnssBatching::Options& options); + int stopSession(); + void getBatchedLocation(int last_n_locations); + void flushBatchedLocations(); + + inline LocationCapabilitiesMask getCapabilities() { return mLocationCapabilitiesMask; } + + // callbacks + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions) final; + +private: + void setCallbacks(); + ~BatchingAPIClient(); + + std::mutex mMutex; + sp mGnssBatchingCbIface; + uint32_t mDefaultId; + LocationCapabilitiesMask mLocationCapabilitiesMask; + sp mGnssBatchingCbIface_2_0; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // BATCHING_API_CLINET_H diff --git a/gps/android/2.0/location_api/GeofenceAPIClient.cpp b/gps/android/2.0/location_api/GeofenceAPIClient.cpp new file mode 100644 index 0000000..a93c988 --- /dev/null +++ b/gps/android/2.0/location_api/GeofenceAPIClient.cpp @@ -0,0 +1,275 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GeofenceApiClient" + +#include +#include + +#include "LocationUtil.h" +#include "GeofenceAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +GeofenceAPIClient::GeofenceAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssGeofencingCbIface(callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + + locationCallbacks.geofenceBreachCb = nullptr; + if (mGnssGeofencingCbIface != nullptr) { + locationCallbacks.geofenceBreachCb = + [this](GeofenceBreachNotification geofenceBreachNotification) { + onGeofenceBreachCb(geofenceBreachNotification); + }; + + locationCallbacks.geofenceStatusCb = + [this](GeofenceStatusNotification geofenceStatusNotification) { + onGeofenceStatusCb(geofenceStatusNotification); + }; + } + + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms) +{ + LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__, + geofence_id, latitude, longitude, radius_meters, + last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms); + + GeofenceOption options; + memset(&options, 0, sizeof(GeofenceOption)); + options.size = sizeof(GeofenceOption); + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + options.breachTypeMask |= GEOFENCE_BREACH_EXIT_BIT; + options.responsiveness = notification_responsiveness_ms; + + GeofenceInfo data; + data.size = sizeof(GeofenceInfo); + data.latitude = latitude; + data.longitude = longitude; + data.radius = radius_meters; + + LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data); + if (LOCATION_ERROR_SUCCESS != err) { + onAddGeofencesCb(1, &err, &geofence_id); + } +} + +void GeofenceAPIClient::geofencePause(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIPauseGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions); + GeofenceBreachTypeMask mask = 0; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + mask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + mask |= GEOFENCE_BREACH_EXIT_BIT; + locAPIResumeGeofences(1, &geofence_id, &mask); +} + +void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIRemoveGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceRemoveAll() +{ + LOC_LOGD("%s]", __FUNCTION__); + // TODO locAPIRemoveAllGeofences(); +} + +// callbacks +void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceBreachNotification.count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < geofenceBreachNotification.count; i++) { + GnssLocation gnssLocation; + convertGnssLocation(geofenceBreachNotification.location, gnssLocation); + + IGnssGeofenceCallback::GeofenceTransition transition; + if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER) + transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED; + else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT) + transition = IGnssGeofenceCallback::GeofenceTransition::EXITED; + else { + // continue with other breach if transition is + // nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED + continue; + } + + auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb( + geofenceBreachNotification.ids[i], gnssLocation, transition, + static_cast(geofenceBreachNotification.timestamp)); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available); + if (mGnssGeofencingCbIface != nullptr) { + IGnssGeofenceCallback::GeofenceAvailability status = + IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE; + if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) { + status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE; + } + GnssLocation gnssLocation; + memset(&gnssLocation, 0, sizeof(GnssLocation)); + auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_EXISTS) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS; + auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/location_api/GeofenceAPIClient.h b/gps/android/2.0/location_api/GeofenceAPIClient.h new file mode 100644 index 0000000..5bce476 --- /dev/null +++ b/gps/android/2.0/location_api/GeofenceAPIClient.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GEOFENCE_API_CLINET_H +#define GEOFENCE_API_CLINET_H + + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::sp; + +class GeofenceAPIClient : public LocationAPIClientBase +{ +public: + GeofenceAPIClient(const sp& callback); + + void geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms); + void geofencePause(uint32_t geofence_id); + void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions); + void geofenceRemove(uint32_t geofence_id); + void geofenceRemoveAll(); + + // callbacks + void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final; + void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final; + void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + +private: + virtual ~GeofenceAPIClient() = default; + + sp mGnssGeofencingCbIface; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GEOFENCE_API_CLINET_H diff --git a/gps/android/2.0/location_api/GnssAPIClient.cpp b/gps/android/2.0/location_api/GnssAPIClient.cpp new file mode 100644 index 0000000..44007d9 --- /dev/null +++ b/gps/android/2.0/location_api/GnssAPIClient.cpp @@ -0,0 +1,728 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GnssAPIClient" +#define SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC (590 * 60 * 60 * 1000) // 590 hours + +#include +#include +#include + +#include "LocationUtil.h" +#include "GnssAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnss; +using ::android::hardware::gnss::V2_0::IGnssCallback; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::gnss::V2_0::GnssLocation; + +static void convertGnssSvStatus(GnssSvNotification& in, V1_0::IGnssCallback::GnssSvStatus& out); +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out); + +GnssAPIClient::GnssAPIClient(const sp& gpsCb, + const sp& niCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false), + mTracking(false), + mGnssCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + initLocationOptions(); + gnssUpdateCallbacks(gpsCb, niCb); +} + +GnssAPIClient::GnssAPIClient(const sp& gpsCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false), + mTracking(false), + mGnssCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + initLocationOptions(); + gnssUpdateCallbacks_2_0(gpsCb); +} + +GnssAPIClient::~GnssAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient) { + delete mControlClient; + mControlClient = nullptr; + } +} + +void GnssAPIClient::initLocationOptions() +{ + // set default LocationOptions. + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = 1000; + mTrackingOptions.minDistance = 0; + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; +} + +void GnssAPIClient::setCallbacks() +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.trackingCb = [this](Location location) { + onTrackingCb(location); + }; + + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + if (mGnssNiCbIface != nullptr) { + loc_core::ContextBase* context = + loc_core::LocContext::getLocContext(loc_core::LocContext::mLocationHalName); + if (!context->hasAgpsExtendedCapabilities()) { + LOC_LOGD("Registering NI CB"); + locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotify) { + onGnssNiCb(id, gnssNiNotify); + }; + } + } + + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) { + onGnssSvCb(gnssSvNotification); + }; + + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) { + onGnssNmeaCb(gnssNmeaNotification); + }; + + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +// for GpsInterface +void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + mMutex.lock(); + mGnssCbIface = gpsCb; + mGnssNiCbIface = niCb; + mMutex.unlock(); + + if (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr) { + setCallbacks(); + } +} + +void GnssAPIClient::gnssUpdateCallbacks_2_0(const sp& gpsCb) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + mMutex.lock(); + mGnssCbIface_2_0 = gpsCb; + mMutex.unlock(); + + if (mGnssCbIface_2_0 != nullptr) { + setCallbacks(); + } +} + +bool GnssAPIClient::gnssStart() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + + mMutex.lock(); + mTracking = true; + mMutex.unlock(); + + bool retVal = true; + locAPIStartTracking(mTrackingOptions); + return retVal; +} + +bool GnssAPIClient::gnssStop() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + + mMutex.lock(); + mTracking = false; + mMutex.unlock(); + + bool retVal = true; + locAPIStopTracking(); + return retVal; +} + +bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode, + IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%d %d %d %d %d %d %d)", __FUNCTION__, + (int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, + preferredTimeMs, (int)powerMode, timeBetweenMeasurement); + bool retVal = true; + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = minIntervalMs; + if (IGnss::GnssPositionMode::MS_ASSISTED == mode || + IGnss::GnssPositionRecurrence::RECURRENCE_SINGLE == recurrence) { + // We set a very large interval to simulate SINGLE mode. Once we report a fix, + // the caller should take the responsibility to stop the session. + // For MSA, we always treat it as SINGLE mode. + mTrackingOptions.minInterval = SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC; + } + if (mode == IGnss::GnssPositionMode::STANDALONE) + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + else if (mode == IGnss::GnssPositionMode::MS_BASED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSB; + else if (mode == IGnss::GnssPositionMode::MS_ASSISTED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSA; + else { + LOC_LOGD("%s]: invalid GnssPositionMode: %d", __FUNCTION__, (int)mode); + retVal = false; + } + if (GNSS_POWER_MODE_INVALID != powerMode) { + mTrackingOptions.powerMode = powerMode; + mTrackingOptions.tbm = timeBetweenMeasurement; + } + locAPIUpdateTrackingOptions(mTrackingOptions); + return retVal; +} + +// for GpsNiInterface +void GnssAPIClient::gnssNiRespond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast(userResponse)); + GnssNiResponse data; + switch (userResponse) { + case IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT: + data = GNSS_NI_RESPONSE_ACCEPT; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY: + data = GNSS_NI_RESPONSE_DENY; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP: + data = GNSS_NI_RESPONSE_NO_RESPONSE; + break; + default: + data = GNSS_NI_RESPONSE_IGNORE; + break; + } + + locAPIGnssNiResponse(notifId, data); +} + +// these apis using LocationAPIControlClient +void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags) +{ + LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags); + if (mControlClient == nullptr) { + return; + } + GnssAidingData data; + memset(&data, 0, sizeof (GnssAidingData)); + data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS_BIT | + GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT | + GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT | + GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT | + GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT | + GNSS_AIDING_DATA_SV_TYPE_NAVIC_BIT; + data.posEngineMask = STANDARD_POSITIONING_ENGINE; + + if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL) + data.deleteAll = true; + else { + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS) + data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC) + data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION) + data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME) + data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO) + data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC) + data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH) + data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR) + data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER) + data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA) + data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI) + data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO) + data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB_BIT; + } + mControlClient->locAPIGnssDeleteAidingData(data); +} + +void GnssAPIClient::gnssEnable(LocationTechnologyType techType) +{ + LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIEnable(techType); +} + +void GnssAPIClient::gnssDisable() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIDisable(); +} + +void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig) +{ + LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIGnssUpdateConfig(gnssConfig); +} + +void GnssAPIClient::requestCapabilities() { + // only send capablities if it's already cached, otherwise the first time LocationAPI + // is initialized, capabilities will be sent by LocationAPI + if (mLocationCapabilitiesCached) { + onCapabilitiesCb(mLocationCapabilitiesMask); + } +} + +// callbacks +void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; + mLocationCapabilitiesCached = true; + + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + mMutex.unlock(); + + if (gnssCbIface_2_0 != nullptr || gnssCbIface != nullptr) { + uint32_t data = 0; + if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT)) + data |= IGnssCallback::Capabilities::SCHEDULING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT) + data |= V1_0::IGnssCallback::Capabilities::GEOFENCING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) + data |= V1_0::IGnssCallback::Capabilities::MEASUREMENTS; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + data |= IGnssCallback::Capabilities::MSB; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + data |= IGnssCallback::Capabilities::MSA; + if (capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) + data |= IGnssCallback::Capabilities::LOW_POWER_MODE; + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT) + data |= IGnssCallback::Capabilities::SATELLITE_BLACKLIST; + + IGnssCallback::GnssSystemInfo gnssInfo = { .yearOfHw = 2015 }; + + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) { + gnssInfo.yearOfHw++; // 2016 + if (capabilitiesMask & LOCATION_CAPABILITIES_DEBUG_NMEA_BIT) { + gnssInfo.yearOfHw++; // 2017 + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT || + capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) { + gnssInfo.yearOfHw++; // 2018 + if (capabilitiesMask & LOCATION_CAPABILITIES_PRIVACY_BIT) { + gnssInfo.yearOfHw++; // 2019 + } + } + } + } + LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw); + + if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssSetCapabilitiesCb_2_0(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitiesCb_2_0 description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssSetCapabilitesCb(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } + + } + +} + +void GnssAPIClient::onTrackingCb(Location location) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + bool isTracking = mTracking; + mMutex.unlock(); + + LOC_LOGD("%s]: (flags: %02x isTracking: %d)", __FUNCTION__, location.flags, isTracking); + + if (!isTracking) { + return; + } + + if (gnssCbIface_2_0 != nullptr) { + V2_0::GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface_2_0->gnssLocationCb_2_0(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb_2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + V1_0::GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface->gnssLocationCb(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb description=%s", + __func__, r.description().c_str()); + } + } else { + LOC_LOGW("%s] No GNSS Interface ready for gnssLocationCb ", __FUNCTION__); + } + +} + +void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) +{ + LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id); + mMutex.lock(); + auto gnssNiCbIface(mGnssNiCbIface); + mMutex.unlock(); + + if (gnssNiCbIface == nullptr) { + LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__); + return; + } + + IGnssNiCallback::GnssNiNotification notificationGnss = {}; + + notificationGnss.notificationId = id; + + if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL; + else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_EMERGENCY_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::EMERGENCY_SUPL; + + if (gnssNiNotification.options & GNSS_NI_OPTIONS_NOTIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_VERIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE; + + notificationGnss.timeoutSec = gnssNiNotification.timeout; + + if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE || + gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP; + + notificationGnss.requestorId = gnssNiNotification.requestor; + + notificationGnss.notificationMessage = gnssNiNotification.message; + + if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + gnssNiCbIface->niNotifyCb(notificationGnss); +} + +void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification) +{ + LOC_LOGD("%s]: (count: %u)", __FUNCTION__, gnssSvNotification.count); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + mMutex.unlock(); + + if (gnssCbIface_2_0 != nullptr) { + hidl_vec svInfoList; + convertGnssSvStatus(gnssSvNotification, svInfoList); + auto r = gnssCbIface_2_0->gnssSvStatusCb_2_0(svInfoList); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb_2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + V1_0::IGnssCallback::GnssSvStatus svStatus; + convertGnssSvStatus(gnssSvNotification, svStatus); + auto r = gnssCbIface->gnssSvStatusCb(svStatus); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + mMutex.unlock(); + + if (gnssCbIface != nullptr || gnssCbIface_2_0 != nullptr) { + const std::string s(gnssNmeaNotification.nmea); + std::stringstream ss(s); + std::string each; + while(std::getline(ss, each, '\n')) { + each += '\n'; + android::hardware::hidl_string nmeaString; + nmeaString.setToExternal(each.c_str(), each.length()); + if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssCbIface_2_0 nmea=%s length=%u description=%s", + __func__, gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%u description=%s", + __func__, gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } + } + } +} + +void GnssAPIClient::onStartTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS) { + if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2.0 ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2.0 SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GnssAPIClient::onStopTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS) { + if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2.0 SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2.0 ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, V1_0::IGnssCallback::GnssSvStatus& out) +{ + memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus)); + out.numSvs = in.count; + if (out.numSvs > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many satellites %u. Clamps to %d.", + __FUNCTION__, out.numSvs, V1_0::GnssMax::SVS_COUNT); + out.numSvs = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.numSvs; i++) { + convertGnssSvid(in.gnssSvs[i], out.gnssSvList[i].svid); + convertGnssConstellationType(in.gnssSvs[i].type, out.gnssSvList[i].constellation); + out.gnssSvList[i].cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + out.gnssSvList[i].elevationDegrees = in.gnssSvs[i].elevation; + out.gnssSvList[i].azimuthDegrees = in.gnssSvs[i].azimuth; + out.gnssSvList[i].carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + out.gnssSvList[i].svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out) +{ + out.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssSvid(in.gnssSvs[i], out[i].v1_0.svid); + out[i].v1_0.cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + out[i].v1_0.elevationDegrees = in.gnssSvs[i].elevation; + out[i].v1_0.azimuthDegrees = in.gnssSvs[i].azimuth; + out[i].v1_0.carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + out[i].v1_0.svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + + convertGnssConstellationType(in.gnssSvs[i].type, out[i].constellation); + } +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/location_api/GnssAPIClient.h b/gps/android/2.0/location_api/GnssAPIClient.h new file mode 100644 index 0000000..cfa78c7 --- /dev/null +++ b/gps/android/2.0/location_api/GnssAPIClient.h @@ -0,0 +1,115 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GNSS_API_CLINET_H +#define GNSS_API_CLINET_H + + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::sp; + +class GnssAPIClient : public LocationAPIClientBase +{ +public: + GnssAPIClient(const sp& gpsCb, + const sp& niCb); + GnssAPIClient(const sp& gpsCb); + GnssAPIClient(const GnssAPIClient&) = delete; + GnssAPIClient& operator=(const GnssAPIClient&) = delete; + + // for GpsInterface + void gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb); + void gnssUpdateCallbacks_2_0(const sp& gpsCb); + bool gnssStart(); + bool gnssStop(); + bool gnssSetPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = 0); + + // for GpsNiInterface + void gnssNiRespond(int32_t notifId, V1_0::IGnssNiCallback::GnssUserResponseType userResponse); + + // these apis using LocationAPIControlClient + void gnssDeleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags); + void gnssEnable(LocationTechnologyType techType); + void gnssDisable(); + void gnssConfigurationUpdate(const GnssConfig& gnssConfig); + + inline LocationCapabilitiesMask gnssGetCapabilities() const { + return mLocationCapabilitiesMask; + } + void requestCapabilities(); + + // callbacks we are interested in + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onTrackingCb(Location location) final; + void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final; + void onGnssSvCb(GnssSvNotification gnssSvNotification) final; + void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final; + + void onStartTrackingCb(LocationError error) final; + void onStopTrackingCb(LocationError error) final; + +private: + virtual ~GnssAPIClient(); + + void setCallbacks(); + void initLocationOptions(); + sp mGnssCbIface; + sp mGnssNiCbIface; + std::mutex mMutex; + LocationAPIControlClient* mControlClient; + LocationCapabilitiesMask mLocationCapabilitiesMask; + bool mLocationCapabilitiesCached; + TrackingOptions mTrackingOptions; + bool mTracking; + sp mGnssCbIface_2_0; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GNSS_API_CLINET_H diff --git a/gps/android/2.0/location_api/LocationUtil.cpp b/gps/android/2.0/location_api/LocationUtil.cpp new file mode 100644 index 0000000..961b7b1 --- /dev/null +++ b/gps/android/2.0/location_api/LocationUtil.cpp @@ -0,0 +1,334 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::GnssLocation; +using ::android::hardware::gnss::V2_0::ElapsedRealtimeFlags; +using ::android::hardware::gnss::V2_0::GnssConstellationType; +using ::android::hardware::gnss::V1_0::GnssLocationFlags; + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out) +{ + memset(&out, 0, sizeof(V1_0::GnssLocation)); + if (in.flags & LOCATION_HAS_LAT_LONG_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG; + out.latitudeDegrees = in.latitude; + out.longitudeDegrees = in.longitude; + } + if (in.flags & LOCATION_HAS_ALTITUDE_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE; + out.altitudeMeters = in.altitude; + } + if (in.flags & LOCATION_HAS_SPEED_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED; + out.speedMetersPerSec = in.speed; + } + if (in.flags & LOCATION_HAS_BEARING_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING; + out.bearingDegrees = in.bearing; + } + if (in.flags & LOCATION_HAS_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY; + out.horizontalAccuracyMeters = in.accuracy; + } + if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY; + out.verticalAccuracyMeters = in.verticalAccuracy; + } + if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY; + out.speedAccuracyMetersPerSecond = in.speedAccuracy; + } + if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY; + out.bearingAccuracyDegrees = in.bearingAccuracy; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(Location& in, V2_0::GnssLocation& out) +{ + memset(&out, 0, sizeof(V2_0::GnssLocation)); + convertGnssLocation(in, out.v1_0); + + if (in.flags & LOCATION_HAS_ELAPSED_REAL_TIME) { + out.elapsedRealtime.flags |= ElapsedRealtimeFlags::HAS_TIMESTAMP_NS; + out.elapsedRealtime.timestampNs = in.elapsedRealTime; + out.elapsedRealtime.flags |= ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS; + out.elapsedRealtime.timeUncertaintyNs = in.elapsedRealTimeUnc; + LOC_LOGd("out.elapsedRealtime.timestampNs=%" PRIi64 "" + " out.elapsedRealtime.timeUncertaintyNs=%" PRIi64 "" + " out.elapsedRealtime.flags=0x%X", + out.elapsedRealtime.timestampNs, + out.elapsedRealtime.timeUncertaintyNs, out.elapsedRealtime.flags); + } +} + +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) { + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + out.latitude = in.latitudeDegrees; + out.longitude = in.longitudeDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) { + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + out.altitude = in.altitudeMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) { + out.flags |= LOCATION_HAS_SPEED_BIT; + out.speed = in.speedMetersPerSec; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { + out.flags |= LOCATION_HAS_BEARING_BIT; + out.bearing = in.bearingDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) { + out.flags |= LOCATION_HAS_ACCURACY_BIT; + out.accuracy = in.horizontalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + out.verticalAccuracy = in.verticalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) { + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + out.speedAccuracy = in.speedAccuracyMetersPerSecond; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) { + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.bearingAccuracy = in.bearingAccuracyDegrees; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(const V2_0::GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + convertGnssLocation(in.v1_0, out); +} + +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = V1_0::GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = V1_0::GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = V1_0::GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = V1_0::GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = V1_0::GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = V1_0::GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = V1_0::GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssConstellationType(GnssSvType& in, V2_0::GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = V2_0::GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = V2_0::GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = V2_0::GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = V2_0::GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = V2_0::GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = V2_0::GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_NAVIC: + out = V2_0::GnssConstellationType::IRNSS; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = V2_0::GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssSvid(GnssSv& in, int16_t& out) +{ + switch (in.type) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out) +{ + switch (in.svType) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out) +{ + switch(in) { + case GNSS_EPH_TYPE_EPHEMERIS: + out = GnssDebug::SatelliteEphemerisType::EPHEMERIS; + break; + case GNSS_EPH_TYPE_ALMANAC: + out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY; + break; + case GNSS_EPH_TYPE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE; + break; + } +} + +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out) +{ + switch(in) { + case GNSS_EPH_SOURCE_DEMODULATED: + out = GnssDebug::SatelliteEphemerisSource::DEMODULATED; + break; + case GNSS_EPH_SOURCE_SUPL_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED; + break; + case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED; + break; + case GNSS_EPH_SOURCE_LOCAL: + case GNSS_EPH_SOURCE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisSource::OTHER; + break; + } +} + +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out) +{ + switch(in) { + case GNSS_EPH_HEALTH_GOOD: + out = GnssDebug::SatelliteEphemerisHealth::GOOD; + break; + case GNSS_EPH_HEALTH_BAD: + out = GnssDebug::SatelliteEphemerisHealth::BAD; + break; + case GNSS_EPH_HEALTH_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN; + break; + } +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/location_api/LocationUtil.h b/gps/android/2.0/location_api/LocationUtil.h new file mode 100644 index 0000000..70729e4 --- /dev/null +++ b/gps/android/2.0/location_api/LocationUtil.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOCATION_UTIL_H +#define LOCATION_UTIL_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out); +void convertGnssLocation(Location& in, V2_0::GnssLocation& out); +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out); +void convertGnssLocation(const V2_0::GnssLocation& in, Location& out); +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out); +void convertGnssConstellationType(GnssSvType& in, V2_0::GnssConstellationType& out); +void convertGnssSvid(GnssSv& in, int16_t& out); +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out); +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out); +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out); +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out); + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // LOCATION_UTIL_H diff --git a/gps/android/2.0/location_api/MeasurementAPIClient.cpp b/gps/android/2.0/location_api/MeasurementAPIClient.cpp new file mode 100644 index 0000000..425415f --- /dev/null +++ b/gps/android/2.0/location_api/MeasurementAPIClient.cpp @@ -0,0 +1,507 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_MeasurementAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "MeasurementAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssMeasurement; +using ::android::hardware::gnss::V2_0::IGnssMeasurementCallback; + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + V1_1::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_2_0(GnssMeasurementsNotification& in, + V2_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out); +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out); +static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in, + ::android::hardware::hidl_string& out); +static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in, + ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtimeNanos); + +MeasurementAPIClient::MeasurementAPIClient() : + mGnssMeasurementCbIface(nullptr), + mGnssMeasurementCbIface_1_1(nullptr), + mGnssMeasurementCbIface_2_0(nullptr), + mTracking(false) +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +MeasurementAPIClient::~MeasurementAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +void MeasurementAPIClient::clearInterfaces() +{ + mGnssMeasurementCbIface = nullptr; + mGnssMeasurementCbIface_1_1 = nullptr; + mGnssMeasurementCbIface_2_0 = nullptr; +} + +// for GpsInterface +Return +MeasurementAPIClient::measurementSetCallback(const sp& callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface = callback; + mMutex.unlock(); + + return startTracking(); +} + +Return +MeasurementAPIClient::measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface_1_1 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} + +Return +MeasurementAPIClient::measurementSetCallback_2_0( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface_2_0 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} + +Return +MeasurementAPIClient::startTracking( + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + + locationCallbacks.gnssMeasurementsCb = nullptr; + if (mGnssMeasurementCbIface_2_0 != nullptr || + mGnssMeasurementCbIface_1_1 != nullptr || + mGnssMeasurementCbIface != nullptr) { + locationCallbacks.gnssMeasurementsCb = + [this](GnssMeasurementsNotification gnssMeasurementsNotification) { + onGnssMeasurementsCb(gnssMeasurementsNotification); + }; + } + + locAPISetCallbacks(locationCallbacks); + + TrackingOptions options = {}; + memset(&options, 0, sizeof(TrackingOptions)); + options.size = sizeof(TrackingOptions); + options.minInterval = 1000; + options.mode = GNSS_SUPL_MODE_STANDALONE; + if (GNSS_POWER_MODE_INVALID != powerMode) { + options.powerMode = powerMode; + options.tbm = timeBetweenMeasurement; + } + + mTracking = true; + LOC_LOGD("%s]: start tracking session", __FUNCTION__); + locAPIStartTracking(options); + return IGnssMeasurement::GnssMeasurementStatus::SUCCESS; +} + +// for GpsMeasurementInterface +void MeasurementAPIClient::measurementClose() { + LOC_LOGD("%s]: ()", __FUNCTION__); + mTracking = false; + locAPIStopTracking(); +} + +// callbacks +void MeasurementAPIClient::onGnssMeasurementsCb( + GnssMeasurementsNotification gnssMeasurementsNotification) +{ + LOC_LOGD("%s]: (count: %u active: %d)", + __FUNCTION__, gnssMeasurementsNotification.count, mTracking); + if (mTracking) { + mMutex.lock(); + sp gnssMeasurementCbIface = nullptr; + sp gnssMeasurementCbIface_1_1 = nullptr; + sp gnssMeasurementCbIface_2_0 = nullptr; + if (mGnssMeasurementCbIface_2_0 != nullptr) { + gnssMeasurementCbIface_2_0 = mGnssMeasurementCbIface_2_0; + } else if (mGnssMeasurementCbIface_1_1 != nullptr) { + gnssMeasurementCbIface_1_1 = mGnssMeasurementCbIface_1_1; + } else if (mGnssMeasurementCbIface != nullptr) { + gnssMeasurementCbIface = mGnssMeasurementCbIface; + } + mMutex.unlock(); + + if (gnssMeasurementCbIface_2_0 != nullptr) { + V2_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_2_0(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_2_0->gnssMeasurementCb_2_0(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface_1_1 != nullptr) { + V1_1::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_1_1(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_1_1->gnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface != nullptr) { + V1_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from GnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out) +{ + memset(&out, 0, sizeof(out)); + if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL; + convertGnssSvid(in, out.svid); + convertGnssConstellationType(in.svType, out.constellation); + out.timeOffsetNs = in.timeOffsetNs; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + out.receivedSvTimeInNs = in.receivedSvTimeNs; + out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs; + out.cN0DbHz = in.carrierToNoiseDbHz; + out.pseudorangeRateMps = in.pseudorangeRateMps; + out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + out.accumulatedDeltaRangeM = in.adrMeters; + out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters; + out.carrierFrequencyHz = in.carrierFrequencyHz; + out.carrierCycles = in.carrierCycles; + out.carrierPhase = in.carrierPhase; + out.carrierPhaseUncertainty = in.carrierPhaseUncertainty; + uint8_t indicator = + static_cast(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN); + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT; + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT; + out.multipathIndicator = + static_cast(indicator); + out.snrDb = in.signalToNoiseRatioDb; + out.agcLevelDb = in.agcLevelDb; +} + +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out) +{ + memset(&out, 0, sizeof(out)); + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY; + out.leapSecond = in.leapSecond; + out.timeNs = in.timeNs; + out.timeUncertaintyNs = in.timeUncertaintyNs; + out.fullBiasNs = in.fullBiasNs; + out.biasNs = in.biasNs; + out.biasUncertaintyNs = in.biasUncertaintyNs; + out.driftNsps = in.driftNsps; + out.driftUncertaintyNsps = in.driftUncertaintyNsps; + out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount; +} + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurementCount = in.count; + if (out.measurementCount > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.", + __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT); + out.measurementCount = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.measurementCount; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i]); + } + convertGnssClock(in.clock, out.clock); +} + +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + V1_1::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_0); + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT) + out.measurements[i].accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED; + } + convertGnssClock(in.clock, out.clock); +} + +static void convertGnssData_2_0(GnssMeasurementsNotification& in, + V2_0::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_1.v1_0); + convertGnssConstellationType(in.measurements[i].svType, out.measurements[i].constellation); + convertGnssMeasurementsCodeType(in.measurements[i].codeType, out.measurements[i].codeType); + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.measurements[i].v1_1.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.measurements[i].v1_1.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.measurements[i].v1_1.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + if (in.measurements[i].adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT) + out.measurements[i].v1_1.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_KNOWN; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_KNOWN; + if (in.measurements[i].stateMask & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT) + out.measurements[i].state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_2ND_CODE_LOCK; + } + convertGnssClock(in.clock, out.clock); + convertElapsedRealtimeNanos(in, out.elapsedRealtime); +} + +static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in, + ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtime) +{ + if (in.clock.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT) { + elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS; + elapsedRealtime.timestampNs = in.clock.elapsedRealTime; + elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS; + elapsedRealtime.timeUncertaintyNs = in.clock.elapsedRealTimeUnc; + LOC_LOGd("elapsedRealtime.timestampNs=%" PRIi64 "" + " elapsedRealtime.timeUncertaintyNs=%" PRIi64 " elapsedRealtime.flags=0x%X", + elapsedRealtime.timestampNs, + elapsedRealtime.timeUncertaintyNs, elapsedRealtime.flags); + } +} + +static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& in, + ::android::hardware::hidl_string& out) +{ + switch(in) { + case GNSS_MEASUREMENTS_CODE_TYPE_A: + out = "A"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_B: + out = "B"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_C: + out = "C"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_I: + out = "I"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_L: + out = "L"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_M: + out = "M"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_P: + out = "P"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Q: + out = "Q"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_S: + out = "S"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_W: + out = "W"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_X: + out = "X"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Y: + out = "Y"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Z: + out = "Z"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_N: + out = "N"; + break; + default: + out = "UNKNOWN"; + } +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.0/location_api/MeasurementAPIClient.h b/gps/android/2.0/location_api/MeasurementAPIClient.h new file mode 100644 index 0000000..6c2d38d --- /dev/null +++ b/gps/android/2.0/location_api/MeasurementAPIClient.h @@ -0,0 +1,90 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef MEASUREMENT_API_CLINET_H +#define MEASUREMENT_API_CLINET_H + +#include +#include +//#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::sp; + +class MeasurementAPIClient : public LocationAPIClientBase +{ +public: + MeasurementAPIClient(); + MeasurementAPIClient(const MeasurementAPIClient&) = delete; + MeasurementAPIClient& operator=(const MeasurementAPIClient&) = delete; + + // for GpsMeasurementInterface + Return measurementSetCallback( + const sp& callback); + Return measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + Return measurementSetCallback_2_0( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + void measurementClose(); + Return startTracking( + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + + // callbacks we are interested in + void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final; + +private: + virtual ~MeasurementAPIClient(); + + std::mutex mMutex; + sp mGnssMeasurementCbIface; + sp mGnssMeasurementCbIface_1_1; + sp mGnssMeasurementCbIface_2_0; + bool mTracking; + void clearInterfaces(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // MEASUREMENT_API_CLINET_H diff --git a/gps/android/2.0/service.cpp b/gps/android/2.0/service.cpp new file mode 100644 index 0000000..f7efb18 --- /dev/null +++ b/gps/android/2.0/service.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.gnss@2.0-service-qti" + +#include +#include +#include "loc_cfg.h" +#include "loc_misc_utils.h" + +extern "C" { +#include "vndfwk-detect.h" +} + +#ifdef ARCH_ARM_32 +#define DEFAULT_HW_BINDER_MEM_SIZE 65536 +#endif + +using android::hardware::gnss::V2_0::IGnss; + +using android::hardware::configureRpcThreadpool; +using android::hardware::registerPassthroughServiceImplementation; +using android::hardware::joinRpcThreadpool; + +using android::status_t; +using android::OK; + +typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []); + +int main() { + + ALOGI("%s", __FUNCTION__); + + int vendorInfo = getVendorEnhancedInfo(); + bool vendorEnhanced = ( 1 == vendorInfo || 3 == vendorInfo ); + setVendorEnhanced(vendorEnhanced); + +#ifdef ARCH_ARM_32 + android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE)); +#endif + configureRpcThreadpool(1, true); + status_t status; + + status = registerPassthroughServiceImplementation(); + if (status == OK) { + #ifdef LOC_HIDL_VERSION + #define VENDOR_ENHANCED_LIB "vendor.qti.gnss@" LOC_HIDL_VERSION "-service.so" + + void* libHandle = NULL; + vendorEnhancedServiceMain* vendorEnhancedMainMethod = (vendorEnhancedServiceMain*) + dlGetSymFromLib(libHandle, VENDOR_ENHANCED_LIB, "main"); + if (NULL != vendorEnhancedMainMethod) { + (*vendorEnhancedMainMethod)(0, NULL); + } + #else + ALOGI("LOC_HIDL_VERSION not defined."); + #endif + joinRpcThreadpool(); + } else { + ALOGE("Error while registering IGnss 2.0 service: %d", status); + } + + return 0; +} diff --git a/gps/android/2.1/AGnss.cpp b/gps/android/2.1/AGnss.cpp new file mode 100644 index 0000000..c759492 --- /dev/null +++ b/gps/android/2.1/AGnss.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_AGnssInterface" + +#include +#include "Gnss.h" +#include "AGnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +static AGnss* spAGnss = nullptr; + +AGnss::AGnss(Gnss* gnss) : mGnss(gnss) { + spAGnss = this; +} + +AGnss::~AGnss() { + spAGnss = nullptr; +} + +void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status) { + if (nullptr != spAGnss) { + spAGnss->statusCb(status.type, status.status); + } +} + +void AGnss::statusCb(AGpsExtType type, LocAGpsStatusValue status) { + + V2_0::IAGnssCallback::AGnssType aType; + IAGnssCallback::AGnssStatusValue aStatus; + + switch (type) { + case LOC_AGPS_TYPE_SUPL: + aType = IAGnssCallback::AGnssType::SUPL; + break; + case LOC_AGPS_TYPE_SUPL_ES: + aType = IAGnssCallback::AGnssType::SUPL_EIMS; + break; + default: + LOC_LOGE("invalid type: %d", type); + return; + } + + switch (status) { + case LOC_GPS_REQUEST_AGPS_DATA_CONN: + aStatus = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN; + break; + case LOC_GPS_RELEASE_AGPS_DATA_CONN: + aStatus = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN; + break; + case LOC_GPS_AGPS_DATA_CONNECTED: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED; + break; + case LOC_GPS_AGPS_DATA_CONN_DONE: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE; + break; + case LOC_GPS_AGPS_DATA_CONN_FAILED: + aStatus = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED; + break; + default: + LOC_LOGE("invalid status: %d", status); + return; + } + + if (mAGnssCbIface != nullptr) { + auto r = mAGnssCbIface->agnssStatusCb(aType, aStatus); + if (!r.isOk()) { + LOC_LOGw("Error invoking AGNSS status cb %s", r.description().c_str()); + } + } + else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +Return AGnss::setCallback(const sp& callback) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return Void(); + } + + // Save the interface + mAGnssCbIface = callback; + + AgpsCbInfo cbInfo = {}; + cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + cbInfo.atlType = AGPS_ATL_TYPE_SUPL | AGPS_ATL_TYPE_SUPL_ES; + + mGnss->getGnssInterface()->agpsInit(cbInfo); + return Void(); +} + +Return AGnss::dataConnClosed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnFailed() { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL); + return true; +} + +Return AGnss::dataConnOpen(uint64_t /*networkHandle*/, const hidl_string& apn, + V2_0::IAGnss::ApnIpType apnIpType) { + + if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){ + LOC_LOGE("Null GNSS interface"); + return false; + } + + /* Validate */ + if(apn.empty()){ + LOC_LOGE("Invalid APN"); + return false; + } + + LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str()); + + AGpsBearerType bearerType; + switch (apnIpType) { + case IAGnss::ApnIpType::IPV4: + bearerType = AGPS_APN_BEARER_IPV4; + break; + case IAGnss::ApnIpType::IPV6: + bearerType = AGPS_APN_BEARER_IPV6; + break; + case IAGnss::ApnIpType::IPV4V6: + bearerType = AGPS_APN_BEARER_IPV4V6; + break; + default: + bearerType = AGPS_APN_BEARER_IPV4; + break; + } + + mGnss->getGnssInterface()->agpsDataConnOpen( + LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType); + return true; +} + +Return AGnss::setServer(V2_0::IAGnssCallback::AGnssType type, + const hidl_string& hostname, + int32_t port) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + if (type == IAGnssCallback::AGnssType::SUPL) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL; + } else if (type == IAGnssCallback::AGnssType::C2K) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K; + } else if (type == IAGnssCallback::AGnssType::SUPL_EIMS) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_EIMS; + } else if (type == IAGnssCallback::AGnssType::SUPL_IMS) { + config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL_IMS; + } else { + LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast(type)); + return false; + } + config.assistanceServer.hostName = strdup(hostname.c_str()); + config.assistanceServer.port = port; + return mGnss->updateConfiguration(config); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/AGnss.h b/gps/android/2.1/AGnss.h new file mode 100644 index 0000000..f6ea997 --- /dev/null +++ b/gps/android/2.1/AGnss.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H +#define ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; +using ::android::hardware::gnss::V2_0::IAGnssCallback; + +struct Gnss; +struct AGnss : public V2_0::IAGnss { + + AGnss(Gnss* gnss); + ~AGnss(); + /* + * Methods from ::android::hardware::gnss::V2_0::IAGnss interface follow. + * These declarations were generated from IAGnss.hal. + */ + Return setCallback(const sp& callback) override; + + Return dataConnClosed() override; + + Return dataConnFailed() override; + + Return dataConnOpen(uint64_t networkHandle, const hidl_string& apn, + V2_0::IAGnss::ApnIpType apnIpType) override; + + Return setServer(V2_0::IAGnssCallback::AGnssType type, + const hidl_string& hostname, int32_t port) override; + + void statusCb(AGpsExtType type, LocAGpsStatusValue status); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status); + + private: + Gnss* mGnss = nullptr; + sp mAGnssCbIface = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_AGNSS_H diff --git a/gps/android/2.1/AGnssRil.cpp b/gps/android/2.1/AGnssRil.cpp new file mode 100644 index 0000000..f413e93 --- /dev/null +++ b/gps/android/2.1/AGnssRil.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc__AGnssRilInterface" + +#include +#include +#include +#include +#include +#include +#include +#include "Gnss.h" +#include "AGnssRil.h" +#include + +typedef void* (getLocationInterface)(); + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + + +AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) { + ENTRY_LOG_CALLFLOW(); +} + +AGnssRil::~AGnssRil() { + ENTRY_LOG_CALLFLOW(); +} + +Return AGnssRil::updateNetworkState(bool connected, NetworkType type, bool /*roaming*/) { + ENTRY_LOG_CALLFLOW(); + // Extra NetworkTypes not available in IAgnssRil enums + const int NetworkType_BLUETOOTH = 7; + const int NetworkType_ETHERNET = 9; + const int NetworkType_PROXY = 16; + std::string apn(""); + + // for XTRA + if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) { + int8_t typeout = loc_core::TYPE_UNKNOWN; + switch(type) + { + case IAGnssRil::NetworkType::MOBILE: + typeout = loc_core::TYPE_MOBILE; + break; + case IAGnssRil::NetworkType::WIFI: + typeout = loc_core::TYPE_WIFI; + break; + case IAGnssRil::NetworkType::MMS: + typeout = loc_core::TYPE_MMS; + break; + case IAGnssRil::NetworkType::SUPL: + typeout = loc_core::TYPE_SUPL; + break; + case IAGnssRil::NetworkType::DUN: + typeout = loc_core::TYPE_DUN; + break; + case IAGnssRil::NetworkType::HIPRI: + typeout = loc_core::TYPE_HIPRI; + break; + case IAGnssRil::NetworkType::WIMAX: + typeout = loc_core::TYPE_WIMAX; + break; + default: + { + int networkType = (int) type; + // Handling network types not available in IAgnssRil + switch(networkType) + { + case NetworkType_BLUETOOTH: + typeout = loc_core::TYPE_BLUETOOTH; + break; + case NetworkType_ETHERNET: + typeout = loc_core::TYPE_ETHERNET; + break; + case NetworkType_PROXY: + typeout = loc_core::TYPE_PROXY; + break; + default: + typeout = loc_core::TYPE_UNKNOWN; + } + } + break; + } + mGnss->getGnssInterface()->updateConnectionStatus(connected, typeout, false, 0, apn); + } + return true; +} +Return AGnssRil::updateNetworkState_2_0(const V2_0::IAGnssRil::NetworkAttributes& attributes) { + ENTRY_LOG_CALLFLOW(); + std::string apn = attributes.apn; + if (nullptr != mGnss && (nullptr != mGnss->getGnssInterface())) { + int8_t typeout = loc_core::TYPE_UNKNOWN; + bool roaming = false; + if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_METERED) { + typeout = loc_core::TYPE_WIFI; + } else { + typeout = loc_core::TYPE_MOBILE; + } + if (attributes.capabilities & IAGnssRil::NetworkCapability::NOT_ROAMING) { + roaming = false; + } + LOC_LOGd("apn string received is: %s", apn.c_str()); + mGnss->getGnssInterface()->updateConnectionStatus(attributes.isConnected, + typeout, roaming, (NetworkHandle) attributes.networkHandle, apn); + } + return true; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/AGnssRil.h b/gps/android/2.1/AGnssRil.h new file mode 100644 index 0000000..2bf6156 --- /dev/null +++ b/gps/android/2.1/AGnssRil.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ +#define ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +/* + * Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface + * allows the GNSS chipset to request radio interface layer information from Android platform. + * Examples of such information are reference location, unique subscriber ID, phone number string + * and network availability changes. Also contains wrapper methods to allow methods from + * IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL. + */ +struct AGnssRil : public V2_0::IAGnssRil { + AGnssRil(Gnss* gnss); + ~AGnssRil(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow. + * These declarations were generated from IAGnssRil.hal. + */ + Return setCallback(const sp& /*callback*/) override { + return Void(); + } + Return setRefLocation(const V1_0::IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override { + return Void(); + } + Return setSetId(V1_0::IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override { + return false; + } + Return updateNetworkAvailability(bool /*available*/, + const hidl_string& /*apn*/) override { + return false; + } + Return updateNetworkState(bool connected, V1_0::IAGnssRil::NetworkType type, bool roaming) override; + + // Methods from ::android::hardware::gnss::V2_0::IAGnssRil follow + Return updateNetworkState_2_0(const V2_0::IAGnssRil::NetworkAttributes& attributes) override; + + private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H_ diff --git a/gps/android/2.1/Android.mk b/gps/android/2.1/Android.mk new file mode 100644 index 0000000..a947e41 --- /dev/null +++ b/gps/android/2.1/Android.mk @@ -0,0 +1,116 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@2.1-impl-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + AGnss.cpp \ + Gnss.cpp \ + AGnssRil.cpp \ + GnssMeasurement.cpp \ + GnssConfiguration.cpp \ + GnssBatching.cpp \ + GnssGeofencing.cpp \ + GnssNi.cpp \ + GnssDebug.cpp \ + GnssAntennaInfo.cpp \ + MeasurementCorrections.cpp \ + GnssVisibilityControl.cpp + +LOCAL_SRC_FILES += \ + location_api/GnssAPIClient.cpp \ + location_api/MeasurementAPIClient.cpp \ + location_api/GeofenceAPIClient.cpp \ + location_api/BatchingAPIClient.cpp \ + location_api/LocationUtil.cpp \ + +ifeq ($(GNSS_HIDL_LEGACY_MEASURMENTS),true) +LOCAL_CFLAGS += \ + -DGNSS_HIDL_LEGACY_MEASURMENTS +endif + +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/location_api + +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers \ + liblocbatterylistener_headers + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libhidlbase \ + libcutils \ + libutils \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + android.hardware.gnss@2.0 \ + android.hardware.gnss@2.1 \ + android.hardware.gnss.measurement_corrections@1.0 \ + android.hardware.gnss.measurement_corrections@1.1 \ + android.hardware.gnss.visibility_control@1.0 \ + android.hardware.health@1.0 \ + android.hardware.health@2.0 \ + android.hardware.health@2.1 \ + android.hardware.power@1.2 \ + libbase + +LOCAL_SHARED_LIBRARIES += \ + libloc_core \ + libgps.utils \ + libdl \ + liblocation_api \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) +LOCAL_STATIC_LIBRARIES := liblocbatterylistener +LOCAL_STATIC_LIBRARIES += libhealthhalutils +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.gnss@2.1-service-qti +LOCAL_SANITIZE += $(GNSS_SANITIZE) +# activate the following line for debug purposes only, comment out for production +#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG) +LOCAL_VINTF_FRAGMENTS := android.hardware.gnss@2.1-service-qti.xml +LOCAL_VENDOR_MODULE := true +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_INIT_RC := android.hardware.gnss@2.1-service-qti.rc +LOCAL_SRC_FILES := \ + service.cpp \ + +LOCAL_HEADER_LIBRARIES := \ + libgps.utils_headers \ + libloc_core_headers \ + libloc_pla_headers \ + liblocation_api_headers + + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libcutils \ + libdl \ + libbase \ + libutils \ + libgps.utils \ + libqti_vndfwk_detect \ + +LOCAL_SHARED_LIBRARIES += \ + libhidlbase \ + android.hardware.gnss@1.0 \ + android.hardware.gnss@1.1 \ + android.hardware.gnss@2.0 \ + android.hardware.gnss@2.1 \ + +LOCAL_CFLAGS += $(GNSS_CFLAGS) + +ifneq ($(LOC_HIDL_VERSION),) +LOCAL_CFLAGS += -DLOC_HIDL_VERSION='"$(LOC_HIDL_VERSION)"' +endif + +include $(BUILD_EXECUTABLE) diff --git a/gps/android/2.1/Gnss.cpp b/gps/android/2.1/Gnss.cpp new file mode 100644 index 0000000..37e1cc5 --- /dev/null +++ b/gps/android/2.1/Gnss.cpp @@ -0,0 +1,800 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssInterface" +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include "Gnss.h" +#include "LocationUtil.h" +#include "battery_listener.h" +#include "loc_misc_utils.h" + +typedef const GnssInterface* (getLocationInterface)(); + +#define IMAGES_INFO_FILE "/sys/devices/soc0/images" +#define DELIMITER ";" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::visibility_control::V1_0::implementation::GnssVisibilityControl; +using ::android::hardware::gnss::measurement_corrections::V1_1:: + implementation::MeasurementCorrections; +static sp sGnss; +static std::string getVersionString() { + static std::string version; + if (!version.empty()) + return version; + + char value[PROPERTY_VALUE_MAX] = {0}; + property_get("ro.hardware", value, "unknown"); + version.append(value).append(DELIMITER); + + std::ifstream in(IMAGES_INFO_FILE); + std::string s; + while(getline(in, s)) { + std::size_t found = s.find("CRM:"); + if (std::string::npos == found) { + continue; + } + + // skip over space characters after "CRM:" + const char* substr = s.c_str(); + found += 4; + while (0 != substr[found] && isspace(substr[found])) { + found++; + } + if (s.find("11:") != found) { + continue; + } + s.erase(0, found + 3); + + found = s.find_first_of("\r\n"); + if (std::string::npos != found) { + s.erase(s.begin() + found, s.end()); + } + version.append(s).append(DELIMITER); + } + return version; +} + +void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnss != nullptr) { + mGnss->getGnssInterface()->resetNetworkInfo(); + mGnss->cleanup(); + } +} + +void location_on_battery_status_changed(bool charging) { + LOC_LOGd("battery status changed to %s charging", charging ? "" : "not"); + if (sGnss != nullptr) { + sGnss->getGnssInterface()->updateBatteryStatus(charging); + } +} +Gnss::Gnss() { + ENTRY_LOG_CALLFLOW(); + sGnss = this; + // initilize gnss interface at first in case needing notify battery status + sGnss->getGnssInterface()->initialize(); + // register health client to listen on battery change + loc_extn_battery_properties_listener_init(location_on_battery_status_changed); + // clear pending GnssConfig + memset(&mPendingConfig, 0, sizeof(GnssConfig)); + mGnssDeathRecipient = new GnssDeathRecipient(this); +} + +Gnss::~Gnss() { + ENTRY_LOG_CALLFLOW(); + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } + sGnss = nullptr; +} + +GnssAPIClient* Gnss::getApi() { + if (mApi != nullptr) { + return mApi; + } + + if (mGnssCbIface_2_1 != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface_2_1); + } else if (mGnssCbIface_2_0 != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface_2_0); + } else if (mGnssCbIface_1_1 != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface_1_1, mGnssNiCbIface); + } else if (mGnssCbIface != nullptr) { + mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface); + } else { + LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__); + return mApi; + } + + if (mPendingConfig.size == sizeof(GnssConfig)) { + // we have pending GnssConfig + mApi->gnssConfigurationUpdate(mPendingConfig); + // clear size to invalid mPendingConfig + mPendingConfig.size = 0; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + } + } + + return mApi; +} + +const GnssInterface* Gnss::getGnssInterface() { + static bool getGnssInterfaceFailed = false; + if (mGnssInterface == nullptr && !getGnssInterfaceFailed) { + void * libHandle = nullptr; + getLocationInterface* getter = (getLocationInterface*) + dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface"); + if (NULL == getter) { + getGnssInterfaceFailed = true; + } else { + mGnssInterface = (GnssInterface*)(*getter)(); + } + } + return mGnssInterface; +} + +Return Gnss::setCallback(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + + // In case where previous call to setCallback_1_1/setCallback_2_0/setCallback_2_1, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks_2_0(nullptr); + mApi->gnssUpdateCallbacks_2_1(nullptr); + } + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_1_1 = nullptr; + } + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_0 = nullptr; + } + if (mGnssCbIface_2_1 != nullptr) { + mGnssCbIface_2_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_1 = nullptr; + } + + + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface = callback; + if (mGnssCbIface != nullptr) { + mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + return true; +} + +Return Gnss::setGnssNiCb(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + mGnssNiCbIface = callback; + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface); + } + return true; +} + +Return Gnss::updateConfiguration(GnssConfig& gnssConfig) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssConfigurationUpdate(gnssConfig); + } else if (gnssConfig.flags != 0) { + // api is not ready yet, update mPendingConfig with gnssConfig + mPendingConfig.size = sizeof(GnssConfig); + + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + mPendingConfig.gpsLock = gnssConfig.gpsLock; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + mPendingConfig.suplVersion = gnssConfig.suplVersion; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT; + mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer); + mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type; + if (mPendingConfig.assistanceServer.hostName != nullptr) { + free((void*)mPendingConfig.assistanceServer.hostName); + mPendingConfig.assistanceServer.hostName = + strdup(gnssConfig.assistanceServer.hostName); + } + mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT; + mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT; + mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT; + mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + mPendingConfig.suplModeMask = gnssConfig.suplModeMask; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds; + } + if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) { + mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT; + mPendingConfig.emergencyExtensionSeconds = gnssConfig.emergencyExtensionSeconds; + } + } + return true; +} + +Return Gnss::start() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStart(); + } + return retVal; +} + +Return Gnss::stop() { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssStop(); + } + return retVal; +} + +Return Gnss::cleanup() { + ENTRY_LOG_CALLFLOW(); + + if (mApi != nullptr) { + mApi->gnssStop(); + mApi->gnssDisable(); + } + + return Void(); +} + +Return Gnss::injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters); + return true; + } else { + return false; + } +} + +Return Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs, + int32_t uncertaintyMs) { + return true; +} + +Return Gnss::deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) { + ENTRY_LOG_CALLFLOW(); + GnssAPIClient* api = getApi(); + if (api) { + api->gnssDeleteAidingData(aidingDataFlags); + } + return Void(); +} + +Return Gnss::setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs); + } + return retVal; +} + +Return> Gnss::getExtensionAGnss() { + ENTRY_LOG_CALLFLOW(); + // deprecated function. Must return nullptr to pass VTS + return nullptr; +} + +Return> Gnss::getExtensionGnssNi() { + ENTRY_LOG_CALLFLOW(); + // deprecated function. Must return nullptr to pass VTS + return nullptr; +} + +Return> Gnss::getExtensionGnssMeasurement() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) { + mGnssMeasurement = new GnssMeasurement(); + } + return mGnssMeasurement; +} + +Return> Gnss::getExtensionGnssConfiguration() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) { + mGnssConfig = new GnssConfiguration(this); + } + return mGnssConfig; +} + +Return> Gnss::getExtensionGnssGeofencing() { + ENTRY_LOG_CALLFLOW(); + if (mGnssGeofencingIface == nullptr) { + mGnssGeofencingIface = new GnssGeofencing(); + } + return mGnssGeofencingIface; +} + +Return> Gnss::getExtensionGnssBatching() { + ENTRY_LOG_CALLFLOW(); + if (mGnssBatching == nullptr) { + mGnssBatching = new GnssBatching(); + } + return mGnssBatching; +} + +Return> Gnss::getExtensionGnssDebug() { + ENTRY_LOG_CALLFLOW(); + if (mGnssDebug == nullptr) { + mGnssDebug = new GnssDebug(this); + } + return mGnssDebug; +} + +Return> Gnss::getExtensionAGnssRil() { + ENTRY_LOG_CALLFLOW(); + if (mGnssRil == nullptr) { + mGnssRil = new AGnssRil(this); + } + return mGnssRil; +} + +// Methods from ::android::hardware::gnss::V1_1::IGnss follow. +Return Gnss::setCallback_1_1(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + auto r = callback->gnssNameCb(getVersionString()); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNameCb description=%s", + __func__, r.description().c_str()); + } + + // In case where previous call to setCallback/setCallback_2_0/setCallback_2_1, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks_2_0(nullptr); + mApi->gnssUpdateCallbacks_2_1(nullptr); + } + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface = nullptr; + } + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_0 = nullptr; + } + if (mGnssCbIface_2_1 != nullptr) { + mGnssCbIface_2_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_1 = nullptr; + } + + + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface_1_1 = callback; + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks(mGnssCbIface_1_1, mGnssNiCbIface); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + + return true; +} + +Return Gnss::setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + bool lowPowerMode) { + ENTRY_LOG_CALLFLOW(); + bool retVal = false; + GnssAPIClient* api = getApi(); + if (api) { + GnssPowerMode powerMode = lowPowerMode? + GNSS_POWER_MODE_M4 : GNSS_POWER_MODE_M2; + retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs, + preferredAccuracyMeters, preferredTimeMs, powerMode, minIntervalMs); + } + return retVal; +} + +Return> Gnss::getExtensionGnssMeasurement_1_1() { + ENTRY_LOG_CALLFLOW(); +#ifdef GNSS_HIDL_LEGACY_MEASURMENTS + return nullptr; +#else + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +#endif +} + +Return> Gnss::getExtensionGnssConfiguration_1_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) + mGnssConfig = new GnssConfiguration(this); + return mGnssConfig; +} + +Return Gnss::injectBestLocation(const GnssLocation& gnssLocation) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } + return true; +} + +void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) { + ENTRY_LOG_CALLFLOW(); + if (ODCPI_REQUEST_TYPE_STOP == request.type) { + return; + } + if (mGnssCbIface_2_1 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + LOC_LOGd("gnssRequestLocationCb_2_1 isUserEmergency = %d", request.isEmergencyMode); + auto r = mGnssCbIface_2_1->gnssRequestLocationCb_2_0(!request.isEmergencyMode, + request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb_2_0 %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else if (mGnssCbIface_2_0 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + LOC_LOGd("gnssRequestLocationCb_2_0 isUserEmergency = %d", request.isEmergencyMode); + auto r = mGnssCbIface_2_0->gnssRequestLocationCb_2_0(!request.isEmergencyMode, + request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb_2_0 %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else if (mGnssCbIface_1_1 != nullptr) { + // For emergency mode, request DBH (Device based hybrid) location + // Mark Independent from GNSS flag to false. + if (ODCPI_REQUEST_TYPE_START == request.type) { + auto r = mGnssCbIface_1_1->gnssRequestLocationCb(!request.isEmergencyMode); + if (!r.isOk()) { + LOC_LOGe("Error invoking gnssRequestLocationCb %s", r.description().c_str()); + } + } else { + LOC_LOGv("Unsupported ODCPI request type: %d", request.type); + } + } else { + LOC_LOGe("ODCPI request not supported."); + } +} + +// Methods from ::android::hardware::gnss::V2_0::IGnss follow. +Return Gnss::setCallback_2_0(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + auto r = callback->gnssNameCb(getVersionString()); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNameCb description=%s", + __func__, r.description().c_str()); + } + + // In case where previous call to setCallback/setCallback_1_1/setCallback_2_1, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks(nullptr, nullptr); + mApi->gnssUpdateCallbacks_2_1(nullptr); + } + mGnssNiCbIface = nullptr; + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface = nullptr; + } + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_1_1 = nullptr; + } + if (mGnssCbIface_2_1 != nullptr) { + mGnssCbIface_2_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_1 = nullptr; + } + + + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface_2_0 = callback; + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks_2_0(mGnssCbIface_2_0); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + + return true; +} + +Return> Gnss::getExtensionAGnss_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mAGnssIface_2_0 == nullptr) { + mAGnssIface_2_0 = new AGnss(this); + } + return mAGnssIface_2_0; +} +Return> Gnss::getExtensionAGnssRil_2_0() { + + if (mGnssRil == nullptr) { + mGnssRil = new AGnssRil(this); + } + return mGnssRil; +} + +Return> Gnss::getExtensionGnssConfiguration_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) { + mGnssConfig = new GnssConfiguration(this); + } + return mGnssConfig; +} +Return> Gnss::getExtensionGnssMeasurement_2_0() { + ENTRY_LOG_CALLFLOW(); +#ifdef GNSS_HIDL_LEGACY_MEASURMENTS + return nullptr; +#else + if (mGnssMeasurement == nullptr) + mGnssMeasurement = new GnssMeasurement(); + return mGnssMeasurement; +#endif +} + +Return> + Gnss::getExtensionMeasurementCorrections() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasCorr == nullptr) { + mGnssMeasCorr = new MeasurementCorrections(this); + } + return mGnssMeasCorr; +} + +Return> + Gnss::getExtensionMeasurementCorrections_1_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasCorr == nullptr) { + mGnssMeasCorr = new MeasurementCorrections(this); + } + return mGnssMeasCorr; +} + +Return> + Gnss::getExtensionVisibilityControl() { + ENTRY_LOG_CALLFLOW(); + if (mVisibCtrl == nullptr) { + mVisibCtrl = new GnssVisibilityControl(this); + } + return mVisibCtrl; +} + +Return Gnss::injectBestLocation_2_0(const V2_0::GnssLocation& gnssLocation) { + ENTRY_LOG_CALLFLOW(); + const GnssInterface* gnssInterface = getGnssInterface(); + if (nullptr != gnssInterface) { + Location location = {}; + convertGnssLocation(gnssLocation, location); + gnssInterface->odcpiInject(location); + } + return true; +} + +Return> Gnss::getExtensionGnssDebug_2_0() { + ENTRY_LOG_CALLFLOW(); + if (mGnssDebug == nullptr) { + mGnssDebug = new GnssDebug(this); + } + return mGnssDebug; +} + +Return> Gnss::getExtensionGnssBatching_2_0() { + return nullptr; +} + +// Methods from ::android::hardware::gnss::V2_1::IGnss follow. +Return Gnss::setCallback_2_1(const sp& callback) { + ENTRY_LOG_CALLFLOW(); + auto r = callback->gnssNameCb(getVersionString()); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNameCb description=%s", + __func__, r.description().c_str()); + } + + // In case where previous call to setCallback/setCallback_1_1/setCallback_2_0, then + // we need to cleanup these interfaces/callbacks here since we no longer + // do so in cleanup() function to keep callbacks around after cleanup() + if (mApi != nullptr) { + mApi->gnssUpdateCallbacks(nullptr, nullptr); + mApi->gnssUpdateCallbacks_2_0(nullptr); + } + mGnssNiCbIface = nullptr; + if (mGnssCbIface != nullptr) { + mGnssCbIface->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface = nullptr; + } + if (mGnssCbIface_1_1 != nullptr) { + mGnssCbIface_1_1->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_1_1 = nullptr; + } + if (mGnssCbIface_2_0 != nullptr) { + mGnssCbIface_2_0->unlinkToDeath(mGnssDeathRecipient); + mGnssCbIface_2_0 = nullptr; + } + if (mGnssCbIface_2_1 != nullptr) { + mGnssCbIface_2_1->unlinkToDeath(mGnssDeathRecipient); + } + mGnssCbIface_2_1 = callback; + if (mGnssCbIface_2_1 != nullptr) { + mGnssCbIface_2_1->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/); + } + + const GnssInterface* gnssInterface = getGnssInterface(); + if (gnssInterface != nullptr) { + OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) { + odcpiRequestCb(odcpiRequest); + }; + gnssInterface->odcpiInit(cb, OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW); + } + + GnssAPIClient* api = getApi(); + if (api != nullptr) { + api->gnssUpdateCallbacks_2_1(mGnssCbIface_2_1); + api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS); + api->requestCapabilities(); + } + + return true; +} +Return> Gnss::getExtensionGnssMeasurement_2_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssMeasurement == nullptr) { + mGnssMeasurement = new GnssMeasurement(); + } + return mGnssMeasurement; +} +Return> Gnss::getExtensionGnssConfiguration_2_1() { + ENTRY_LOG_CALLFLOW(); + if (mGnssConfig == nullptr) { + mGnssConfig = new GnssConfiguration(this); + } + return mGnssConfig; +} + +Return> Gnss::getExtensionGnssAntennaInfo() { + ENTRY_LOG_CALLFLOW(); + if (mGnssAntennaInfo == nullptr) { + mGnssAntennaInfo = new GnssAntennaInfo(this); + } + return mGnssAntennaInfo; +} + +V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) { + ENTRY_LOG_CALLFLOW(); + V1_0::IGnss* iface = nullptr; + iface = new Gnss(); + if (iface == nullptr) { + LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal); + } + return iface; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/Gnss.h b/gps/android/2.1/Gnss.h new file mode 100644 index 0000000..c383882 --- /dev/null +++ b/gps/android/2.1/Gnss.h @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSS_H +#define ANDROID_HARDWARE_GNSS_V2_1_GNSS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "GnssAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; +using IMeasurementCorrectionsV1_0 = + ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections; +using IMeasurementCorrectionsV1_1 = + ::android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections; +using ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl; + +struct Gnss : public IGnss { + Gnss(); + ~Gnss(); + + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnss follow. + * These declarations were generated from Gnss.hal. + */ + Return setCallback(const sp& callback) override; + Return start() override; + Return stop() override; + Return cleanup() override; + Return injectLocation(double latitudeDegrees, + double longitudeDegrees, + float accuracyMeters) override; + Return injectTime(int64_t timeMs, + int64_t timeReferenceMs, + int32_t uncertaintyMs) override; + Return deleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags) override; + Return setPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs) override; + Return> getExtensionAGnss() override; + Return> getExtensionGnssNi() override; + Return> getExtensionGnssMeasurement() override; + Return> getExtensionGnssConfiguration() override; + Return> getExtensionGnssGeofencing() override; + Return> getExtensionGnssBatching() override; + + Return> getExtensionAGnssRil() override; + + inline Return> getExtensionGnssNavigationMessage() override { + return nullptr; + } + + inline Return> getExtensionXtra() override { + return nullptr; + } + + Return> getExtensionGnssDebug() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnss follow. + Return setCallback_1_1(const sp& callback) override; + Return setPositionMode_1_1(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, bool lowPowerMode) override; + Return> getExtensionGnssMeasurement_1_1() override; + Return> getExtensionGnssConfiguration_1_1() override; + Return injectBestLocation(const GnssLocation& location) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnss follow. + Return setCallback_2_0(const sp& callback) override; + Return> getExtensionAGnss_2_0() override; + Return> getExtensionAGnssRil_2_0() override; + + Return> getExtensionGnssConfiguration_2_0() override; + Return> getExtensionMeasurementCorrections() override; + Return> getExtensionMeasurementCorrections_1_1() override; + Return> getExtensionGnssMeasurement_2_0() override; + + Return injectBestLocation_2_0( + const ::android::hardware::gnss::V2_0::GnssLocation& location) override; + + Return> getExtensionGnssBatching_2_0() override; + Return> getExtensionGnssDebug_2_0() override; + Return> + getExtensionVisibilityControl() override; + + // Methods from ::android::hardware::gnss::V2_1::IGnss follow. + Return setCallback_2_1(const sp& callback) override; + Return> getExtensionGnssMeasurement_2_1() override; + Return> getExtensionGnssConfiguration_2_1() override; + Return> getExtensionGnssAntennaInfo() override; + + // These methods are not part of the IGnss base class. + GnssAPIClient* getApi(); + Return setGnssNiCb(const sp& niCb); + Return updateConfiguration(GnssConfig& gnssConfig); + const GnssInterface* getGnssInterface(); + + // Callback for ODCPI request + void odcpiRequestCb(const OdcpiRequestInfo& request); + + private: + struct GnssDeathRecipient : hidl_death_recipient { + GnssDeathRecipient(sp gnss) : mGnss(gnss) { + } + ~GnssDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnss; + }; + + private: + sp mGnssDeathRecipient = nullptr; + + sp mGnssNi = nullptr; + sp mGnssGeofencingIface = nullptr; + sp mAGnssIface = nullptr; + sp mGnssCbIface = nullptr; + sp mGnssNiCbIface = nullptr; + sp mGnssCbIface_1_1 = nullptr; + sp mAGnssIface_2_0 = nullptr; + sp mGnssRil = nullptr; + sp mGnssBatching = nullptr; + sp mGnssDebug = nullptr; + sp mGnssCbIface_2_0 = nullptr; + sp mGnssCbIface_2_1 = nullptr; + sp mGnssMeasurement = nullptr; + sp mGnssConfig = nullptr; + sp mGnssAntennaInfo = nullptr; + sp mGnssMeasCorr = nullptr; + sp mVisibCtrl = nullptr; + + GnssAPIClient* mApi = nullptr; + GnssConfig mPendingConfig; + const GnssInterface* mGnssInterface = nullptr; +}; + +extern "C" V1_0::IGnss* HIDL_FETCH_IGnss(const char* name); + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSS_H diff --git a/gps/android/2.1/GnssAntennaInfo.cpp b/gps/android/2.1/GnssAntennaInfo.cpp new file mode 100644 index 0000000..62c4cc7 --- /dev/null +++ b/gps/android/2.1/GnssAntennaInfo.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#define LOG_TAG "LocSvc_GnssAntennaInfoInterface" + +#include +#include "Gnss.h" +#include "GnssAntennaInfo.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +static GnssAntennaInfo* spGnssAntennaInfo = nullptr; + +static void convertGnssAntennaInfo(std::vector& in, + hidl_vec& antennaInfos); + +void GnssAntennaInfo::GnssAntennaInfoDeathRecipient::serviceDied(uint64_t cookie, + const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + // we do nothing here + // Gnss::GnssDeathRecipient will stop the session + // However, we need to inform the adapter that the service has died + if (nullptr == spGnssAntennaInfo) { + LOC_LOGE("%s]: spGnssAntennaInfo is nullptr", __FUNCTION__); + return; + } + if (nullptr == spGnssAntennaInfo->mGnss) { + LOC_LOGE("%s]: spGnssAntennaInfo->mGnss is nullptr", __FUNCTION__); + return; + } + + spGnssAntennaInfo->mGnss->getGnssInterface()->antennaInfoClose(); +} + +static void convertGnssAntennaInfo(std::vector& in, + hidl_vec& out) { + + uint32_t vecSize, numberOfRows, numberOfColumns; + vecSize = in.size(); + out.resize(vecSize); + for (uint32_t i = 0; i < vecSize; i++) { + out[i].carrierFrequencyMHz = in[i].carrierFrequencyMHz; + out[i].phaseCenterOffsetCoordinateMillimeters.x = + in[i].phaseCenterOffsetCoordinateMillimeters.x; + out[i].phaseCenterOffsetCoordinateMillimeters.xUncertainty = + in[i].phaseCenterOffsetCoordinateMillimeters.xUncertainty; + out[i].phaseCenterOffsetCoordinateMillimeters.y = + in[i].phaseCenterOffsetCoordinateMillimeters.y; + out[i].phaseCenterOffsetCoordinateMillimeters.yUncertainty = + in[i].phaseCenterOffsetCoordinateMillimeters.yUncertainty; + out[i].phaseCenterOffsetCoordinateMillimeters.z = + in[i].phaseCenterOffsetCoordinateMillimeters.z; + out[i].phaseCenterOffsetCoordinateMillimeters.zUncertainty = + in[i].phaseCenterOffsetCoordinateMillimeters.zUncertainty; + + numberOfRows = in[i].phaseCenterVariationCorrectionMillimeters.size(); + out[i].phaseCenterVariationCorrectionMillimeters.resize(numberOfRows); + for (uint32_t j = 0; j < numberOfRows; j++) { + numberOfColumns = in[i].phaseCenterVariationCorrectionMillimeters[j].size(); + out[i].phaseCenterVariationCorrectionMillimeters[j].row.resize(numberOfColumns); + for (uint32_t k = 0; k < numberOfColumns; k++) { + out[i].phaseCenterVariationCorrectionMillimeters[j].row[k] = + in[i].phaseCenterVariationCorrectionMillimeters[j][k]; + } + } + + numberOfRows = in[i].phaseCenterVariationCorrectionUncertaintyMillimeters.size(); + out[i].phaseCenterVariationCorrectionUncertaintyMillimeters.resize(numberOfRows); + for (uint32_t j = 0; j < numberOfRows; j++) { + numberOfColumns = in[i].phaseCenterVariationCorrectionUncertaintyMillimeters[j].size(); + out[i].phaseCenterVariationCorrectionUncertaintyMillimeters[j]. + row.resize(numberOfColumns); + for (uint32_t k = 0; k < numberOfColumns; k++) { + out[i].phaseCenterVariationCorrectionUncertaintyMillimeters[j].row[k] = + in[i].phaseCenterVariationCorrectionUncertaintyMillimeters[j][k]; + } + } + + numberOfRows = in[i].signalGainCorrectionDbi.size(); + out[i].signalGainCorrectionDbi.resize(numberOfRows); + for (uint32_t j = 0; j < numberOfRows; j++) { + numberOfColumns = in[i].signalGainCorrectionDbi[j].size(); + out[i].signalGainCorrectionDbi[j].row.resize(numberOfColumns); + for (uint32_t k = 0; k < numberOfColumns; k++) { + out[i].signalGainCorrectionDbi[j].row[k] = in[i].signalGainCorrectionDbi[j][k]; + } + } + + numberOfRows = in[i].signalGainCorrectionUncertaintyDbi.size(); + out[i].signalGainCorrectionUncertaintyDbi.resize(numberOfRows); + for (uint32_t j = 0; j < numberOfRows; j++) { + numberOfColumns = in[i].signalGainCorrectionUncertaintyDbi[j].size(); + out[i].signalGainCorrectionUncertaintyDbi[j].row.resize(numberOfColumns); + for (uint32_t k = 0; k < numberOfColumns; k++) { + out[i].signalGainCorrectionUncertaintyDbi[j].row[k] = + in[i].signalGainCorrectionUncertaintyDbi[j][k]; + } + } + } +} + +GnssAntennaInfo::GnssAntennaInfo(Gnss* gnss) : mGnss(gnss) { + mGnssAntennaInfoDeathRecipient = new GnssAntennaInfoDeathRecipient(this); + spGnssAntennaInfo = this; +} + +GnssAntennaInfo::~GnssAntennaInfo() { + spGnssAntennaInfo = nullptr; +} + +// Methods from ::android::hardware::gnss::V2_1::IGnssAntennaInfo follow. +Return + GnssAntennaInfo::setCallback(const sp& callback) { + uint32_t retValue; + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return GnssAntennaInfoStatus::ERROR_GENERIC; + } + + mGnssAntennaInfoCbIface = callback; + retValue = mGnss->getGnssInterface()->antennaInfoInit(aiGnssAntennaInfoCb); + + switch (retValue) { + case ANTENNA_INFO_SUCCESS: return GnssAntennaInfoStatus::SUCCESS; + case ANTENNA_INFO_ERROR_ALREADY_INIT: return GnssAntennaInfoStatus::ERROR_ALREADY_INIT; + case ANTENNA_INFO_ERROR_GENERIC: + default: return GnssAntennaInfoStatus::ERROR_GENERIC; + } +} + +Return GnssAntennaInfo::close(void) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + mGnss->getGnssInterface()->antennaInfoClose(); + + return Void(); +} + +void GnssAntennaInfo::aiGnssAntennaInfoCb + (std::vector gnssAntennaInformations) { + if (nullptr != spGnssAntennaInfo) { + spGnssAntennaInfo->gnssAntennaInfoCb(gnssAntennaInformations); + } +} + +void GnssAntennaInfo::gnssAntennaInfoCb + (std::vector gnssAntennaInformations) { + + if (mGnssAntennaInfoCbIface != nullptr) { + hidl_vec antennaInfos; + + // Convert from one structure to another + convertGnssAntennaInfo(gnssAntennaInformations, antennaInfos); + + auto r = mGnssAntennaInfoCbIface->gnssAntennaInfoCb(antennaInfos); + if (!r.isOk()) { + LOC_LOGw("Error antenna info cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssAntennaInfo.h b/gps/android/2.1/GnssAntennaInfo.h new file mode 100644 index 0000000..02ddd28 --- /dev/null +++ b/gps/android/2.1/GnssAntennaInfo.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H +#define ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_1::IGnssAntennaInfo; +using ::android::hardware::gnss::V2_1::IGnssAntennaInfoCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct GnssAntennaInfo : public IGnssAntennaInfo { + GnssAntennaInfo(Gnss* gnss); + ~GnssAntennaInfo(); + + /* + * Methods from ::android::hardware::gnss::V1_1::IGnssAntennaInfo follow. + * These declarations were generated from IGnssAntennaInfo.hal. + */ + Return + setCallback(const sp& callback) override; + Return close(void) override; + + void gnssAntennaInfoCb(std::vector gnssAntennaInformations); + + static void aiGnssAntennaInfoCb(std::vector gnssAntennaInformations); + + private: + struct GnssAntennaInfoDeathRecipient : hidl_death_recipient { + GnssAntennaInfoDeathRecipient(sp gnssAntennaInfo) : + mGnssAntennaInfo(gnssAntennaInfo) { + } + ~GnssAntennaInfoDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssAntennaInfo; + }; + + private: + sp mGnssAntennaInfoDeathRecipient = nullptr; + sp mGnssAntennaInfoCbIface = nullptr; + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSANTENNAINFO_H diff --git a/gps/android/2.1/GnssBatching.cpp b/gps/android/2.1/GnssBatching.cpp new file mode 100644 index 0000000..73e3532 --- /dev/null +++ b/gps/android/2.1/GnssBatching.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssBatchingInterface" + +#include +#include +#include "GnssBatching.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +void GnssBatching::GnssBatchingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssBatching != nullptr) { + mGnssBatching->stop(); + mGnssBatching->cleanup(); + } +} + +GnssBatching::GnssBatching() : mApi(nullptr) { + mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this); +} + +GnssBatching::~GnssBatching() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + + +// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. +Return GnssBatching::init(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface = callback; + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +Return GnssBatching::getBatchSize() { + uint16_t ret = 0; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->getBatchSize(); + } + return ret; +} + +Return GnssBatching::start(const IGnssBatching::Options& options) { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->startSession(options); + } + return ret; +} + +Return GnssBatching::flush() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->flushBatchedLocations(); + } + return Void(); +} + +Return GnssBatching::stop() { + bool ret = false; + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + ret = mApi->stopSession(); + } + return ret; +} + +Return GnssBatching::cleanup() { + if (mApi != nullptr) { + mApi->stopSession(); + } + if (mGnssBatchingCbIface != nullptr) { + mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient); + mGnssBatchingCbIface = nullptr; + } + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->unlinkToDeath(mGnssBatchingDeathRecipient); + mGnssBatchingCbIface_2_0 = nullptr; + } + return Void(); +} + +// Methods from ::android::hardware::gnss::V2_0::IGnssBatching follow. +Return GnssBatching::init_2_0(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__); + mApi->destroy(); + mApi = nullptr; + } + + mApi = new BatchingAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + return false; + } + + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->unlinkToDeath(mGnssBatchingDeathRecipient); + } + mGnssBatchingCbIface_2_0 = callback; + if (mGnssBatchingCbIface_2_0 != nullptr) { + mGnssBatchingCbIface_2_0->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/); + } + + return true; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssBatching.h b/gps/android/2.1/GnssBatching.h new file mode 100644 index 0000000..908748f --- /dev/null +++ b/gps/android/2.1/GnssBatching.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H + +#include +#include + + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssBatching; +using ::android::hardware::gnss::V2_0::IGnssBatchingCallback; +using ::android::hidl::base::V1_0::IBase; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class BatchingAPIClient; +struct GnssBatching : public IGnssBatching { + GnssBatching(); + ~GnssBatching(); + + // Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow. + Return init(const sp& callback) override; + Return getBatchSize() override; + Return start(const IGnssBatching::Options& options ) override; + Return flush() override; + Return stop() override; + Return cleanup() override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssBatching follow. + Return init_2_0(const sp& callback) override; + + private: + struct GnssBatchingDeathRecipient : hidl_death_recipient { + GnssBatchingDeathRecipient(sp gnssBatching) : + mGnssBatching(gnssBatching) { + } + ~GnssBatchingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssBatching; + }; + + private: + sp mGnssBatchingDeathRecipient = nullptr; + sp mGnssBatchingCbIface = nullptr; + BatchingAPIClient* mApi = nullptr; + sp mGnssBatchingCbIface_2_0 = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSBATCHING_H diff --git a/gps/android/2.1/GnssConfiguration.cpp b/gps/android/2.1/GnssConfiguration.cpp new file mode 100644 index 0000000..b6077ae --- /dev/null +++ b/gps/android/2.1/GnssConfiguration.cpp @@ -0,0 +1,408 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssConfigurationInterface" + +#include +#include "Gnss.h" +#include "GnssConfiguration.h" +#include "ContextBase.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::GnssConstellationType; +using namespace loc_core; + +GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) { +} + +// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow. +Return GnssConfiguration::setSuplEs(bool enabled) { + // deprecated function. Must return false to pass VTS + return false; +} + +Return GnssConfiguration::setSuplVersion(uint32_t version) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT; + switch (version) { + case 0x00020004: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4; + break; + case 0x00020002: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2; + break; + case 0x00020000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0; + break; + case 0x00010000: + config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0; + break; + default: + LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setSuplMode(uint8_t mode) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT; + switch (mode) { + case 0: + config.suplModeMask = 0; // STANDALONE ONLY + break; + case 1: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT; + break; + case 2: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + case 3: + config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT; + break; + default: + LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode); + return false; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setLppProfile(uint8_t lppProfileMask) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default + + if (lppProfileMask & (1<<0)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT; + } + if (lppProfileMask & (1<<1)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT; + } + if (lppProfileMask & (1<<2)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT; + } + if (lppProfileMask & (1<<3)) { + config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + + config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT; + if (protocol & (1<<0)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT; + } + if (protocol & (1<<1)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT; + } + if (protocol & (1<<2)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT; + } + if (protocol & (1<<3)) { + config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT; + } + + return mGnss->updateConfiguration(config); +} + +Return GnssConfiguration::setGpsLock(uint8_t lock) { + + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT; + switch (lock) { + case 0: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + break; + case 1: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO; + break; + case 2: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI; + break; + case 3: + config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; + break; + default: + LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock); + return false; + } + + mGnss->updateConfiguration(config); + // Must return false to pass VTS + return false; +} + +Return GnssConfiguration::setEmergencySuplPdn(bool enabled) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT; + config.emergencyPdnForEmergencySupl = (enabled ? + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES : + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO); + + return mGnss->updateConfiguration(config); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. +Return GnssConfiguration::setBlacklist( + const hidl_vec& blacklist) { + + ENTRY_LOG_CALLFLOW(); + if (nullptr == mGnss) { + LOC_LOGe("mGnss is null"); + return false; + } + + // blValid is true if blacklist is empty, i.e. clearing the BL; + // if blacklist is not empty, blValid is initialied to false, and later + // updated in the for loop to become true only if there is at least + // one {constellation, svid} in the list that is valid. + bool blValid = (0 == blacklist.size()); + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + config.blacklistedSvIds.clear(); + + GnssSvIdSource source = {}; + for (int idx = 0; idx < (int)blacklist.size(); idx++) { + // Set blValid true if any one source is valid + blValid = setBlacklistedSource(source, (GnssConstellationType)blacklist[idx].constellation, + blacklist[idx].svid) || blValid; + config.blacklistedSvIds.push_back(source); + } + + // Update configuration only if blValid is true + // i.e. only if atleast one source is valid for blacklisting + return (blValid && mGnss->updateConfiguration(config)); +} + +bool GnssConfiguration::setBlacklistedSource( + GnssSvIdSource& copyToSource, const GnssConstellationType& constellation, + const int16_t svid) { + + bool retVal = true; + uint16_t svIdOffset = 0; + copyToSource.size = sizeof(GnssSvIdSource); + copyToSource.svId = svid; + + switch(constellation) { + case GnssConstellationType::GPS: + copyToSource.constellation = GNSS_SV_TYPE_GPS; + LOC_LOGe("GPS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::SBAS: + copyToSource.constellation = GNSS_SV_TYPE_SBAS; + LOC_LOGe("SBAS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::GLONASS: + copyToSource.constellation = GNSS_SV_TYPE_GLONASS; + svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::QZSS: + copyToSource.constellation = GNSS_SV_TYPE_QZSS; + svIdOffset = 0; + break; + case GnssConstellationType::BEIDOU: + copyToSource.constellation = GNSS_SV_TYPE_BEIDOU; + svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::GALILEO: + copyToSource.constellation = GNSS_SV_TYPE_GALILEO; + svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::IRNSS: + copyToSource.constellation = GNSS_SV_TYPE_NAVIC; + svIdOffset = 0; + break; + default: + copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; + LOC_LOGe("Invalid constellation %hhu", constellation); + retVal = false; + break; + } + + if (copyToSource.svId > 0 && svIdOffset > 0) { + copyToSource.svId += svIdOffset; + } + + return retVal; +} + +bool GnssConfiguration::setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource) { + + bool retVal = true; + uint16_t svIdOffset = 0; + copyToSource.size = sizeof(GnssSvIdSource); + copyToSource.svId = copyFromSource.svid; + + switch(copyFromSource.constellation) { + case GnssConstellationType::GPS: + copyToSource.constellation = GNSS_SV_TYPE_GPS; + LOC_LOGe("GPS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::SBAS: + copyToSource.constellation = GNSS_SV_TYPE_SBAS; + LOC_LOGe("SBAS SVs can't be blacklisted."); + retVal = false; + break; + case GnssConstellationType::GLONASS: + copyToSource.constellation = GNSS_SV_TYPE_GLONASS; + svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::QZSS: + copyToSource.constellation = GNSS_SV_TYPE_QZSS; + svIdOffset = GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::BEIDOU: + copyToSource.constellation = GNSS_SV_TYPE_BEIDOU; + svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::GALILEO: + copyToSource.constellation = GNSS_SV_TYPE_GALILEO; + svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1; + break; + case GnssConstellationType::IRNSS: + copyToSource.constellation = GNSS_SV_TYPE_NAVIC; + svIdOffset = GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID - 1; + break; + default: + copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN; + LOC_LOGe("Invalid constellation %hhu", copyFromSource.constellation); + retVal = false; + break; + } + + if (copyToSource.svId > 0 && svIdOffset > 0) { + copyToSource.svId += svIdOffset; + } + + return retVal; +} + +// Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow. +Return GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) { + ENTRY_LOG_CALLFLOW(); + if (mGnss == nullptr) { + LOC_LOGe("mGnss is nullptr"); + return false; + } + + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT; + config.emergencyExtensionSeconds = emergencyExtensionSeconds; + + return mGnss->updateConfiguration(config); +} + +// Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow. +Return GnssConfiguration::setBlacklist_2_1( + const hidl_vec& blacklist) { + ENTRY_LOG_CALLFLOW(); + if (nullptr == mGnss) { + LOC_LOGe("mGnss is null"); + return false; + } + + // blValid is true if blacklist is empty, i.e. clearing the BL; + // if blacklist is not empty, blValid is initialied to false, and later + // updated in the for loop to become true only if there is at least + // one {constellation, svid} in the list that is valid. + bool blValid = (0 == blacklist.size()); + GnssConfig config; + memset(&config, 0, sizeof(GnssConfig)); + config.size = sizeof(GnssConfig); + config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + config.blacklistedSvIds.clear(); + + GnssSvIdSource source = {}; + for (int idx = 0; idx < (int)blacklist.size(); idx++) { + // Set blValid true if any one source is valid + blValid = setBlacklistedSource(source, blacklist[idx]) || blValid; + config.blacklistedSvIds.push_back(source); + } + + // Update configuration only if blValid is true + // i.e. only if atleast one source is valid for blacklisting + return (blValid && mGnss->updateConfiguration(config)); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssConfiguration.h b/gps/android/2.1/GnssConfiguration.h new file mode 100644 index 0000000..f000dbd --- /dev/null +++ b/gps/android/2.1/GnssConfiguration.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ + + /* Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H +#define ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::hardware::gnss::V2_0::GnssConstellationType; +using ::android::sp; + +/* + * Interface for passing GNSS configuration info from platform to HAL. + */ +struct Gnss; +struct GnssConfiguration : public V2_1::IGnssConfiguration { + GnssConfiguration(Gnss* gnss); + ~GnssConfiguration() = default; + + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow. + * These declarations were generated from IGnssConfiguration.hal. + */ + Return setSuplVersion(uint32_t version) override; + Return setSuplMode(uint8_t mode) override; + Return setSuplEs(bool enabled) override; + Return setLppProfile(uint8_t lppProfileMask) override; + Return setGlonassPositioningProtocol(uint8_t protocol) override; + Return setEmergencySuplPdn(bool enable) override; + Return setGpsLock(uint8_t lock) override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow. + Return setBlacklist( + const hidl_vec& blacklist) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow. + Return setEsExtensionSec(uint32_t emergencyExtensionSeconds) override; + // Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow. + Return setBlacklist_2_1( + const hidl_vec& blacklist) override; + + private: + Gnss* mGnss = nullptr; + bool setBlacklistedSource( + GnssSvIdSource& copyToSource, + const GnssConfiguration::BlacklistedSource& copyFromSource); + bool setBlacklistedSource( + GnssSvIdSource& copyToSource, const GnssConstellationType& constellation, + const int16_t svid); +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSCONFIGURATION_H diff --git a/gps/android/2.1/GnssDebug.cpp b/gps/android/2.1/GnssDebug.cpp new file mode 100644 index 0000000..27ff964 --- /dev/null +++ b/gps/android/2.1/GnssDebug.cpp @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssDebugInterface" + +#include +#include +#include "Gnss.h" +#include "GnssDebug.h" +#include "LocationUtil.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::hidl_vec; +using ::android::hardware::gnss::V2_0::IGnssDebug; + +#define GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS (20000000) +#define GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS (20000) +#define GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC (500) +#define GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG (180) + +#define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000LL) // 1/1/2017 00:00 GMT +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN (999) // 999 ns +#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX (1.57783680E17) // 5 years in ns +#define GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC (2.0e5) // ppm + +GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss) +{ +} + +/* + * This methods requests position, time and satellite ephemeris debug information + * from the HAL. + * + * @return void +*/ +Return GnssDebug::getDebugData(getDebugData_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + V1_0::IGnssDebug::DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + V1_0::IGnssDebug::SatelliteData s = { }; + std::vector s_array; + + for (uint32_t i=0; i GnssDebug::getDebugData_2_0(getDebugData_2_0_cb _hidl_cb) +{ + LOC_LOGD("%s]: ", __func__); + + V2_0::IGnssDebug::DebugData data = { }; + + if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){ + LOC_LOGE("GnssDebug - Null GNSS interface"); + _hidl_cb(data); + return Void(); + } + + // get debug report snapshot via hal interface + GnssDebugReport reports = { }; + mGnss->getGnssInterface()->getDebugReport(reports); + + // location block + if (reports.mLocation.mValid) { + data.position.valid = true; + data.position.latitudeDegrees = reports.mLocation.mLocation.latitude; + data.position.longitudeDegrees = reports.mLocation.mLocation.longitude; + data.position.altitudeMeters = reports.mLocation.mLocation.altitude; + + data.position.speedMetersPerSec = + (double)(reports.mLocation.mLocation.speed); + data.position.bearingDegrees = + (double)(reports.mLocation.mLocation.bearing); + data.position.horizontalAccuracyMeters = + (double)(reports.mLocation.mLocation.accuracy); + data.position.verticalAccuracyMeters = + reports.mLocation.verticalAccuracyMeters; + data.position.speedAccuracyMetersPerSecond = + reports.mLocation.speedAccuracyMetersPerSecond; + data.position.bearingAccuracyDegrees = + reports.mLocation.bearingAccuracyDegrees; + + timeval tv_now, tv_report; + tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec; + tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL; + gettimeofday(&tv_now, NULL); + data.position.ageSeconds = + (tv_now.tv_sec - tv_report.tv_sec) + + (float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000; + } + else { + data.position.valid = false; + } + + if (data.position.horizontalAccuracyMeters <= 0 || + data.position.horizontalAccuracyMeters > GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS) { + data.position.horizontalAccuracyMeters = GNSS_DEBUG_UNKNOWN_HORIZONTAL_ACCURACY_METERS; + } + if (data.position.verticalAccuracyMeters <= 0 || + data.position.verticalAccuracyMeters > GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS) { + data.position.verticalAccuracyMeters = GNSS_DEBUG_UNKNOWN_VERTICAL_ACCURACY_METERS; + } + if (data.position.speedAccuracyMetersPerSecond <= 0 || + data.position.speedAccuracyMetersPerSecond > GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC) { + data.position.speedAccuracyMetersPerSecond = GNSS_DEBUG_UNKNOWN_SPEED_ACCURACY_PER_SEC; + } + if (data.position.bearingAccuracyDegrees <= 0 || + data.position.bearingAccuracyDegrees > GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG) { + data.position.bearingAccuracyDegrees = GNSS_DEBUG_UNKNOWN_BEARING_ACCURACY_DEG; + } + + // time block + if (reports.mTime.mValid) { + data.time.timeEstimate = reports.mTime.timeEstimate; + data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs; + data.time.frequencyUncertaintyNsPerSec = + reports.mTime.frequencyUncertaintyNsPerSec; + } + + if (data.time.timeEstimate < GNSS_DEBUG_UNKNOWN_UTC_TIME) { + data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME; + } + if (data.time.timeUncertaintyNs <= 0) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MIN; + } + else if (data.time.timeUncertaintyNs > GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX) { + data.time.timeUncertaintyNs = (float)GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC_MAX; + } + if (data.time.frequencyUncertaintyNsPerSec <= 0 || + data.time.frequencyUncertaintyNsPerSec > (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC) { + data.time.frequencyUncertaintyNsPerSec = (float)GNSS_DEBUG_UNKNOWN_FREQ_UNC_NS_PER_SEC; + } + + // satellite data block + V2_0::IGnssDebug::SatelliteData s = { }; + std::vector s_array; + + for (uint32_t i=0; i +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssDebug; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +/* Interface for GNSS Debug support. */ +struct Gnss; +struct GnssDebug : public IGnssDebug { + GnssDebug(Gnss* gnss); + ~GnssDebug() {}; + + // Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow + Return getDebugData(getDebugData_cb _hidl_cb) override; + // Methods from ::android::hardware::gnss::V2_0::IGnssDebug follow. + Return getDebugData_2_0(getDebugData_2_0_cb _hidl_cb) override; + +private: + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSDEBUG_H diff --git a/gps/android/2.1/GnssGeofencing.cpp b/gps/android/2.1/GnssGeofencing.cpp new file mode 100644 index 0000000..0ca3e6d --- /dev/null +++ b/gps/android/2.1/GnssGeofencing.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "GnssHal_GnssGeofencing" + +#include +#include +#include "GnssGeofencing.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssGeofencing != nullptr) { + mGnssGeofencing->removeAllGeofences(); + } +} + +GnssGeofencing::GnssGeofencing() : mApi(nullptr) { + mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this); +} + +GnssGeofencing::~GnssGeofencing() { + if (mApi != nullptr) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. +Return GnssGeofencing::setCallback(const sp& callback) { + if (mApi != nullptr) { + LOC_LOGd("mApi is NOT nullptr"); + return Void(); + } + + mApi = new GeofenceAPIClient(callback); + if (mApi == nullptr) { + LOC_LOGE("%s]: failed to create mApi", __FUNCTION__); + } + + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient); + } + mGnssGeofencingCbIface = callback; + if (mGnssGeofencingCbIface != nullptr) { + mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssGeofencing::addGeofence( + int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceAdd( + geofenceId, + latitudeDegrees, + longitudeDegrees, + radiusMeters, + static_cast(lastTransition), + monitorTransitions, + notificationResponsivenessMs, + unknownTimerMs); + } + return Void(); +} + +Return GnssGeofencing::pauseGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofencePause(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceResume(geofenceId, monitorTransitions); + } + return Void(); +} + +Return GnssGeofencing::removeGeofence(int32_t geofenceId) { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + } else { + mApi->geofenceRemove(geofenceId); + } + return Void(); +} + +Return GnssGeofencing::removeAllGeofences() { + if (mApi == nullptr) { + LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__); + } else { + mApi->geofenceRemoveAll(); + } + return Void(); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssGeofencing.h b/gps/android/2.1/GnssGeofencing.h new file mode 100644 index 0000000..1cdca12 --- /dev/null +++ b/gps/android/2.1/GnssGeofencing.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::IGnssGeofencing; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class GeofenceAPIClient; +struct GnssGeofencing : public IGnssGeofencing { + GnssGeofencing(); + ~GnssGeofencing(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow. + * These declarations were generated from IGnssGeofencing.hal. + */ + Return setCallback(const sp& callback) override; + Return addGeofence(int32_t geofenceId, + double latitudeDegrees, + double longitudeDegrees, + double radiusMeters, + IGnssGeofenceCallback::GeofenceTransition lastTransition, + int32_t monitorTransitions, + uint32_t notificationResponsivenessMs, + uint32_t unknownTimerMs) override; + + Return pauseGeofence(int32_t geofenceId) override; + Return resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override; + Return removeGeofence(int32_t geofenceId) override; + + private: + // This method is not part of the IGnss base class. + // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far. + Return removeAllGeofences(); + + private: + struct GnssGeofencingDeathRecipient : hidl_death_recipient { + GnssGeofencingDeathRecipient(sp gnssGeofencing) : + mGnssGeofencing(gnssGeofencing) { + } + ~GnssGeofencingDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssGeofencing; + }; + + private: + sp mGnssGeofencingDeathRecipient = nullptr; + sp mGnssGeofencingCbIface = nullptr; + GeofenceAPIClient* mApi = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSGEOFENCING_H diff --git a/gps/android/2.1/GnssMeasurement.cpp b/gps/android/2.1/GnssMeasurement.cpp new file mode 100644 index 0000000..af75802 --- /dev/null +++ b/gps/android/2.1/GnssMeasurement.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssMeasurementInterface" + +#include +#include "GnssMeasurement.h" +#include "MeasurementAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied( + uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + if (mGnssMeasurement != nullptr) { + mGnssMeasurement->close(); + } +} + +GnssMeasurement::GnssMeasurement() { + mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this); + mApi = new MeasurementAPIClient(); +} + +GnssMeasurement::~GnssMeasurement() { + if (mApi) { + mApi->destroy(); + mApi = nullptr; + } +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. +Return GnssMeasurement::setCallback( + const sp& callback) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface = callback; + mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + return mApi->measurementSetCallback(callback); +} + +void GnssMeasurement::clearInterfaces() { + if (mGnssMeasurementCbIface != nullptr) { + mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface = nullptr; + } + if (mGnssMeasurementCbIface_1_1 != nullptr) { + mGnssMeasurementCbIface_1_1->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_1_1 = nullptr; + } + if (mGnssMeasurementCbIface_2_0 != nullptr) { + mGnssMeasurementCbIface_2_0->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_2_0 = nullptr; + } + if (mGnssMeasurementCbIface_2_1 != nullptr) { + mGnssMeasurementCbIface_2_1->unlinkToDeath(mGnssMeasurementDeathRecipient); + mGnssMeasurementCbIface_2_1 = nullptr; + } +} + +Return GnssMeasurement::close() { + if (mApi == nullptr) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return Void(); + } + + clearInterfaces(); + mApi->measurementClose(); + + return Void(); +} + +// Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_1_1( + const sp& callback, bool enableFullTracking) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_1_1 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface_1_1 = callback; + mGnssMeasurementCbIface_1_1->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_1_1(callback, powerMode); +} +// Methods from ::android::hardware::gnss::V2_0::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_2_0( + const sp& callback, + bool enableFullTracking) { + + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_2_0 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface_2_0 = callback; + mGnssMeasurementCbIface_2_0->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking ? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_2_0(callback, powerMode); +} + +// Methods from ::android::hardware::gnss::V2_1::IGnssMeasurement follow. +Return GnssMeasurement::setCallback_2_1( + const sp<::android::hardware::gnss::V2_1::IGnssMeasurementCallback>& callback, + bool enableFullTracking) { + Return ret = + IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC; + if (mGnssMeasurementCbIface_2_1 != nullptr) { + LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__); + return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT; + } + + if (callback == nullptr) { + LOC_LOGE("%s]: callback is nullptr", __FUNCTION__); + return ret; + } + if (nullptr == mApi) { + LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__); + return ret; + } + + clearInterfaces(); + + mGnssMeasurementCbIface_2_1 = callback; + mGnssMeasurementCbIface_2_1->linkToDeath(mGnssMeasurementDeathRecipient, 0); + + GnssPowerMode powerMode = enableFullTracking ? + GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2; + + return mApi->measurementSetCallback_2_1(callback, powerMode); + +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssMeasurement.h b/gps/android/2.1/GnssMeasurement.h new file mode 100644 index 0000000..2ac45c6 --- /dev/null +++ b/gps/android/2.1/GnssMeasurement.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_1_GNSSMEASUREMENT_H +#define ANDROID_HARDWARE_GNSS_V2_1_GNSSMEASUREMENT_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +class MeasurementAPIClient; +struct GnssMeasurement : public V2_1::IGnssMeasurement { + GnssMeasurement(); + ~GnssMeasurement(); + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow. + * These declarations were generated from IGnssMeasurement.hal. + */ + Return setCallback( + const sp& callback) override; + Return close() override; + + // Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow. + Return setCallback_1_1( + const sp& callback, + bool enableFullTracking) override; + + // Methods from ::android::hardware::gnss::V2_0::IGnssMeasurement follow. + Return setCallback_2_0( + const sp& callback, + bool enableFullTracking) override; + // Methods from ::android::hardware::gnss::V2_1::IGnssMeasurement follow. + Return setCallback_2_1( + const sp<::android::hardware::gnss::V2_1::IGnssMeasurementCallback>& callback, + bool enableFullTracking) override; + + private: + struct GnssMeasurementDeathRecipient : hidl_death_recipient { + GnssMeasurementDeathRecipient(sp gnssMeasurement) : + mGnssMeasurement(gnssMeasurement) { + } + ~GnssMeasurementDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssMeasurement; + }; + + private: + sp mGnssMeasurementDeathRecipient = nullptr; + sp mGnssMeasurementCbIface = nullptr; + sp mGnssMeasurementCbIface_1_1 = nullptr; + sp mGnssMeasurementCbIface_2_0 = nullptr; + sp mGnssMeasurementCbIface_2_1 = nullptr; + MeasurementAPIClient* mApi; + void clearInterfaces(); +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_1_GNSSMEASUREMENT_H diff --git a/gps/android/2.1/GnssNi.cpp b/gps/android/2.1/GnssNi.cpp new file mode 100644 index 0000000..ba5e8d9 --- /dev/null +++ b/gps/android/2.1/GnssNi.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "LocSvc_GnssNiInterface" + +#include +#include "Gnss.h" +#include "GnssNi.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp& who) { + LOC_LOGE("%s] service died. cookie: %llu, who: %p", + __FUNCTION__, static_cast(cookie), &who); + // we do nothing here + // Gnss::GnssDeathRecipient will stop the session +} + +GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) { + mGnssNiDeathRecipient = new GnssNiDeathRecipient(this); +} + +// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. +Return GnssNi::setCallback(const sp& callback) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + mGnss->setGnssNiCb(callback); + + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient); + } + mGnssNiCbIface = callback; + if (mGnssNiCbIface != nullptr) { + mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/); + } + + return Void(); +} + +Return GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) { + if (mGnss == nullptr) { + LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); + return Void(); + } + + GnssAPIClient* api = mGnss->getApi(); + if (api == nullptr) { + LOC_LOGE("%s]: api is nullptr", __FUNCTION__); + return Void(); + } + + api->gnssNiRespond(notifId, userResponse); + + return Void(); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssNi.h b/gps/android/2.1/GnssNi.h new file mode 100644 index 0000000..9a8fb69 --- /dev/null +++ b/gps/android/2.1/GnssNi.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H +#define ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssNi; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Gnss; +struct GnssNi : public IGnssNi { + GnssNi(Gnss* gnss); + ~GnssNi() = default; + + /* + * Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. + * These declarations were generated from IGnssNi.hal. + */ + Return setCallback(const sp& callback) override; + Return respond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) override; + + private: + struct GnssNiDeathRecipient : hidl_death_recipient { + GnssNiDeathRecipient(sp gnssNi) : mGnssNi(gnssNi) { + } + ~GnssNiDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssNi; + }; + + private: + sp mGnssNiDeathRecipient = nullptr; + sp mGnssNiCbIface = nullptr; + Gnss* mGnss = nullptr; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_GNSSNI_H diff --git a/gps/android/2.1/GnssVisibilityControl.cpp b/gps/android/2.1/GnssVisibilityControl.cpp new file mode 100644 index 0000000..5a8c697 --- /dev/null +++ b/gps/android/2.1/GnssVisibilityControl.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include "GnssVisibilityControl.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace visibility_control { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +static GnssVisibilityControl* spGnssVisibilityControl = nullptr; + +static void convertGnssNfwNotification(GnssNfwNotification& in, + IGnssVisibilityControlCallback::NfwNotification& out); + +GnssVisibilityControl::GnssVisibilityControl(Gnss* gnss) : mGnss(gnss) { + spGnssVisibilityControl = this; +} +GnssVisibilityControl::~GnssVisibilityControl() { + spGnssVisibilityControl = nullptr; +} + +void GnssVisibilityControl::nfwStatusCb(GnssNfwNotification notification) { + if (nullptr != spGnssVisibilityControl) { + spGnssVisibilityControl->statusCb(notification); + } +} + +bool GnssVisibilityControl::isInEmergencySession() { + if (nullptr != spGnssVisibilityControl) { + return spGnssVisibilityControl->isE911Session(); + } + return false; +} + +static void convertGnssNfwNotification(GnssNfwNotification& in, + IGnssVisibilityControlCallback::NfwNotification& out) +{ + memset(&out, 0, sizeof(IGnssVisibilityControlCallback::NfwNotification)); + out.proxyAppPackageName = in.proxyAppPackageName; + out.protocolStack = (IGnssVisibilityControlCallback::NfwProtocolStack)in.protocolStack; + out.otherProtocolStackName = in.otherProtocolStackName; + out.requestor = (IGnssVisibilityControlCallback::NfwRequestor)in.requestor; + out.requestorId = in.requestorId; + out.responseType = (IGnssVisibilityControlCallback::NfwResponseType)in.responseType; + out.inEmergencyMode = in.inEmergencyMode; + out.isCachedLocation = in.isCachedLocation; +} + +void GnssVisibilityControl::statusCb(GnssNfwNotification notification) { + + if (mGnssVisibilityControlCbIface != nullptr) { + IGnssVisibilityControlCallback::NfwNotification nfwNotification; + + // Convert from one structure to another + convertGnssNfwNotification(notification, nfwNotification); + + auto r = mGnssVisibilityControlCbIface->nfwNotifyCb(nfwNotification); + if (!r.isOk()) { + LOC_LOGw("Error invoking NFW status cb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +bool GnssVisibilityControl::isE911Session() { + + if (mGnssVisibilityControlCbIface != nullptr) { + auto r = mGnssVisibilityControlCbIface->isInEmergencySession(); + if (!r.isOk()) { + LOC_LOGw("Error invoking NFW status cb %s", r.description().c_str()); + return false; + } else { + return (r); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + return false; + } +} + +// Methods from ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl follow. +Return GnssVisibilityControl::enableNfwLocationAccess(const hidl_vec<::android::hardware::hidl_string>& proxyApps) { + + if (nullptr == mGnss || nullptr == mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return false; + } + + /* If the vector is empty we need to disable all NFW clients + If there is at least one app in the vector we need to enable + all NFW clients */ + if (0 == proxyApps.size()) { + mGnss->getGnssInterface()->enableNfwLocationAccess(false); + } else { + mGnss->getGnssInterface()->enableNfwLocationAccess(true); + } + + return true; +} +/** + * Registers the callback for HAL implementation to use. + * + * @param callback Handle to IGnssVisibilityControlCallback interface. + */ +Return GnssVisibilityControl::setCallback(const ::android::sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback>& callback) { + + if (nullptr == mGnss || nullptr == mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return false; + } + mGnssVisibilityControlCbIface = callback; + + NfwCbInfo cbInfo = {}; + cbInfo.visibilityControlCb = (void*)nfwStatusCb; + cbInfo.isInEmergencySession = (void*)isInEmergencySession; + + mGnss->getGnssInterface()->nfwInit(cbInfo); + + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace visibility_control +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/GnssVisibilityControl.h b/gps/android/2.1/GnssVisibilityControl.h new file mode 100644 index 0000000..6794a64 --- /dev/null +++ b/gps/android/2.1/GnssVisibilityControl.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H +#define ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H + +#include +#include +#include + +#include +#include +#include "Gnss.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace visibility_control { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V2_1::implementation::Gnss; + +struct GnssVisibilityControl : public IGnssVisibilityControl { + GnssVisibilityControl(Gnss* gnss); + ~GnssVisibilityControl(); + + // Methods from ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl follow. + Return enableNfwLocationAccess(const hidl_vec<::android::hardware::hidl_string>& proxyApps) override; + /** + * Registers the callback for HAL implementation to use. + * + * @param callback Handle to IGnssVisibilityControlCallback interface. + */ + Return setCallback(const ::android::sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback>& callback) override; + + void statusCb(GnssNfwNotification notification); + bool isE911Session(); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void nfwStatusCb(GnssNfwNotification notification); + static bool isInEmergencySession(); + +private: + Gnss* mGnss = nullptr; + sp mGnssVisibilityControlCbIface = nullptr; +}; + + +} // namespace implementation +} // namespace V1_0 +} // namespace visibility_control +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_0_GnssVisibilityControl_H diff --git a/gps/android/2.1/MeasurementCorrections.cpp b/gps/android/2.1/MeasurementCorrections.cpp new file mode 100644 index 0000000..f8f0803 --- /dev/null +++ b/gps/android/2.1/MeasurementCorrections.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "LocSvc_MeasurementCorrectionsInterface" + +#include +#include "MeasurementCorrections.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; +using ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections; +using MeasurementCorrectionsV1_0 = + ::android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections; +using MeasurementCorrectionsV1_1 = + ::android::hardware::gnss::measurement_corrections::V1_1::MeasurementCorrections; + +static MeasurementCorrections* spMeasurementCorrections = nullptr; + +void MeasurementCorrections::GnssMeasurementCorrectionsDeathRecipient::serviceDied(uint64_t cookie, + const wp& who) { + LOC_LOGe("service died. cookie: %llu, who: %p", static_cast(cookie), &who); + // Gnss::GnssDeathrecipient will stop the session + // we inform the adapter that service has died + if (nullptr == spMeasurementCorrections) { + LOC_LOGe("spMeasurementCorrections is nullptr"); + return; + } + if (nullptr == spMeasurementCorrections->mGnss || + nullptr == spMeasurementCorrections->mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return; + } + spMeasurementCorrections->mGnss->getGnssInterface()->measCorrClose(); +} + +MeasurementCorrections::MeasurementCorrections(Gnss* gnss) : mGnss(gnss) { + mGnssMeasurementCorrectionsDeathRecipient = new GnssMeasurementCorrectionsDeathRecipient(this); + spMeasurementCorrections = this; +} + +MeasurementCorrections::~MeasurementCorrections() { + spMeasurementCorrections = nullptr; +} + +void MeasurementCorrections::measCorrSetCapabilitiesCb( + GnssMeasurementCorrectionsCapabilitiesMask capabilities) { + if (nullptr != spMeasurementCorrections) { + spMeasurementCorrections->setCapabilitiesCb(capabilities); + } +} + +void MeasurementCorrections::setCapabilitiesCb( + GnssMeasurementCorrectionsCapabilitiesMask capabilities) { + + if (mMeasurementCorrectionsCbIface != nullptr) { + uint32_t measCorrCapabilities = 0; + + // Convert from one enum to another + if (capabilities & GNSS_MEAS_CORR_LOS_SATS) { + measCorrCapabilities |= + IMeasurementCorrectionsCallback::Capabilities::LOS_SATS; + } + if (capabilities & GNSS_MEAS_CORR_EXCESS_PATH_LENGTH) { + measCorrCapabilities |= + IMeasurementCorrectionsCallback::Capabilities::EXCESS_PATH_LENGTH; + } + if (capabilities & GNSS_MEAS_CORR_REFLECTING_PLANE) { + measCorrCapabilities |= + IMeasurementCorrectionsCallback::Capabilities::REFLECTING_PLANE; + } + + auto r = mMeasurementCorrectionsCbIface->setCapabilitiesCb(measCorrCapabilities); + if (!r.isOk()) { + LOC_LOGw("Error invoking setCapabilitiesCb %s", r.description().c_str()); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + } +} + +Return MeasurementCorrections::setCorrections( + const MeasurementCorrectionsV1_0& corrections) { + + GnssMeasurementCorrections gnssMeasurementCorrections = {}; + + V2_1::implementation::convertMeasurementCorrections(corrections, gnssMeasurementCorrections); + + return mGnss->getGnssInterface()->measCorrSetCorrections(gnssMeasurementCorrections); +} + +Return MeasurementCorrections::setCorrections_1_1( + const MeasurementCorrectionsV1_1& corrections) { + + GnssMeasurementCorrections gnssMeasurementCorrections = {}; + + V2_1::implementation::convertMeasurementCorrections( + corrections.v1_0, gnssMeasurementCorrections); + + gnssMeasurementCorrections.hasEnvironmentBearing = corrections.hasEnvironmentBearing; + gnssMeasurementCorrections.environmentBearingDegrees = + corrections.environmentBearingDegrees; + gnssMeasurementCorrections.environmentBearingUncertaintyDegrees = + corrections.environmentBearingUncertaintyDegrees; + + for (int i = 0; i < corrections.satCorrections.size(); i++) { + GnssSingleSatCorrection gnssSingleSatCorrection = {}; + + V2_1::implementation::convertSingleSatCorrections( + corrections.satCorrections[i].v1_0, gnssSingleSatCorrection); + switch (corrections.satCorrections[i].constellation) { + case (::android::hardware::gnss::V2_0::GnssConstellationType::GPS): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_GPS; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::SBAS): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_SBAS; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::GLONASS): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_GLONASS; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::QZSS): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_QZSS; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::BEIDOU): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_BEIDOU; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::GALILEO): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_GALILEO; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::IRNSS): + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_NAVIC; + break; + case (::android::hardware::gnss::V2_0::GnssConstellationType::UNKNOWN): + default: + gnssSingleSatCorrection.svType = GNSS_SV_TYPE_UNKNOWN; + break; + } + gnssMeasurementCorrections.satCorrections.push_back(gnssSingleSatCorrection); + } + + return mGnss->getGnssInterface()->measCorrSetCorrections(gnssMeasurementCorrections); +} + +Return MeasurementCorrections::setCallback( + const sp& callback) { + + if (nullptr == mGnss || nullptr == mGnss->getGnssInterface()) { + LOC_LOGe("Null GNSS interface"); + return false; + } + mMeasurementCorrectionsCbIface = callback; + + return mGnss->getGnssInterface()->measCorrInit(measCorrSetCapabilitiesCb); +} + +} // namespace implementation +} // namespace V1_1 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/MeasurementCorrections.h b/gps/android/2.1/MeasurementCorrections.h new file mode 100644 index 0000000..92fcc6a --- /dev/null +++ b/gps/android/2.1/MeasurementCorrections.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ANDROID_HARDWARE_GNSS_V1_1_MeasurementCorrections_H +#define ANDROID_HARDWARE_GNSS_V1_1_MeasurementCorrections_H + +#include +#include +#include +#include + +#include +#include +#include "Gnss.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace measurement_corrections { +namespace V1_1 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; +using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrectionsCallback; +using ::android::hardware::gnss::V2_1::implementation::Gnss; +using MeasurementCorrectionsV1_0 = + ::android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections; +using MeasurementCorrectionsV1_1 = + ::android::hardware::gnss::measurement_corrections::V1_1::MeasurementCorrections; + +struct MeasurementCorrections : public V1_1::IMeasurementCorrections { + MeasurementCorrections(Gnss* gnss); + ~MeasurementCorrections(); + + Return setCorrections(const MeasurementCorrectionsV1_0& corrections) override; + + // Methods from + // ::android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections follow. + Return setCorrections_1_1(const MeasurementCorrectionsV1_1& corrections); + + Return setCallback(const sp& callback) override; + + void setCapabilitiesCb(GnssMeasurementCorrectionsCapabilitiesMask capabilities); + + /* Data call setup callback passed down to GNSS HAL implementation */ + static void measCorrSetCapabilitiesCb(GnssMeasurementCorrectionsCapabilitiesMask capabilities); + +private: + struct GnssMeasurementCorrectionsDeathRecipient : hidl_death_recipient { + GnssMeasurementCorrectionsDeathRecipient( + sp gnssMeasurementCorrections) : + mGnssMeasurementCorrections(gnssMeasurementCorrections) { + } + ~GnssMeasurementCorrectionsDeathRecipient() = default; + virtual void serviceDied(uint64_t cookie, const wp& who) override; + sp mGnssMeasurementCorrections; + }; + Gnss* mGnss = nullptr; + sp mGnssMeasurementCorrectionsDeathRecipient = + nullptr; + sp mMeasurementCorrectionsCbIface = nullptr; +}; + + +} // namespace implementation +} // namespace V1_1 +} // namespace measurement_corrections +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V1_1_MeasurementCorrections_H diff --git a/gps/android/2.1/android.hardware.gnss@2.1-service-qti.rc b/gps/android/2.1/android.hardware.gnss@2.1-service-qti.rc new file mode 100644 index 0000000..19e32c4 --- /dev/null +++ b/gps/android/2.1/android.hardware.gnss@2.1-service-qti.rc @@ -0,0 +1,4 @@ +service gnss_service /vendor/bin/hw/android.hardware.gnss@2.1-service-qti + class hal + user gps + group system gps radio vendor_qti_diag diff --git a/gps/android/2.1/android.hardware.gnss@2.1-service-qti.xml b/gps/android/2.1/android.hardware.gnss@2.1-service-qti.xml new file mode 100755 index 0000000..842fb6e --- /dev/null +++ b/gps/android/2.1/android.hardware.gnss@2.1-service-qti.xml @@ -0,0 +1,36 @@ + + + + android.hardware.gnss + hwbinder + @1.1::IGnss/default + @2.1::IGnss/default + + + diff --git a/gps/android/2.1/location_api/BatchingAPIClient.cpp b/gps/android/2.1/location_api/BatchingAPIClient.cpp new file mode 100644 index 0000000..00d2ed9 --- /dev/null +++ b/gps/android/2.1/location_api/BatchingAPIClient.cpp @@ -0,0 +1,251 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_BatchingAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "BatchingAPIClient.h" + +#include "limits.h" + + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::IGnssBatching; +using ::android::hardware::gnss::V2_0::IGnssBatchingCallback; +using ::android::hardware::gnss::V2_0::GnssLocation; + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask); + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(nullptr), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + gnssUpdateCallbacks(callback); +} + +BatchingAPIClient::BatchingAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(nullptr), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + gnssUpdateCallbacks_2_0(callback); +} + +BatchingAPIClient::~BatchingAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +int BatchingAPIClient::getBatchSize() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + return locAPIGetBatchSize(); +} + +void BatchingAPIClient::setCallbacks() +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.batchingCb = [this](size_t count, Location* location, + BatchingOptions batchOptions) { + onBatchingCb(count, location, batchOptions); + }; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void BatchingAPIClient::gnssUpdateCallbacks(const sp& callback) +{ + mMutex.lock(); + mGnssBatchingCbIface = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface != nullptr) { + setCallbacks(); + } +} + +void BatchingAPIClient::gnssUpdateCallbacks_2_0(const sp& callback) +{ + mMutex.lock(); + mGnssBatchingCbIface_2_0 = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface_2_0 != nullptr) { + setCallbacks(); + } +} + +int BatchingAPIClient::startSession(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::updateSessionOptions(const IGnssBatching::Options& opts) +{ + LOC_LOGD("%s]: (%lld %d)", __FUNCTION__, + static_cast(opts.periodNanos), static_cast(opts.flags)); + int retVal = -1; + LocationOptions options; + convertBatchOption(opts, options, mLocationCapabilitiesMask); + + uint32_t mode = 0; + if (opts.flags == static_cast(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) { + mode = SESSION_MODE_ON_FULL; + } + if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +int BatchingAPIClient::stopSession() +{ + LOC_LOGD("%s]: ", __FUNCTION__); + int retVal = -1; + if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) { + retVal = 1; + } + return retVal; +} + +void BatchingAPIClient::getBatchedLocation(int last_n_locations) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations); + locAPIGetBatchedLocations(mDefaultId, last_n_locations); +} + +void BatchingAPIClient::flushBatchedLocations() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + locAPIGetBatchedLocations(mDefaultId, SIZE_MAX); +} + +void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; +} + +void BatchingAPIClient::onBatchingCb(size_t count, Location* location, + BatchingOptions /*batchOptions*/) +{ + mMutex.lock(); + auto gnssBatchingCbIface(mGnssBatchingCbIface); + auto gnssBatchingCbIface_2_0(mGnssBatchingCbIface_2_0); + mMutex.unlock(); + + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count); + if (gnssBatchingCbIface_2_0 != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = gnssBatchingCbIface_2_0->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb 2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssBatchingCbIface != nullptr && count > 0) { + hidl_vec locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = gnssBatchingCbIface->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb 1.0 description=%s", + __func__, r.description().c_str()); + } + } +} + +static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, + LocationCapabilitiesMask mask) +{ + memset(&out, 0, sizeof(LocationOptions)); + out.size = sizeof(LocationOptions); + out.minInterval = (uint32_t)(in.periodNanos / 1000000L); + out.minDistance = 0; + out.mode = GNSS_SUPL_MODE_STANDALONE; + if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + out.mode = GNSS_SUPL_MODE_MSA; + if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + out.mode = GNSS_SUPL_MODE_MSB; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/location_api/BatchingAPIClient.h b/gps/android/2.1/location_api/BatchingAPIClient.h new file mode 100755 index 0000000..08d7d23 --- /dev/null +++ b/gps/android/2.1/location_api/BatchingAPIClient.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef BATCHING_API_CLINET_H +#define BATCHING_API_CLINET_H + +#include +#include +#include +#include + +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +class BatchingAPIClient : public LocationAPIClientBase +{ +public: + BatchingAPIClient(const sp& callback); + BatchingAPIClient(const sp& callback); + void gnssUpdateCallbacks(const sp& callback); + void gnssUpdateCallbacks_2_0(const sp& callback); + int getBatchSize(); + int startSession(const V1_0::IGnssBatching::Options& options); + int updateSessionOptions(const V1_0::IGnssBatching::Options& options); + int stopSession(); + void getBatchedLocation(int last_n_locations); + void flushBatchedLocations(); + + inline LocationCapabilitiesMask getCapabilities() { return mLocationCapabilitiesMask; } + + // callbacks + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions) final; + +private: + ~BatchingAPIClient(); + + void setCallbacks(); + std::mutex mMutex; + sp mGnssBatchingCbIface; + uint32_t mDefaultId; + LocationCapabilitiesMask mLocationCapabilitiesMask; + sp mGnssBatchingCbIface_2_0; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // BATCHING_API_CLINET_H diff --git a/gps/android/2.1/location_api/GeofenceAPIClient.cpp b/gps/android/2.1/location_api/GeofenceAPIClient.cpp new file mode 100755 index 0000000..6e63465 --- /dev/null +++ b/gps/android/2.1/location_api/GeofenceAPIClient.cpp @@ -0,0 +1,275 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GeofenceApiClient" + +#include +#include + +#include "LocationUtil.h" +#include "GeofenceAPIClient.h" + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback; +using ::android::hardware::gnss::V1_0::GnssLocation; + +GeofenceAPIClient::GeofenceAPIClient(const sp& callback) : + LocationAPIClientBase(), + mGnssGeofencingCbIface(callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + + locationCallbacks.geofenceBreachCb = nullptr; + if (mGnssGeofencingCbIface != nullptr) { + locationCallbacks.geofenceBreachCb = + [this](GeofenceBreachNotification geofenceBreachNotification) { + onGeofenceBreachCb(geofenceBreachNotification); + }; + + locationCallbacks.geofenceStatusCb = + [this](GeofenceStatusNotification geofenceStatusNotification) { + onGeofenceStatusCb(geofenceStatusNotification); + }; + } + + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms) +{ + LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__, + geofence_id, latitude, longitude, radius_meters, + last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms); + + GeofenceOption options; + memset(&options, 0, sizeof(GeofenceOption)); + options.size = sizeof(GeofenceOption); + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + options.breachTypeMask |= GEOFENCE_BREACH_EXIT_BIT; + options.responsiveness = notification_responsiveness_ms; + + GeofenceInfo data; + data.size = sizeof(GeofenceInfo); + data.latitude = latitude; + data.longitude = longitude; + data.radius = radius_meters; + + LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data); + if (LOCATION_ERROR_SUCCESS != err) { + onAddGeofencesCb(1, &err, &geofence_id); + } +} + +void GeofenceAPIClient::geofencePause(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIPauseGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions); + GeofenceBreachTypeMask mask = 0; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED) + mask |= GEOFENCE_BREACH_ENTER_BIT; + if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED) + mask |= GEOFENCE_BREACH_EXIT_BIT; + locAPIResumeGeofences(1, &geofence_id, &mask); +} + +void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id); + locAPIRemoveGeofences(1, &geofence_id); +} + +void GeofenceAPIClient::geofenceRemoveAll() +{ + LOC_LOGD("%s]", __FUNCTION__); + // TODO locAPIRemoveAllGeofences(); +} + +// callbacks +void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceBreachNotification.count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < geofenceBreachNotification.count; i++) { + GnssLocation gnssLocation; + convertGnssLocation(geofenceBreachNotification.location, gnssLocation); + + IGnssGeofenceCallback::GeofenceTransition transition; + if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER) + transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED; + else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT) + transition = IGnssGeofenceCallback::GeofenceTransition::EXITED; + else { + // continue with other breach if transition is + // nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED + continue; + } + + auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb( + geofenceBreachNotification.ids[i], gnssLocation, transition, + static_cast(geofenceBreachNotification.timestamp)); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available); + if (mGnssGeofencingCbIface != nullptr) { + IGnssGeofenceCallback::GeofenceAvailability status = + IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE; + if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) { + status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE; + } + GnssLocation gnssLocation; + memset(&gnssLocation, 0, sizeof(GnssLocation)); + auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_EXISTS) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS; + auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) +{ + LOC_LOGD("%s]: (%zu)", __FUNCTION__, count); + if (mGnssGeofencingCbIface != nullptr) { + for (size_t i = 0; i < count; i++) { + IGnssGeofenceCallback::GeofenceStatus status = + IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC; + if (errors[i] == LOCATION_ERROR_SUCCESS) + status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS; + else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN) + status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN; + auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/location_api/GeofenceAPIClient.h b/gps/android/2.1/location_api/GeofenceAPIClient.h new file mode 100755 index 0000000..9ed289f --- /dev/null +++ b/gps/android/2.1/location_api/GeofenceAPIClient.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GEOFENCE_API_CLINET_H +#define GEOFENCE_API_CLINET_H + + +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::sp; + +class GeofenceAPIClient : public LocationAPIClientBase +{ +public: + GeofenceAPIClient(const sp& callback); + + void geofenceAdd(uint32_t geofence_id, double latitude, double longitude, + double radius_meters, int32_t last_transition, int32_t monitor_transitions, + uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms); + void geofencePause(uint32_t geofence_id); + void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions); + void geofenceRemove(uint32_t geofence_id); + void geofenceRemoveAll(); + + // callbacks + void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final; + void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final; + void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final; + +private: + virtual ~GeofenceAPIClient() = default; + + sp mGnssGeofencingCbIface; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GEOFENCE_API_CLINET_H diff --git a/gps/android/2.1/location_api/GnssAPIClient.cpp b/gps/android/2.1/location_api/GnssAPIClient.cpp new file mode 100644 index 0000000..07f617d --- /dev/null +++ b/gps/android/2.1/location_api/GnssAPIClient.cpp @@ -0,0 +1,864 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GnssAPIClient" +#define SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC (590 * 60 * 60 * 1000) // 590 hours + +#include +#include +#include + +#include "LocationUtil.h" +#include "GnssAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_1::IGnss; +using ::android::hardware::gnss::V2_1::IGnssCallback; +using ::android::hardware::gnss::V1_0::IGnssNiCallback; +using ::android::hardware::gnss::V2_0::GnssLocation; + +static void convertGnssSvStatus(GnssSvNotification& in, V1_0::IGnssCallback::GnssSvStatus& out); +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out); +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out); + +GnssAPIClient::GnssAPIClient(const sp& gpsCb, + const sp& niCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false), + mTracking(false), + mGnssCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + initLocationOptions(); + gnssUpdateCallbacks(gpsCb, niCb); +} + +GnssAPIClient::GnssAPIClient(const sp& gpsCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false), + mTracking(false), + mGnssCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + initLocationOptions(); + gnssUpdateCallbacks_2_0(gpsCb); +} + +GnssAPIClient::GnssAPIClient(const sp& gpsCb) : + LocationAPIClientBase(), + mGnssCbIface(nullptr), + mGnssNiCbIface(nullptr), + mControlClient(new LocationAPIControlClient()), + mLocationCapabilitiesMask(0), + mLocationCapabilitiesCached(false), + mTracking(false), + mGnssCbIface_2_1(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + initLocationOptions(); + gnssUpdateCallbacks_2_1(gpsCb); +} + +GnssAPIClient::~GnssAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient) { + delete mControlClient; + mControlClient = nullptr; + } +} + +void GnssAPIClient::initLocationOptions() +{ + // set default LocationOptions. + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = 1000; + mTrackingOptions.minDistance = 0; + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; +} + +void GnssAPIClient::setCallbacks() +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.trackingCb = [this](Location location) { + onTrackingCb(location); + }; + + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + if (mGnssNiCbIface != nullptr) { + loc_core::ContextBase* context = + loc_core::LocContext::getLocContext(loc_core::LocContext::mLocationHalName); + if (!context->hasAgpsExtendedCapabilities()) { + LOC_LOGD("Registering NI CB"); + locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotify) { + onGnssNiCb(id, gnssNiNotify); + }; + } + } + + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) { + onGnssSvCb(gnssSvNotification); + }; + + locationCallbacks.gnssNmeaCb = nullptr; + locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) { + onGnssNmeaCb(gnssNmeaNotification); + }; + + locationCallbacks.gnssMeasurementsCb = nullptr; + + locAPISetCallbacks(locationCallbacks); +} + +// for GpsInterface +void GnssAPIClient::gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb) +{ + LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb); + + mMutex.lock(); + mGnssCbIface = gpsCb; + mGnssNiCbIface = niCb; + mMutex.unlock(); + + if (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr) { + setCallbacks(); + } +} + +void GnssAPIClient::gnssUpdateCallbacks_2_0(const sp& gpsCb) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + mMutex.lock(); + mGnssCbIface_2_0 = gpsCb; + mMutex.unlock(); + + if (mGnssCbIface_2_0 != nullptr) { + setCallbacks(); + } +} + +void GnssAPIClient::gnssUpdateCallbacks_2_1(const sp& gpsCb) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb); + + mMutex.lock(); + mGnssCbIface_2_1 = gpsCb; + mMutex.unlock(); + + if (mGnssCbIface_2_1 != nullptr) { + setCallbacks(); + } +} + +bool GnssAPIClient::gnssStart() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + + mMutex.lock(); + mTracking = true; + mMutex.unlock(); + + bool retVal = true; + locAPIStartTracking(mTrackingOptions); + return retVal; +} + +bool GnssAPIClient::gnssStop() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + + mMutex.lock(); + mTracking = false; + mMutex.unlock(); + + bool retVal = true; + locAPIStopTracking(); + return retVal; +} + +bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode, + IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%d %d %d %d %d %d %d)", __FUNCTION__, + (int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, + preferredTimeMs, (int)powerMode, timeBetweenMeasurement); + bool retVal = true; + memset(&mTrackingOptions, 0, sizeof(TrackingOptions)); + mTrackingOptions.size = sizeof(TrackingOptions); + mTrackingOptions.minInterval = minIntervalMs; + if (IGnss::GnssPositionMode::MS_ASSISTED == mode || + IGnss::GnssPositionRecurrence::RECURRENCE_SINGLE == recurrence) { + // We set a very large interval to simulate SINGLE mode. Once we report a fix, + // the caller should take the responsibility to stop the session. + // For MSA, we always treat it as SINGLE mode. + mTrackingOptions.minInterval = SINGLE_SHOT_MIN_TRACKING_INTERVAL_MSEC; + } + if (mode == IGnss::GnssPositionMode::STANDALONE) + mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE; + else if (mode == IGnss::GnssPositionMode::MS_BASED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSB; + else if (mode == IGnss::GnssPositionMode::MS_ASSISTED) + mTrackingOptions.mode = GNSS_SUPL_MODE_MSA; + else { + LOC_LOGD("%s]: invalid GnssPositionMode: %d", __FUNCTION__, (int)mode); + retVal = false; + } + if (GNSS_POWER_MODE_INVALID != powerMode) { + mTrackingOptions.powerMode = powerMode; + mTrackingOptions.tbm = timeBetweenMeasurement; + } + locAPIUpdateTrackingOptions(mTrackingOptions); + return retVal; +} + +// for GpsNiInterface +void GnssAPIClient::gnssNiRespond(int32_t notifId, + IGnssNiCallback::GnssUserResponseType userResponse) +{ + LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast(userResponse)); + GnssNiResponse data; + switch (userResponse) { + case IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT: + data = GNSS_NI_RESPONSE_ACCEPT; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY: + data = GNSS_NI_RESPONSE_DENY; + break; + case IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP: + data = GNSS_NI_RESPONSE_NO_RESPONSE; + break; + default: + data = GNSS_NI_RESPONSE_IGNORE; + break; + } + + locAPIGnssNiResponse(notifId, data); +} + +// these apis using LocationAPIControlClient +void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags) +{ + LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags); + if (mControlClient == nullptr) { + return; + } + GnssAidingData data; + memset(&data, 0, sizeof (GnssAidingData)); + data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS_BIT | + GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT | + GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT | + GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT | + GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT | + GNSS_AIDING_DATA_SV_TYPE_NAVIC_BIT; + data.posEngineMask = STANDARD_POSITIONING_ENGINE; + + if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL) + data.deleteAll = true; + else { + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS) + data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC) + data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION) + data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME) + data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO) + data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC) + data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH) + data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR) + data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER) + data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA) + data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI) + data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI_BIT; + if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO) + data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB_BIT; + } + mControlClient->locAPIGnssDeleteAidingData(data); +} + +void GnssAPIClient::gnssEnable(LocationTechnologyType techType) +{ + LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIEnable(techType); +} + +void GnssAPIClient::gnssDisable() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIDisable(); +} + +void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig) +{ + LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags); + if (mControlClient == nullptr) { + return; + } + mControlClient->locAPIGnssUpdateConfig(gnssConfig); +} + +void GnssAPIClient::requestCapabilities() { + // only send capablities if it's already cached, otherwise the first time LocationAPI + // is initialized, capabilities will be sent by LocationAPI + if (mLocationCapabilitiesCached) { + onCapabilitiesCb(mLocationCapabilitiesMask); + } +} + +// callbacks +void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) +{ + LOC_LOGD("%s]: (%" PRIu64 ")", __FUNCTION__, capabilitiesMask); + mLocationCapabilitiesMask = capabilitiesMask; + mLocationCapabilitiesCached = true; + + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + mMutex.unlock(); + + if (gnssCbIface_2_1 != nullptr ||gnssCbIface_2_0 != nullptr || gnssCbIface != nullptr) { + + uint32_t antennaInfoVectorSize = 0; + uint32_t data = 0; + loc_param_s_type ant_info_vector_table[] = + { + { "ANTENNA_INFO_VECTOR_SIZE", &antennaInfoVectorSize, NULL, 'n' } + }; + UTIL_READ_CONF(LOC_PATH_ANT_CORR, ant_info_vector_table); + + if (0 != antennaInfoVectorSize) { + data |= V2_1::IGnssCallback::Capabilities::ANTENNA_INFO; + } + + if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) || + (capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT)) + data |= IGnssCallback::Capabilities::SCHEDULING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT) + data |= V1_0::IGnssCallback::Capabilities::GEOFENCING; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) + data |= V1_0::IGnssCallback::Capabilities::MEASUREMENTS; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT) + data |= IGnssCallback::Capabilities::MSB; + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT) + data |= IGnssCallback::Capabilities::MSA; + if (capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) + data |= IGnssCallback::Capabilities::LOW_POWER_MODE; + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT) + data |= IGnssCallback::Capabilities::SATELLITE_BLACKLIST; + if (capabilitiesMask & LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT) + data |= V2_0::IGnssCallback::Capabilities::MEASUREMENT_CORRECTIONS; + + IGnssCallback::GnssSystemInfo gnssInfo = { .yearOfHw = 2015 }; + + if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) { + gnssInfo.yearOfHw++; // 2016 + if (capabilitiesMask & LOCATION_CAPABILITIES_DEBUG_NMEA_BIT) { + gnssInfo.yearOfHw++; // 2017 + if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT || + capabilitiesMask & LOCATION_CAPABILITIES_AGPM_BIT) { + gnssInfo.yearOfHw++; // 2018 + if (capabilitiesMask & LOCATION_CAPABILITIES_PRIVACY_BIT) { + gnssInfo.yearOfHw++; // 2019 + if (capabilitiesMask & LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT) { + gnssInfo.yearOfHw++; // 2020 + } + } + } + } + } + LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw); + + if (gnssCbIface_2_1 != nullptr) { + auto r = gnssCbIface_2_1->gnssSetCapabilitiesCb_2_1(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitiesCb_2_1 description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_1->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssSetCapabilitiesCb_2_0(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitiesCb_2_0 description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssSetCapabilitesCb(data); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssSetSystemInfoCb(gnssInfo); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s", + __func__, r.description().c_str()); + } + } + + } + +} + +void GnssAPIClient::onTrackingCb(Location location) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + bool isTracking = mTracking; + mMutex.unlock(); + + LOC_LOGD("%s]: (flags: %02x isTracking: %d)", __FUNCTION__, location.flags, isTracking); + + if (!isTracking) { + return; + } + + if (gnssCbIface_2_1 != nullptr) { + V2_0::GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface_2_1->gnssLocationCb_2_0(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb_2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + V2_0::GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface_2_0->gnssLocationCb_2_0(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb_2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + V1_0::GnssLocation gnssLocation; + convertGnssLocation(location, gnssLocation); + auto r = gnssCbIface->gnssLocationCb(gnssLocation); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationCb description=%s", + __func__, r.description().c_str()); + } + } else { + LOC_LOGW("%s] No GNSS Interface ready for gnssLocationCb ", __FUNCTION__); + } + +} + +void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) +{ + LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id); + mMutex.lock(); + auto gnssNiCbIface(mGnssNiCbIface); + mMutex.unlock(); + + if (gnssNiCbIface == nullptr) { + LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__); + return; + } + + IGnssNiCallback::GnssNiNotification notificationGnss = {}; + + notificationGnss.notificationId = id; + + if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL; + else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE) + notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE; + else if (gnssNiNotification.type == GNSS_NI_TYPE_EMERGENCY_SUPL) + notificationGnss.niType = IGnssNiCallback::GnssNiType::EMERGENCY_SUPL; + + if (gnssNiNotification.options & GNSS_NI_OPTIONS_NOTIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_VERIFICATION_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY; + if (gnssNiNotification.options & GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT) + notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE; + + notificationGnss.timeoutSec = gnssNiNotification.timeout; + + if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY; + else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE || + gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE) + notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP; + + notificationGnss.requestorId = gnssNiNotification.requestor; + + notificationGnss.notificationMessage = gnssNiNotification.message; + + if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.requestorIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_NONE; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8; + else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2) + notificationGnss.notificationIdEncoding = + IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2; + + gnssNiCbIface->niNotifyCb(notificationGnss); +} + +void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification) +{ + LOC_LOGD("%s]: (count: %u)", __FUNCTION__, gnssSvNotification.count); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + mMutex.unlock(); + + if (gnssCbIface_2_1 != nullptr) { + hidl_vec svInfoList; + convertGnssSvStatus(gnssSvNotification, svInfoList); + auto r = gnssCbIface_2_1->gnssSvStatusCb_2_1(svInfoList); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb_2_1 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + hidl_vec svInfoList; + convertGnssSvStatus(gnssSvNotification, svInfoList); + auto r = gnssCbIface_2_0->gnssSvStatusCb_2_0(svInfoList); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb_2_0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + V1_0::IGnssCallback::GnssSvStatus svStatus; + convertGnssSvStatus(gnssSvNotification, svStatus); + auto r = gnssCbIface->gnssSvStatusCb(svStatus); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssSvStatusCb description=%s", + __func__, r.description().c_str()); + } + } +} + +void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) +{ + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + mMutex.unlock(); + + if (gnssCbIface != nullptr || gnssCbIface_2_0 != nullptr| gnssCbIface_2_1 != nullptr) { + const std::string s(gnssNmeaNotification.nmea); + std::stringstream ss(s); + std::string each; + while(std::getline(ss, each, '\n')) { + each += '\n'; + android::hardware::hidl_string nmeaString; + nmeaString.setToExternal(each.c_str(), each.length()); + if (gnssCbIface_2_1 != nullptr) { + auto r = gnssCbIface_2_1->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssCbIface_2_1 nmea=%s length=%u description=%s", + __func__, gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssCbIface_2_0 nmea=%s length=%u description=%s", + __func__, gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssNmeaCb( + static_cast(gnssNmeaNotification.timestamp), nmeaString); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%u description=%s", + __func__, gnssNmeaNotification.nmea, gnssNmeaNotification.length, + r.description().c_str()); + } + } + } + } +} + +void GnssAPIClient::onStartTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS) { + if (gnssCbIface_2_1 != nullptr) { + auto r = gnssCbIface_2_1->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_1->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s", + __func__, r.description().c_str()); + } + } + } +} + +void GnssAPIClient::onStopTrackingCb(LocationError error) +{ + LOC_LOGD("%s]: (%d)", __FUNCTION__, error); + mMutex.lock(); + auto gnssCbIface(mGnssCbIface); + auto gnssCbIface_2_0(mGnssCbIface_2_0); + auto gnssCbIface_2_1(mGnssCbIface_2_1); + mMutex.unlock(); + + if (error == LOCATION_ERROR_SUCCESS) { + if (gnssCbIface_2_1 != nullptr) { + auto r = gnssCbIface_2_1->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_1->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + } else if (gnssCbIface_2_0 != nullptr) { + auto r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface_2_0->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb 2_0 ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + + } else if (gnssCbIface != nullptr) { + auto r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s", + __func__, r.description().c_str()); + } + r = gnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, V1_0::IGnssCallback::GnssSvStatus& out) +{ + memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus)); + out.numSvs = in.count; + if (out.numSvs > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many satellites %u. Clamps to %d.", + __FUNCTION__, out.numSvs, V1_0::GnssMax::SVS_COUNT); + out.numSvs = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.numSvs; i++) { + convertGnssSvid(in.gnssSvs[i], out.gnssSvList[i].svid); + convertGnssConstellationType(in.gnssSvs[i].type, out.gnssSvList[i].constellation); + out.gnssSvList[i].cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + out.gnssSvList[i].elevationDegrees = in.gnssSvs[i].elevation; + out.gnssSvList[i].azimuthDegrees = in.gnssSvs[i].azimuth; + out.gnssSvList[i].carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + out.gnssSvList[i].svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + out.gnssSvList[i].svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out) +{ + out.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssSvid(in.gnssSvs[i], out[i].v1_0.svid); + out[i].v1_0.cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + out[i].v1_0.elevationDegrees = in.gnssSvs[i].elevation; + out[i].v1_0.azimuthDegrees = in.gnssSvs[i].azimuth; + out[i].v1_0.carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + out[i].v1_0.svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + out[i].v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + + convertGnssConstellationType(in.gnssSvs[i].type, out[i].constellation); + } +} + +static void convertGnssSvStatus(GnssSvNotification& in, + hidl_vec& out) +{ + out.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssSvid(in.gnssSvs[i], out[i].v2_0.v1_0.svid); + out[i].v2_0.v1_0.cN0Dbhz = in.gnssSvs[i].cN0Dbhz; + out[i].v2_0.v1_0.elevationDegrees = in.gnssSvs[i].elevation; + out[i].v2_0.v1_0.azimuthDegrees = in.gnssSvs[i].azimuth; + out[i].v2_0.v1_0.carrierFrequencyHz = in.gnssSvs[i].carrierFrequencyHz; + out[i].v2_0.v1_0.svFlag = static_cast(IGnssCallback::GnssSvFlags::NONE); + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT) + out[i].v2_0.v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT) + out[i].v2_0.v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT) + out[i].v2_0.v1_0.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX; + if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT) + out[i].v2_0.v1_0.svFlag |= IGnssCallback::GnssSvFlags::HAS_CARRIER_FREQUENCY; + + convertGnssConstellationType(in.gnssSvs[i].type, out[i].v2_0.constellation); + out[i].basebandCN0DbHz = in.gnssSvs[i].basebandCarrierToNoiseDbHz; + } +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/location_api/GnssAPIClient.h b/gps/android/2.1/location_api/GnssAPIClient.h new file mode 100755 index 0000000..c4dbe9a --- /dev/null +++ b/gps/android/2.1/location_api/GnssAPIClient.h @@ -0,0 +1,118 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GNSS_API_CLINET_H +#define GNSS_API_CLINET_H + + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::sp; + +class GnssAPIClient : public LocationAPIClientBase +{ +public: + GnssAPIClient(const sp& gpsCb, + const sp& niCb); + GnssAPIClient(const sp& gpsCb); + GnssAPIClient(const sp& gpsCb); + GnssAPIClient(const GnssAPIClient&) = delete; + GnssAPIClient& operator=(const GnssAPIClient&) = delete; + + // for GpsInterface + void gnssUpdateCallbacks(const sp& gpsCb, + const sp& niCb); + void gnssUpdateCallbacks_2_0(const sp& gpsCb); + void gnssUpdateCallbacks_2_1(const sp& gpsCb); + bool gnssStart(); + bool gnssStop(); + bool gnssSetPositionMode(V1_0::IGnss::GnssPositionMode mode, + V1_0::IGnss::GnssPositionRecurrence recurrence, + uint32_t minIntervalMs, + uint32_t preferredAccuracyMeters, + uint32_t preferredTimeMs, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = 0); + + // for GpsNiInterface + void gnssNiRespond(int32_t notifId, V1_0::IGnssNiCallback::GnssUserResponseType userResponse); + + // these apis using LocationAPIControlClient + void gnssDeleteAidingData(V1_0::IGnss::GnssAidingData aidingDataFlags); + void gnssEnable(LocationTechnologyType techType); + void gnssDisable(); + void gnssConfigurationUpdate(const GnssConfig& gnssConfig); + + inline LocationCapabilitiesMask gnssGetCapabilities() const { + return mLocationCapabilitiesMask; + } + void requestCapabilities(); + + // callbacks we are interested in + void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final; + void onTrackingCb(Location location) final; + void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final; + void onGnssSvCb(GnssSvNotification gnssSvNotification) final; + void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final; + + void onStartTrackingCb(LocationError error) final; + void onStopTrackingCb(LocationError error) final; + +private: + virtual ~GnssAPIClient(); + void setCallbacks(); + void initLocationOptions(); + + sp mGnssCbIface; + sp mGnssNiCbIface; + std::mutex mMutex; + LocationAPIControlClient* mControlClient; + LocationCapabilitiesMask mLocationCapabilitiesMask; + bool mLocationCapabilitiesCached; + TrackingOptions mTrackingOptions; + bool mTracking; + sp mGnssCbIface_2_0; + sp mGnssCbIface_2_1; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // GNSS_API_CLINET_H diff --git a/gps/android/2.1/location_api/LocationUtil.cpp b/gps/android/2.1/location_api/LocationUtil.cpp new file mode 100644 index 0000000..5154e70 --- /dev/null +++ b/gps/android/2.1/location_api/LocationUtil.cpp @@ -0,0 +1,405 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V2_0::GnssLocation; +using ::android::hardware::gnss::V2_0::ElapsedRealtimeFlags; +using ::android::hardware::gnss::V2_0::GnssConstellationType; +using ::android::hardware::gnss::V1_0::GnssLocationFlags; +using ::android::hardware::gnss::measurement_corrections::V1_0::GnssSingleSatCorrectionFlags; + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out) +{ + memset(&out, 0, sizeof(V1_0::GnssLocation)); + if (in.flags & LOCATION_HAS_LAT_LONG_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG; + out.latitudeDegrees = in.latitude; + out.longitudeDegrees = in.longitude; + } + if (in.flags & LOCATION_HAS_ALTITUDE_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE; + out.altitudeMeters = in.altitude; + } + if (in.flags & LOCATION_HAS_SPEED_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED; + out.speedMetersPerSec = in.speed; + } + if (in.flags & LOCATION_HAS_BEARING_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING; + out.bearingDegrees = in.bearing; + } + if (in.flags & LOCATION_HAS_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY; + out.horizontalAccuracyMeters = in.accuracy; + } + if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY; + out.verticalAccuracyMeters = in.verticalAccuracy; + } + if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY; + out.speedAccuracyMetersPerSecond = in.speedAccuracy; + } + if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT) { + out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY; + out.bearingAccuracyDegrees = in.bearingAccuracy; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(Location& in, V2_0::GnssLocation& out) +{ + memset(&out, 0, sizeof(V2_0::GnssLocation)); + convertGnssLocation(in, out.v1_0); + + if (in.flags & LOCATION_HAS_ELAPSED_REAL_TIME) { + out.elapsedRealtime.flags |= ElapsedRealtimeFlags::HAS_TIMESTAMP_NS; + out.elapsedRealtime.timestampNs = in.elapsedRealTime; + out.elapsedRealtime.flags |= ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS; + out.elapsedRealtime.timeUncertaintyNs = in.elapsedRealTimeUnc; + LOC_LOGd("out.elapsedRealtime.timestampNs=%" PRIi64 "" + " out.elapsedRealtime.timeUncertaintyNs=%" PRIi64 "" + " out.elapsedRealtime.flags=0x%X", + out.elapsedRealtime.timestampNs, + out.elapsedRealtime.timeUncertaintyNs, out.elapsedRealtime.flags); + } +} + +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) { + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + out.latitude = in.latitudeDegrees; + out.longitude = in.longitudeDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) { + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + out.altitude = in.altitudeMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) { + out.flags |= LOCATION_HAS_SPEED_BIT; + out.speed = in.speedMetersPerSec; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { + out.flags |= LOCATION_HAS_BEARING_BIT; + out.bearing = in.bearingDegrees; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) { + out.flags |= LOCATION_HAS_ACCURACY_BIT; + out.accuracy = in.horizontalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + out.verticalAccuracy = in.verticalAccuracyMeters; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) { + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + out.speedAccuracy = in.speedAccuracyMetersPerSecond; + } + if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) { + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.bearingAccuracy = in.bearingAccuracyDegrees; + } + + out.timestamp = static_cast(in.timestamp); +} + +void convertGnssLocation(const V2_0::GnssLocation& in, Location& out) +{ + memset(&out, 0, sizeof(out)); + convertGnssLocation(in.v1_0, out); +} + +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = V1_0::GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = V1_0::GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = V1_0::GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = V1_0::GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = V1_0::GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = V1_0::GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = V1_0::GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssConstellationType(GnssSvType& in, V2_0::GnssConstellationType& out) +{ + switch(in) { + case GNSS_SV_TYPE_GPS: + out = V2_0::GnssConstellationType::GPS; + break; + case GNSS_SV_TYPE_SBAS: + out = V2_0::GnssConstellationType::SBAS; + break; + case GNSS_SV_TYPE_GLONASS: + out = V2_0::GnssConstellationType::GLONASS; + break; + case GNSS_SV_TYPE_QZSS: + out = V2_0::GnssConstellationType::QZSS; + break; + case GNSS_SV_TYPE_BEIDOU: + out = V2_0::GnssConstellationType::BEIDOU; + break; + case GNSS_SV_TYPE_GALILEO: + out = V2_0::GnssConstellationType::GALILEO; + break; + case GNSS_SV_TYPE_NAVIC: + out = V2_0::GnssConstellationType::IRNSS; + break; + case GNSS_SV_TYPE_UNKNOWN: + default: + out = V2_0::GnssConstellationType::UNKNOWN; + break; + } +} + +void convertGnssSvid(GnssSv& in, int16_t& out) +{ + switch (in.type) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out) +{ + switch (in.svType) { + case GNSS_SV_TYPE_GPS: + out = in.svId; + break; + case GNSS_SV_TYPE_SBAS: + out = in.svId; + break; + case GNSS_SV_TYPE_GLONASS: + if (!isGloSlotUnknown(in.svId)) { // OSN is known + out = in.svId - GLO_SV_PRN_MIN + 1; + } else { // OSN is not known, report FCN + out = in.gloFrequency + 92; + } + break; + case GNSS_SV_TYPE_QZSS: + out = in.svId; + break; + case GNSS_SV_TYPE_BEIDOU: + out = in.svId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + out = in.svId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + out = in.svId - NAVIC_SV_PRN_MIN + 1; + break; + default: + out = in.svId; + break; + } +} + +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out) +{ + switch(in) { + case GNSS_EPH_TYPE_EPHEMERIS: + out = GnssDebug::SatelliteEphemerisType::EPHEMERIS; + break; + case GNSS_EPH_TYPE_ALMANAC: + out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY; + break; + case GNSS_EPH_TYPE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE; + break; + } +} + +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out) +{ + switch(in) { + case GNSS_EPH_SOURCE_DEMODULATED: + out = GnssDebug::SatelliteEphemerisSource::DEMODULATED; + break; + case GNSS_EPH_SOURCE_SUPL_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED; + break; + case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED: + out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED; + break; + case GNSS_EPH_SOURCE_LOCAL: + case GNSS_EPH_SOURCE_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisSource::OTHER; + break; + } +} + +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out) +{ + switch(in) { + case GNSS_EPH_HEALTH_GOOD: + out = GnssDebug::SatelliteEphemerisHealth::GOOD; + break; + case GNSS_EPH_HEALTH_BAD: + out = GnssDebug::SatelliteEphemerisHealth::BAD; + break; + case GNSS_EPH_HEALTH_UNKNOWN: + default: + out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN; + break; + } +} + +void convertSingleSatCorrections(const SingleSatCorrection& in, GnssSingleSatCorrection& out) +{ + out.flags = GNSS_MEAS_CORR_UNKNOWN_BIT; + if (in.singleSatCorrectionFlags & (GnssSingleSatCorrectionFlags::HAS_SAT_IS_LOS_PROBABILITY)) { + out.flags |= GNSS_MEAS_CORR_HAS_SAT_IS_LOS_PROBABILITY_BIT; + } + if (in.singleSatCorrectionFlags & (GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH)) { + out.flags |= GNSS_MEAS_CORR_HAS_EXCESS_PATH_LENGTH_BIT; + } + if (in.singleSatCorrectionFlags & (GnssSingleSatCorrectionFlags::HAS_EXCESS_PATH_LENGTH_UNC)) { + out.flags |= GNSS_MEAS_CORR_HAS_EXCESS_PATH_LENGTH_UNC_BIT; + } + if (in.singleSatCorrectionFlags & (GnssSingleSatCorrectionFlags::HAS_REFLECTING_PLANE)) { + out.flags |= GNSS_MEAS_CORR_HAS_REFLECTING_PLANE_BIT; + } + switch (in.constellation) { + case (::android::hardware::gnss::V1_0::GnssConstellationType::GPS): + out.svType = GNSS_SV_TYPE_GPS; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::SBAS): + out.svType = GNSS_SV_TYPE_SBAS; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::GLONASS): + out.svType = GNSS_SV_TYPE_GLONASS; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::QZSS): + out.svType = GNSS_SV_TYPE_QZSS; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::BEIDOU): + out.svType = GNSS_SV_TYPE_BEIDOU; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::GALILEO): + out.svType = GNSS_SV_TYPE_GALILEO; + break; + case (::android::hardware::gnss::V1_0::GnssConstellationType::UNKNOWN): + default: + out.svType = GNSS_SV_TYPE_UNKNOWN; + break; + } + out.svId = in.svid; + out.carrierFrequencyHz = in.carrierFrequencyHz; + out.probSatIsLos = in.probSatIsLos; + out.excessPathLengthMeters = in.excessPathLengthMeters; + out.excessPathLengthUncertaintyMeters = in.excessPathLengthUncertaintyMeters; + + out.reflectingPlane.latitudeDegrees = in.reflectingPlane.latitudeDegrees; + out.reflectingPlane.longitudeDegrees = in.reflectingPlane.longitudeDegrees; + out.reflectingPlane.altitudeMeters = in.reflectingPlane.altitudeMeters; + out.reflectingPlane.azimuthDegrees = in.reflectingPlane.azimuthDegrees; +} + +void convertMeasurementCorrections(const MeasurementCorrectionsV1_0& in, + GnssMeasurementCorrections& out) +{ + memset(&out, 0, sizeof(GnssMeasurementCorrections)); + out.latitudeDegrees = in.latitudeDegrees; + out.longitudeDegrees = in.longitudeDegrees; + out.altitudeMeters = in.altitudeMeters; + out.horizontalPositionUncertaintyMeters = in.horizontalPositionUncertaintyMeters; + out.verticalPositionUncertaintyMeters = in.verticalPositionUncertaintyMeters; + out.toaGpsNanosecondsOfWeek = in.toaGpsNanosecondsOfWeek; + + for (int i = 0; i < in.satCorrections.size(); i++) { + GnssSingleSatCorrection gnssSingleSatCorrection = {}; + + convertSingleSatCorrections(in.satCorrections[i], gnssSingleSatCorrection); + out.satCorrections.push_back(gnssSingleSatCorrection); + } +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/location_api/LocationUtil.h b/gps/android/2.1/location_api/LocationUtil.h new file mode 100644 index 0000000..2d95a2d --- /dev/null +++ b/gps/android/2.1/location_api/LocationUtil.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOCATION_UTIL_H +#define LOCATION_UTIL_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using MeasurementCorrectionsV1_0 = + ::android::hardware::gnss::measurement_corrections::V1_0::MeasurementCorrections; +using ::android::hardware::gnss::measurement_corrections::V1_0::SingleSatCorrection; + +void convertGnssLocation(Location& in, V1_0::GnssLocation& out); +void convertGnssLocation(Location& in, V2_0::GnssLocation& out); +void convertGnssLocation(const V1_0::GnssLocation& in, Location& out); +void convertGnssLocation(const V2_0::GnssLocation& in, Location& out); +void convertGnssConstellationType(GnssSvType& in, V1_0::GnssConstellationType& out); +void convertGnssConstellationType(GnssSvType& in, V2_0::GnssConstellationType& out); +void convertGnssSvid(GnssSv& in, int16_t& out); +void convertGnssSvid(GnssMeasurementsData& in, int16_t& out); +void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out); +void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out); +void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out); +void convertSingleSatCorrections(const SingleSatCorrection& in, GnssSingleSatCorrection& out); +void convertMeasurementCorrections(const MeasurementCorrectionsV1_0& in, + GnssMeasurementCorrections& out); + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // LOCATION_UTIL_H diff --git a/gps/android/2.1/location_api/MeasurementAPIClient.cpp b/gps/android/2.1/location_api/MeasurementAPIClient.cpp new file mode 100644 index 0000000..0028074 --- /dev/null +++ b/gps/android/2.1/location_api/MeasurementAPIClient.cpp @@ -0,0 +1,642 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_MeasurementAPIClient" + +#include +#include +#include + +#include "LocationUtil.h" +#include "MeasurementAPIClient.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::gnss::V1_0::IGnssMeasurement; +using ::android::hardware::gnss::V2_0::IGnssMeasurementCallback; + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + V1_1::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_2_0(GnssMeasurementsNotification& in, + V2_0::IGnssMeasurementCallback::GnssData& out); +static void convertGnssData_2_1(GnssMeasurementsNotification& in, + V2_1::IGnssMeasurementCallback::GnssData& out); +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out); +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out); +static void convertGnssClock_2_1(GnssMeasurementsClock& in, + V2_1::IGnssMeasurementCallback::GnssClock& out); +static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& inCodeType, + char* inOtherCodeTypeName, + ::android::hardware::hidl_string& out); +static void convertGnssMeasurementsAccumulatedDeltaRangeState(GnssMeasurementsAdrStateMask& in, + ::android::hardware::hidl_bitfield + & out); +static void convertGnssMeasurementsState(GnssMeasurementsStateMask& in, + ::android::hardware::hidl_bitfield + & out); +static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in, + ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtimeNanos); + +MeasurementAPIClient::MeasurementAPIClient() : + mGnssMeasurementCbIface(nullptr), + mGnssMeasurementCbIface_1_1(nullptr), + mGnssMeasurementCbIface_2_0(nullptr), + mGnssMeasurementCbIface_2_1(nullptr), + mTracking(false) +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +MeasurementAPIClient::~MeasurementAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +void MeasurementAPIClient::clearInterfaces() +{ + mGnssMeasurementCbIface = nullptr; + mGnssMeasurementCbIface_1_1 = nullptr; + mGnssMeasurementCbIface_2_0 = nullptr; + mGnssMeasurementCbIface_2_1 = nullptr; +} + +// for GpsInterface +Return +MeasurementAPIClient::measurementSetCallback(const sp& callback) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface = callback; + mMutex.unlock(); + + return startTracking(); +} + +Return +MeasurementAPIClient::measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface_1_1 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} + +Return +MeasurementAPIClient::measurementSetCallback_2_0( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface_2_0 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} + +Return MeasurementAPIClient::measurementSetCallback_2_1( + const sp& callback, + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) { + LOC_LOGD("%s]: (%p) (powermode: %d) (tbm: %d)", + __FUNCTION__, &callback, (int)powerMode, timeBetweenMeasurement); + + mMutex.lock(); + clearInterfaces(); + mGnssMeasurementCbIface_2_1 = callback; + mMutex.unlock(); + + return startTracking(powerMode, timeBetweenMeasurement); +} +Return +MeasurementAPIClient::startTracking( + GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) +{ + LocationCallbacks locationCallbacks; + memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); + locationCallbacks.size = sizeof(LocationCallbacks); + + locationCallbacks.trackingCb = nullptr; + locationCallbacks.batchingCb = nullptr; + locationCallbacks.geofenceBreachCb = nullptr; + locationCallbacks.geofenceStatusCb = nullptr; + locationCallbacks.gnssLocationInfoCb = nullptr; + locationCallbacks.gnssNiCb = nullptr; + locationCallbacks.gnssSvCb = nullptr; + locationCallbacks.gnssNmeaCb = nullptr; + + locationCallbacks.gnssMeasurementsCb = nullptr; + if (mGnssMeasurementCbIface_2_1 != nullptr || + mGnssMeasurementCbIface_2_0 != nullptr || + mGnssMeasurementCbIface_1_1 != nullptr || + mGnssMeasurementCbIface != nullptr) { + locationCallbacks.gnssMeasurementsCb = + [this](GnssMeasurementsNotification gnssMeasurementsNotification) { + onGnssMeasurementsCb(gnssMeasurementsNotification); + }; + } + + locAPISetCallbacks(locationCallbacks); + + TrackingOptions options = {}; + memset(&options, 0, sizeof(TrackingOptions)); + options.size = sizeof(TrackingOptions); + options.minInterval = 1000; + options.mode = GNSS_SUPL_MODE_STANDALONE; + if (GNSS_POWER_MODE_INVALID != powerMode) { + options.powerMode = powerMode; + options.tbm = timeBetweenMeasurement; + } + + mTracking = true; + LOC_LOGD("%s]: start tracking session", __FUNCTION__); + locAPIStartTracking(options); + return IGnssMeasurement::GnssMeasurementStatus::SUCCESS; +} + +// for GpsMeasurementInterface +void MeasurementAPIClient::measurementClose() { + LOC_LOGD("%s]: ()", __FUNCTION__); + mTracking = false; + locAPIStopTracking(); +} + +// callbacks +void MeasurementAPIClient::onGnssMeasurementsCb( + GnssMeasurementsNotification gnssMeasurementsNotification) +{ + LOC_LOGD("%s]: (count: %u active: %d)", + __FUNCTION__, gnssMeasurementsNotification.count, mTracking); + if (mTracking) { + mMutex.lock(); + sp gnssMeasurementCbIface = nullptr; + sp gnssMeasurementCbIface_1_1 = nullptr; + sp gnssMeasurementCbIface_2_0 = nullptr; + sp gnssMeasurementCbIface_2_1 = nullptr; + if (mGnssMeasurementCbIface_2_1 != nullptr) { + gnssMeasurementCbIface_2_1 = mGnssMeasurementCbIface_2_1; + } else if (mGnssMeasurementCbIface_2_0 != nullptr) { + gnssMeasurementCbIface_2_0 = mGnssMeasurementCbIface_2_0; + } else if (mGnssMeasurementCbIface_1_1 != nullptr) { + gnssMeasurementCbIface_1_1 = mGnssMeasurementCbIface_1_1; + } else if (mGnssMeasurementCbIface != nullptr) { + gnssMeasurementCbIface = mGnssMeasurementCbIface; + } + mMutex.unlock(); + + if (gnssMeasurementCbIface_2_1 != nullptr) { + V2_1::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_2_1(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_2_1->gnssMeasurementCb_2_1(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface_2_0 != nullptr) { + V2_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_2_0(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_2_0->gnssMeasurementCb_2_0(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface_1_1 != nullptr) { + V1_1::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData_1_1(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface_1_1->gnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } else if (gnssMeasurementCbIface != nullptr) { + V1_0::IGnssMeasurementCallback::GnssData gnssData; + convertGnssData(gnssMeasurementsNotification, gnssData); + auto r = gnssMeasurementCbIface->GnssMeasurementCb(gnssData); + if (!r.isOk()) { + LOC_LOGE("%s] Error from GnssMeasurementCb description=%s", + __func__, r.description().c_str()); + } + } + } +} + +static void convertGnssMeasurement(GnssMeasurementsData& in, + V1_0::IGnssMeasurementCallback::GnssMeasurement& out) +{ + memset(&out, 0, sizeof(out)); + if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE; + if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT) + out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL; + convertGnssSvid(in, out.svid); + convertGnssConstellationType(in.svType, out.constellation); + out.timeOffsetNs = in.timeOffsetNs; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + out.receivedSvTimeInNs = in.receivedSvTimeNs; + out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs; + out.cN0DbHz = in.carrierToNoiseDbHz; + out.pseudorangeRateMps = in.pseudorangeRateMps; + out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out.accumulatedDeltaRangeState |= + IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + out.accumulatedDeltaRangeM = in.adrMeters; + out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters; + out.carrierFrequencyHz = in.carrierFrequencyHz; + out.carrierCycles = in.carrierCycles; + out.carrierPhase = in.carrierPhase; + out.carrierPhaseUncertainty = in.carrierPhaseUncertainty; + uint8_t indicator = + static_cast(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN); + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT; + if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT) + indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT; + out.multipathIndicator = + static_cast(indicator); + out.snrDb = in.signalToNoiseRatioDb; + out.agcLevelDb = in.agcLevelDb; +} + +static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out) +{ + memset(&out, 0, sizeof(out)); + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT; + if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT) + out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY; + out.leapSecond = in.leapSecond; + out.timeNs = in.timeNs; + out.timeUncertaintyNs = in.timeUncertaintyNs; + out.fullBiasNs = in.fullBiasNs; + out.biasNs = in.biasNs; + out.biasUncertaintyNs = in.biasUncertaintyNs; + out.driftNsps = in.driftNsps; + out.driftUncertaintyNsps = in.driftUncertaintyNsps; + out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount; +} + +static void convertGnssClock_2_1(GnssMeasurementsClock& in, + V2_1::IGnssMeasurementCallback::GnssClock& out) +{ + memset(&out, 0, sizeof(out)); + convertGnssClock(in, out.v1_0); + convertGnssConstellationType(in.referenceSignalTypeForIsb.svType, + out.referenceSignalTypeForIsb.constellation); + out.referenceSignalTypeForIsb.carrierFrequencyHz = + in.referenceSignalTypeForIsb.carrierFrequencyHz; + convertGnssMeasurementsCodeType(in.referenceSignalTypeForIsb.codeType, + in.referenceSignalTypeForIsb.otherCodeTypeName, + out.referenceSignalTypeForIsb.codeType); +} + +static void convertGnssData(GnssMeasurementsNotification& in, + V1_0::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurementCount = in.count; + if (out.measurementCount > static_cast(V1_0::GnssMax::SVS_COUNT)) { + LOC_LOGW("%s]: Too many measurement %u. Clamps to %d.", + __FUNCTION__, out.measurementCount, V1_0::GnssMax::SVS_COUNT); + out.measurementCount = static_cast(V1_0::GnssMax::SVS_COUNT); + } + for (size_t i = 0; i < out.measurementCount; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i]); + } + convertGnssClock(in.clock, out.clock); +} + +static void convertGnssData_1_1(GnssMeasurementsNotification& in, + V1_1::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_0); + convertGnssMeasurementsAccumulatedDeltaRangeState(in.measurements[i].adrStateMask, + out.measurements[i].accumulatedDeltaRangeState); + } + convertGnssClock(in.clock, out.clock); +} + +static void convertGnssData_2_0(GnssMeasurementsNotification& in, + V2_0::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + convertGnssMeasurement(in.measurements[i], out.measurements[i].v1_1.v1_0); + convertGnssConstellationType(in.measurements[i].svType, out.measurements[i].constellation); + convertGnssMeasurementsCodeType(in.measurements[i].codeType, + in.measurements[i].otherCodeTypeName, + out.measurements[i].codeType); + convertGnssMeasurementsAccumulatedDeltaRangeState(in.measurements[i].adrStateMask, + out.measurements[i].v1_1.accumulatedDeltaRangeState); + convertGnssMeasurementsState(in.measurements[i].stateMask, out.measurements[i].state); + } + convertGnssClock(in.clock, out.clock); + convertElapsedRealtimeNanos(in, out.elapsedRealtime); +} + +static void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& inCodeType, + char* inOtherCodeTypeName, ::android::hardware::hidl_string& out) +{ + memset(&out, 0, sizeof(out)); + switch(inCodeType) { + case GNSS_MEASUREMENTS_CODE_TYPE_A: + out = "A"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_B: + out = "B"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_C: + out = "C"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_I: + out = "I"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_L: + out = "L"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_M: + out = "M"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_P: + out = "P"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Q: + out = "Q"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_S: + out = "S"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_W: + out = "W"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_X: + out = "X"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Y: + out = "Y"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_Z: + out = "Z"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_N: + out = "N"; + break; + case GNSS_MEASUREMENTS_CODE_TYPE_OTHER: + default: + out = inOtherCodeTypeName; + break; + } +} + +static void convertGnssMeasurementsAccumulatedDeltaRangeState(GnssMeasurementsAdrStateMask& in, + ::android::hardware::hidl_bitfield + & out) +{ + memset(&out, 0, sizeof(out)); + if (in & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT) + out |= IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID; + if (in & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT) + out |= IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET; + if (in & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT) + out |= IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP; + if (in & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT) + out |= IGnssMeasurementCallback:: + GnssAccumulatedDeltaRangeState::ADR_STATE_HALF_CYCLE_RESOLVED; +} + +static void convertGnssMeasurementsState(GnssMeasurementsStateMask& in, + ::android::hardware::hidl_bitfield + & out) +{ + memset(&out, 0, sizeof(out)); + if (in & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK; + if (in & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED; + if (in & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS; + if (in & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED; + if (in & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK; + if (in & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK; + if (in & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC; + if (in & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_KNOWN; + if (in & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_KNOWN; + if (in & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT) + out |= IGnssMeasurementCallback::GnssMeasurementState::STATE_2ND_CODE_LOCK; +} + +static void convertGnssData_2_1(GnssMeasurementsNotification& in, + V2_1::IGnssMeasurementCallback::GnssData& out) +{ + memset(&out, 0, sizeof(out)); + out.measurements.resize(in.count); + for (size_t i = 0; i < in.count; i++) { + out.measurements[i].flags = 0; + convertGnssMeasurement(in.measurements[i], out.measurements[i].v2_0.v1_1.v1_0); + convertGnssConstellationType(in.measurements[i].svType, + out.measurements[i].v2_0.constellation); + convertGnssMeasurementsCodeType(in.measurements[i].codeType, + in.measurements[i].otherCodeTypeName, + out.measurements[i].v2_0.codeType); + convertGnssMeasurementsAccumulatedDeltaRangeState(in.measurements[i].adrStateMask, + out.measurements[i].v2_0.v1_1.accumulatedDeltaRangeState); + convertGnssMeasurementsState(in.measurements[i].stateMask, + out.measurements[i].v2_0.state); + out.measurements[i].basebandCN0DbHz = in.measurements[i].basebandCarrierToNoiseDbHz; + + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback:: + GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT) { + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_BIT) { + out.measurements[i].fullInterSignalBiasNs = in.measurements[i].fullInterSignalBiasNs; + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_FULL_ISB; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_UNCERTAINTY_BIT) { + out.measurements[i].fullInterSignalBiasUncertaintyNs = + in.measurements[i].fullInterSignalBiasUncertaintyNs; + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback:: + GnssMeasurementFlags::HAS_FULL_ISB_UNCERTAINTY; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_BIT) { + out.measurements[i].satelliteInterSignalBiasNs = + in.measurements[i].satelliteInterSignalBiasNs; + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SATELLITE_ISB; + } + if (in.measurements[i].flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_UNCERTAINTY_BIT) { + out.measurements[i].satelliteInterSignalBiasUncertaintyNs = + in.measurements[i].satelliteInterSignalBiasUncertaintyNs; + out.measurements[i].flags |= + V2_1::IGnssMeasurementCallback:: + GnssMeasurementFlags::HAS_SATELLITE_ISB_UNCERTAINTY; + } + } + convertGnssClock_2_1(in.clock, out.clock); + convertElapsedRealtimeNanos(in, out.elapsedRealtime); +} + +static void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in, + ::android::hardware::gnss::V2_0::ElapsedRealtime& elapsedRealtime) +{ + if (in.clock.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT) { + elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIMESTAMP_NS; + elapsedRealtime.timestampNs = in.clock.elapsedRealTime; + elapsedRealtime.flags |= V2_0::ElapsedRealtimeFlags::HAS_TIME_UNCERTAINTY_NS; + elapsedRealtime.timeUncertaintyNs = in.clock.elapsedRealTimeUnc; + LOC_LOGd("elapsedRealtime.timestampNs=%" PRIi64 "" + " elapsedRealtime.timeUncertaintyNs=%" PRIi64 " elapsedRealtime.flags=0x%X", + elapsedRealtime.timestampNs, + elapsedRealtime.timeUncertaintyNs, elapsedRealtime.flags); + } +} + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gps/android/2.1/location_api/MeasurementAPIClient.h b/gps/android/2.1/location_api/MeasurementAPIClient.h new file mode 100644 index 0000000..3e8805b --- /dev/null +++ b/gps/android/2.1/location_api/MeasurementAPIClient.h @@ -0,0 +1,96 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef MEASUREMENT_API_CLINET_H +#define MEASUREMENT_API_CLINET_H + +#include +#include +//#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_1 { +namespace implementation { + +using ::android::sp; + +class MeasurementAPIClient : public LocationAPIClientBase +{ +public: + MeasurementAPIClient(); + MeasurementAPIClient(const MeasurementAPIClient&) = delete; + MeasurementAPIClient& operator=(const MeasurementAPIClient&) = delete; + + // for GpsMeasurementInterface + Return measurementSetCallback( + const sp& callback); + Return measurementSetCallback_1_1( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + Return measurementSetCallback_2_0( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + Return measurementSetCallback_2_1( + const sp& callback, + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + void measurementClose(); + Return startTracking( + GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID, + uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS); + + // callbacks we are interested in + void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final; + +private: + virtual ~MeasurementAPIClient(); + + std::mutex mMutex; + sp mGnssMeasurementCbIface; + sp mGnssMeasurementCbIface_1_1; + sp mGnssMeasurementCbIface_2_0; + sp mGnssMeasurementCbIface_2_1; + bool mTracking; + void clearInterfaces(); +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace gnss +} // namespace hardware +} // namespace android +#endif // MEASUREMENT_API_CLINET_H diff --git a/gps/android/2.1/service.cpp b/gps/android/2.1/service.cpp new file mode 100755 index 0000000..c5f040b --- /dev/null +++ b/gps/android/2.1/service.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * Not a Contribution + */ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2_0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2_0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.gnss@2.1-service-qti" + +#include +#include +#include "loc_cfg.h" +#include "loc_misc_utils.h" + +extern "C" { +#include "vndfwk-detect.h" +} + +#ifdef ARCH_ARM_32 +#define DEFAULT_HW_BINDER_MEM_SIZE 65536 +#endif + +using android::hardware::gnss::V2_1::IGnss; + +using android::hardware::configureRpcThreadpool; +using android::hardware::registerPassthroughServiceImplementation; +using android::hardware::joinRpcThreadpool; + +using android::status_t; +using android::OK; + +typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []); + +int main() { + + ALOGI("%s", __FUNCTION__); + + int vendorInfo = getVendorEnhancedInfo(); + bool vendorEnhanced = ( 1 == vendorInfo || 3 == vendorInfo ); + setVendorEnhanced(vendorEnhanced); + +#ifdef ARCH_ARM_32 + android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE)); +#endif + configureRpcThreadpool(1, true); + status_t status; + + status = registerPassthroughServiceImplementation(); + if (status == OK) { + #ifdef LOC_HIDL_VERSION + #define VENDOR_ENHANCED_LIB "vendor.qti.gnss@" LOC_HIDL_VERSION "-service.so" + + void* libHandle = NULL; + vendorEnhancedServiceMain* vendorEnhancedMainMethod = (vendorEnhancedServiceMain*) + dlGetSymFromLib(libHandle, VENDOR_ENHANCED_LIB, "main"); + if (NULL != vendorEnhancedMainMethod) { + (*vendorEnhancedMainMethod)(0, NULL); + } + #else + ALOGI("LOC_HIDL_VERSION not defined."); + #endif + joinRpcThreadpool(); + } else { + ALOGE("Error while registering IGnss 2.1 service: %d", status); + } + + return 0; +} diff --git a/gps/android/Android.mk b/gps/android/Android.mk new file mode 100644 index 0000000..aa2f4b5 --- /dev/null +++ b/gps/android/Android.mk @@ -0,0 +1,2 @@ +LOCAL_PATH := $(call my-dir) +include $(call all-subdir-makefiles) diff --git a/gps/android/utils/Android.bp b/gps/android/utils/Android.bp new file mode 100644 index 0000000..c3dc17a --- /dev/null +++ b/gps/android/utils/Android.bp @@ -0,0 +1,37 @@ +cc_library_static { + + name: "liblocbatterylistener", + vendor: true, + + sanitize: GNSS_SANITIZE, + + cflags: GNSS_CFLAGS + ["-DBATTERY_LISTENER_ENABLED"], + local_include_dirs: ["."], + + srcs: ["battery_listener.cpp"], + + shared_libs: [ + "liblog", + "libhidlbase", + "libcutils", + "libutils", + "android.hardware.health@1.0", + "android.hardware.health@2.0", + "android.hardware.health@2.1", + "android.hardware.power@1.2", + "libbase", + ], + + static_libs: ["libhealthhalutils"], + + header_libs: [ + "libgps.utils_headers", + "libloc_pla_headers", + ], +} + +cc_library_headers { + + name: "liblocbatterylistener_headers", + export_include_dirs: ["."], +} diff --git a/gps/android/utils/battery_listener.cpp b/gps/android/utils/battery_listener.cpp new file mode 100644 index 0000000..9cbfabd --- /dev/null +++ b/gps/android/utils/battery_listener.cpp @@ -0,0 +1,280 @@ +/* +* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of The Linux Foundation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include "battery_listener.h" +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LocSvc_BatteryListener" +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include +#include +#include + +using android::hardware::interfacesEqual; +using android::hardware::Return; +using android::hardware::Void; +using android::hardware::health::V1_0::BatteryStatus; +using android::hardware::health::V2_1::HealthInfo; +using android::hardware::health::V2_1::IHealthInfoCallback; +using android::hardware::health::V2_1::IHealth; +using android::hardware::health::V2_0::Result; +using android::hidl::manager::V1_0::IServiceManager; +using namespace std::literals::chrono_literals; + +static bool sIsBatteryListened = false; +namespace android { + +#define GET_HEALTH_SVC_RETRY_CNT 5 +#define GET_HEALTH_SVC_WAIT_TIME_MS 500 + +struct BatteryListenerImpl : public hardware::health::V2_1::IHealthInfoCallback, + public hardware::hidl_death_recipient { + typedef std::function cb_fn_t; + BatteryListenerImpl(cb_fn_t cb); + virtual ~BatteryListenerImpl (); + virtual hardware::Return healthInfoChanged( + const hardware::health::V2_0::HealthInfo& info); + virtual hardware::Return healthInfoChanged_2_1( + const hardware::health::V2_1::HealthInfo& info); + virtual void serviceDied(uint64_t cookie, + const wp& who); + bool isCharging() { + std::lock_guard _l(mLock); + return statusToBool(mStatus); + } + private: + sp mHealth; + status_t init(); + BatteryStatus mStatus; + cb_fn_t mCb; + std::mutex mLock; + std::condition_variable mCond; + std::unique_ptr mThread; + bool mDone; + bool statusToBool(const BatteryStatus &s) const { + return (s == BatteryStatus::CHARGING) || + (s == BatteryStatus::FULL); + } +}; + +status_t BatteryListenerImpl::init() +{ + int tries = 0; + + if (mHealth != NULL) + return INVALID_OPERATION; + + do { + mHealth = IHealth::getService(); + if (mHealth != NULL) + break; + usleep(GET_HEALTH_SVC_WAIT_TIME_MS * 1000); + tries++; + } while(tries < GET_HEALTH_SVC_RETRY_CNT); + + if (mHealth == NULL) { + LOC_LOGe("no health service found, retries %d", tries); + return NO_INIT; + } else { + LOC_LOGi("Get health service in %d tries", tries); + } + mStatus = BatteryStatus::UNKNOWN; + auto ret = mHealth->getChargeStatus([&](Result r, BatteryStatus status) { + if (r != Result::SUCCESS) { + LOC_LOGe("batterylistener: cannot get battery status"); + return; + } + mStatus = status; + }); + if (!ret.isOk()) { + LOC_LOGe("batterylistener: get charge status transaction error"); + } + if (mStatus == BatteryStatus::UNKNOWN) { + LOC_LOGw("batterylistener: init: invalid battery status"); + } + mDone = false; + mThread = std::make_unique([this]() { + std::unique_lock l(mLock); + BatteryStatus local_status = mStatus; + while (!mDone) { + if (local_status == mStatus) { + mCond.wait(l); + continue; + } + local_status = mStatus; + switch (local_status) { + // NOT_CHARGING is a special event that indicates, a battery is connected, + // but not charging. This is seen for approx a second + // after charger is plugged in. A charging event is eventually received. + // We must try to avoid an unnecessary cb to HAL + // only to call it again shortly. + // An option to deal with this transient event would be to ignore this. + // Or process this event with a slight delay (i.e cancel this event + // if a different event comes in within a timeout + case BatteryStatus::NOT_CHARGING : { + auto mStatusnot_ncharging = + [this, local_status]() { return mStatus != local_status; }; + mCond.wait_for(l, 3s, mStatusnot_ncharging); + if (mStatusnot_ncharging()) // i.e event changed + break; + [[clang::fallthrough]]; //explicit fall-through between switch labels + } + default: + bool c = statusToBool(local_status); + LOC_LOGi("healthInfo cb thread: cb %s", c ? "CHARGING" : "NOT CHARGING"); + l.unlock(); + mCb(c); + l.lock(); + break; + } + } + }); + auto reg = mHealth->registerCallback(this); + if (!reg.isOk()) { + LOC_LOGe("Transaction error in registeringCb to HealthHAL death: %s", + reg.description().c_str()); + } + + auto linked = mHealth->linkToDeath(this, 0 /* cookie */); + if (!linked.isOk() || linked == false) { + LOC_LOGe("Transaction error in linking to HealthHAL death: %s", + linked.description().c_str()); + } + return NO_ERROR; +} + +BatteryListenerImpl::BatteryListenerImpl(cb_fn_t cb) : + mCb(cb) +{ + init(); +} + +BatteryListenerImpl::~BatteryListenerImpl() +{ + { + std::lock_guard _l(mLock); + if (mHealth != NULL) + mHealth->unregisterCallback(this); + auto r = mHealth->unlinkToDeath(this); + if (!r.isOk() || r == false) { + LOC_LOGe("Transaction error in unregister to HealthHAL death: %s", + r.description().c_str()); + } + } + mDone = true; + mThread->join(); +} + +void BatteryListenerImpl::serviceDied(uint64_t cookie __unused, + const wp& who) +{ + { + std::lock_guard _l(mLock); + if (mHealth == NULL || !interfacesEqual(mHealth, who.promote())) { + LOC_LOGe("health not initialized or unknown interface died"); + return; + } + LOC_LOGi("health service died, reinit"); + mDone = true; + } + mHealth = NULL; + mCond.notify_one(); + mThread->join(); + std::lock_guard _l(mLock); + init(); +} + +// this callback seems to be a SYNC callback and so +// waits for return before next event is issued. +// therefore we need not have a queue to process +// NOT_CHARGING and CHARGING concurrencies. +// Replace single var by a list if this assumption is broken +Return BatteryListenerImpl::healthInfoChanged( + const hardware::health::V2_0::HealthInfo& info) { + LOC_LOGv("healthInfoChanged: %d", info.legacy.batteryStatus); + std::unique_lock l(mLock); + if (info.legacy.batteryStatus != mStatus) { + mStatus = info.legacy.batteryStatus; + mCond.notify_one(); + } + return Void(); +} + +Return BatteryListenerImpl::healthInfoChanged_2_1( + const hardware::health::V2_1::HealthInfo& info) { + LOC_LOGv("healthInfoChanged_2_1: %d", info.legacy.legacy.batteryStatus); + healthInfoChanged(info.legacy); + return Void(); +} + +static sp batteryListener; + +bool batteryPropertiesListenerIsCharging() { + return batteryListener->isCharging(); +} + +status_t batteryPropertiesListenerInit(BatteryListenerImpl::cb_fn_t cb) { + batteryListener = new BatteryListenerImpl(cb); + bool isCharging = batteryPropertiesListenerIsCharging(); + LOC_LOGv("charging status: %s charging", isCharging ? "" : "not");; + if (isCharging) { + cb(isCharging); + } + return NO_ERROR; +} + +status_t batteryPropertiesListenerDeinit() { + batteryListener.clear(); + return OK; +} + +} // namespace android + +void loc_extn_battery_properties_listener_init(battery_status_change_fn_t fn) { + LOC_LOGv("loc_extn_battery_properties_listener_init entry"); + if (!sIsBatteryListened) { + std::thread t1(android::batteryPropertiesListenerInit, + [=](bool charging) { fn(charging); }); + t1.detach(); + sIsBatteryListened = true; + } +} + +void loc_extn_battery_properties_listener_deinit() { + android::batteryPropertiesListenerDeinit(); +} + +bool loc_extn_battery_properties_is_charging() { + return android::batteryPropertiesListenerIsCharging(); +} diff --git a/gps/android/utils/battery_listener.h b/gps/android/utils/battery_listener.h new file mode 100644 index 0000000..bb6b715 --- /dev/null +++ b/gps/android/utils/battery_listener.h @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2019, The Linux Foundation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of The Linux Foundation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +typedef void (* battery_status_change_fn_t)(bool); +void loc_extn_battery_properties_listener_init(battery_status_change_fn_t fn); +void loc_extn_battery_properties_listener_deinit(); +bool loc_extn_battery_properties_is_charging(); diff --git a/gps/batching/Android.bp b/gps/batching/Android.bp new file mode 100644 index 0000000..9182a0a --- /dev/null +++ b/gps/batching/Android.bp @@ -0,0 +1,31 @@ + +cc_library_shared { + + name: "libbatching", + vendor: true, + + sanitize: GNSS_SANITIZE, + + shared_libs: [ + "libutils", + "libcutils", + "liblog", + "libloc_core", + "libgps.utils", + "libdl", + ], + + srcs: [ + "location_batching.cpp", + "BatchingAdapter.cpp", + ], + + header_libs: [ + "libgps.utils_headers", + "libloc_core_headers", + "libloc_pla_headers", + "liblocation_api_headers", + ], + + cflags: GNSS_CFLAGS, +} diff --git a/gps/batching/BatchingAdapter.cpp b/gps/batching/BatchingAdapter.cpp new file mode 100644 index 0000000..d9f7945 --- /dev/null +++ b/gps/batching/BatchingAdapter.cpp @@ -0,0 +1,1045 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_BatchingAdapter" + +#include +#include +#include +#include + +using namespace loc_core; + +BatchingAdapter::BatchingAdapter() : + LocAdapterBase(0, LocContext::getLocContext(LocContext::mLocationHalName)), + mOngoingTripDistance(0), + mOngoingTripTBFInterval(0), + mTripWithOngoingTBFDropped(false), + mTripWithOngoingTripDistanceDropped(false), + mBatchingTimeout(0), + mBatchingAccuracy(1), + mBatchSize(0), + mTripBatchSize(0) +{ + LOC_LOGD("%s]: Constructor", __func__); + readConfigCommand(); + setConfigCommand(); +} + +void +BatchingAdapter::readConfigCommand() +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgReadConfig : public LocMsg { + BatchingAdapter& mAdapter; + inline MsgReadConfig(BatchingAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + inline virtual void proc() const { + uint32_t batchingTimeout = 0; + uint32_t batchingAccuracy = 0; + uint32_t batchSize = 0; + uint32_t tripBatchSize = 0; + static const loc_param_s_type flp_conf_param_table[] = + { + {"BATCH_SIZE", &batchSize, NULL, 'n'}, + {"OUTDOOR_TRIP_BATCH_SIZE", &tripBatchSize, NULL, 'n'}, + {"BATCH_SESSION_TIMEOUT", &batchingTimeout, NULL, 'n'}, + {"ACCURACY", &batchingAccuracy, NULL, 'n'}, + }; + UTIL_READ_CONF(LOC_PATH_FLP_CONF, flp_conf_param_table); + + LOC_LOGD("%s]: batchSize %u tripBatchSize %u batchingAccuracy %u batchingTimeout %u ", + __func__, batchSize, tripBatchSize, batchingAccuracy, batchingTimeout); + + mAdapter.setBatchSize(batchSize); + mAdapter.setTripBatchSize(tripBatchSize); + mAdapter.setBatchingTimeout(batchingTimeout); + mAdapter.setBatchingAccuracy(batchingAccuracy); + } + }; + + sendMsg(new MsgReadConfig(*this)); + +} + +void +BatchingAdapter::setConfigCommand() +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgSetConfig : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + inline MsgSetConfig(BatchingAdapter& adapter, + LocApiBase& api) : + LocMsg(), + mAdapter(adapter), + mApi(api) {} + inline virtual void proc() const { + mApi.setBatchSize(mAdapter.getBatchSize()); + mApi.setTripBatchSize(mAdapter.getTripBatchSize()); + } + }; + + sendMsg(new MsgSetConfig(*this, *mLocApi)); +} + +void +BatchingAdapter::stopClientSessions(LocationAPI* client) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + typedef struct pairKeyBatchMode { + LocationAPI* client; + uint32_t id; + BatchingMode batchingMode; + inline pairKeyBatchMode(LocationAPI* _client, uint32_t _id, BatchingMode _bMode) : + client(_client), id(_id), batchingMode(_bMode) {} + } pairKeyBatchMode; + std::vector vBatchingClient; + for (auto it : mBatchingSessions) { + if (client == it.first.client) { + vBatchingClient.emplace_back(it.first.client, it.first.id, it.second.batchingMode); + } + } + for (auto keyBatchingMode : vBatchingClient) { + if (keyBatchingMode.batchingMode != BATCHING_MODE_TRIP) { + stopBatching(keyBatchingMode.client, keyBatchingMode.id); + } else { + stopTripBatchingMultiplex(keyBatchingMode.client, keyBatchingMode.id); + } + } +} + +void +BatchingAdapter::updateClientsEventMask() +{ + LOC_API_ADAPTER_EVENT_MASK_T mask = 0; + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + // we don't register LOC_API_ADAPTER_BIT_BATCH_FULL until we + // start batching with ROUTINE or TRIP option + if (it->second.batchingCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_BATCH_STATUS; + } + } + if (autoReportBatchingSessionsCount() > 0) { + mask |= LOC_API_ADAPTER_BIT_BATCH_FULL; + } + updateEvtMask(mask, LOC_REGISTRATION_MASK_SET); +} + +void +BatchingAdapter::handleEngineUpEvent() +{ + struct MsgSSREvent : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + inline MsgSSREvent(BatchingAdapter& adapter, + LocApiBase& api) : + LocMsg(), + mAdapter(adapter), + mApi(api) {} + virtual void proc() const { + mAdapter.setEngineCapabilitiesKnown(true); + mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); + mApi.setBatchSize(mAdapter.getBatchSize()); + mApi.setTripBatchSize(mAdapter.getTripBatchSize()); + mAdapter.restartSessions(); + for (auto msg: mAdapter.mPendingMsgs) { + mAdapter.sendMsg(msg); + } + mAdapter.mPendingMsgs.clear(); + } + }; + + sendMsg(new MsgSSREvent(*this, *mLocApi)); +} + +void +BatchingAdapter::restartSessions() +{ + LOC_LOGD("%s]: ", __func__); + + if (autoReportBatchingSessionsCount() > 0) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_ENABLED); + } + for (auto it = mBatchingSessions.begin(); + it != mBatchingSessions.end(); ++it) { + if (it->second.batchingMode != BATCHING_MODE_TRIP) { + mLocApi->startBatching(it->first.id, it->second, + getBatchingAccuracy(), getBatchingTimeout(), + new LocApiResponse(*getContext(), + [] (LocationError /*err*/) {})); + } + } + + if (mTripSessions.size() > 0) { + // restart outdoor trip batching session if any. + mOngoingTripDistance = 0; + mOngoingTripTBFInterval = 0; + + // record the min trip distance and min tbf interval of all ongoing sessions + for (auto tripSession : mTripSessions) { + + TripSessionStatus &tripSessStatus = tripSession.second; + + if ((0 == mOngoingTripDistance) || + (mOngoingTripDistance > + (tripSessStatus.tripDistance - tripSessStatus.accumulatedDistanceThisTrip))) { + mOngoingTripDistance = tripSessStatus.tripDistance - + tripSessStatus.accumulatedDistanceThisTrip; + } + + if ((0 == mOngoingTripTBFInterval) || + (mOngoingTripTBFInterval > tripSessStatus.tripTBFInterval)) { + mOngoingTripTBFInterval = tripSessStatus.tripTBFInterval; + } + + // reset the accumulatedDistanceOngoingBatch for each session + tripSessStatus.accumulatedDistanceOngoingBatch = 0; + + } + + mLocApi->startOutdoorTripBatching(mOngoingTripDistance, mOngoingTripTBFInterval, + getBatchingTimeout(), new LocApiResponse(*getContext(), [this] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + mOngoingTripDistance = 0; + mOngoingTripTBFInterval = 0; + } + printTripReport(); + })); + } +} + +bool +BatchingAdapter::hasBatchingCallback(LocationAPI* client) +{ + auto it = mClientData.find(client); + return (it != mClientData.end() && it->second.batchingCb); +} + +bool +BatchingAdapter::isBatchingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + return (mBatchingSessions.find(key) != mBatchingSessions.end()); +} + +bool +BatchingAdapter::isTripSession(uint32_t sessionId) { + return (mTripSessions.find(sessionId) != mTripSessions.end()); +} + +void +BatchingAdapter::saveBatchingSession(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions) +{ + LocationSessionKey key(client, sessionId); + mBatchingSessions[key] = batchingOptions; +} + +void +BatchingAdapter::eraseBatchingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + auto it = mBatchingSessions.find(key); + if (it != mBatchingSessions.end()) { + mBatchingSessions.erase(it); + } +} + +void +BatchingAdapter::reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId) +{ + LOC_LOGD("%s]: client %p id %u err %u", __func__, client, sessionId, err); + + auto it = mClientData.find(client); + if (it != mClientData.end() && + it->second.responseCb != nullptr) { + it->second.responseCb(err, sessionId); + } else { + LOC_LOGE("%s]: client %p id %u not found in data", __func__, client, sessionId); + } +} + +uint32_t +BatchingAdapter::autoReportBatchingSessionsCount() +{ + uint32_t count = 0; + for (auto batchingSession: mBatchingSessions) { + if (batchingSession.second.batchingMode != BATCHING_MODE_NO_AUTO_REPORT) { + count++; + } + } + count += mTripSessions.size(); + return count; +} + +uint32_t +BatchingAdapter::startBatchingCommand( + LocationAPI* client, BatchingOptions& batchOptions) +{ + uint32_t sessionId = generateSessionId(); + LOC_LOGD("%s]: client %p id %u minInterval %u minDistance %u mode %u Batching Mode %d", + __func__, client, sessionId, batchOptions.minInterval, batchOptions.minDistance, + batchOptions.mode,batchOptions.batchingMode); + + struct MsgStartBatching : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + BatchingOptions mBatchingOptions; + inline MsgStartBatching(BatchingAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId, + BatchingOptions batchOptions) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId), + mBatchingOptions(batchOptions) {} + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgStartBatching(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + + if (!mAdapter.hasBatchingCallback(mClient)) { + err = LOCATION_ERROR_CALLBACK_MISSING; + } else if (0 == mBatchingOptions.size) { + err = LOCATION_ERROR_INVALID_PARAMETER; + } else if (!ContextBase::isMessageSupported( + LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)) { + err = LOCATION_ERROR_NOT_SUPPORTED; + } + if (LOCATION_ERROR_SUCCESS == err) { + if (mBatchingOptions.batchingMode == BATCHING_MODE_ROUTINE || + mBatchingOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) { + mAdapter.startBatching(mClient, mSessionId, mBatchingOptions); + } else if (mBatchingOptions.batchingMode == BATCHING_MODE_TRIP) { + mAdapter.startTripBatchingMultiplex(mClient, mSessionId, mBatchingOptions); + } else { + mAdapter.reportResponse(mClient, LOCATION_ERROR_INVALID_PARAMETER, mSessionId); + } + } + } + }; + + sendMsg(new MsgStartBatching(*this, *mLocApi, client, sessionId, batchOptions)); + + return sessionId; +} + +void +BatchingAdapter::startBatching(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions) +{ + if (batchingOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT && + 0 == autoReportBatchingSessionsCount()) { + // if there is currenty no batching sessions interested in batch full event, then this + // new session will need to register for batch full event + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_ENABLED); + } + + // Assume start will be OK, remove session if not + saveBatchingSession(client, sessionId, batchingOptions); + mLocApi->startBatching(sessionId, batchingOptions, getBatchingAccuracy(), getBatchingTimeout(), + new LocApiResponse(*getContext(), + [this, client, sessionId, batchingOptions] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + eraseBatchingSession(client, sessionId); + } + + if (LOCATION_ERROR_SUCCESS != err && + batchingOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT && + 0 == autoReportBatchingSessionsCount()) { + // if we fail to start batching and we have already registered batch full event + // we need to undo that since no sessions are now interested in batch full event + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_DISABLED); + } + + reportResponse(client, err, sessionId); + })); +} + +void +BatchingAdapter::updateBatchingOptionsCommand(LocationAPI* client, uint32_t id, + BatchingOptions& batchOptions) +{ + LOC_LOGD("%s]: client %p id %u minInterval %u minDistance %u mode %u batchMode %u", + __func__, client, id, batchOptions.minInterval, + batchOptions.minDistance, batchOptions.mode, + batchOptions.batchingMode); + + struct MsgUpdateBatching : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + BatchingOptions mBatchOptions; + inline MsgUpdateBatching(BatchingAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId, + BatchingOptions batchOptions) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId), + mBatchOptions(batchOptions) {} + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgUpdateBatching(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + if (!mAdapter.isBatchingSession(mClient, mSessionId)) { + err = LOCATION_ERROR_ID_UNKNOWN; + } else if ((0 == mBatchOptions.size) || + (mBatchOptions.batchingMode > BATCHING_MODE_NO_AUTO_REPORT)) { + err = LOCATION_ERROR_INVALID_PARAMETER; + } + if (LOCATION_ERROR_SUCCESS == err) { + if (!mAdapter.isTripSession(mSessionId)) { + mAdapter.stopBatching(mClient, mSessionId, true, mBatchOptions); + } else { + mAdapter.stopTripBatchingMultiplex(mClient, mSessionId, true, mBatchOptions); + } + } + } + }; + + sendMsg(new MsgUpdateBatching(*this, *mLocApi, client, id, batchOptions)); +} + +void +BatchingAdapter::stopBatchingCommand(LocationAPI* client, uint32_t id) +{ + LOC_LOGD("%s]: client %p id %u", __func__, client, id); + + struct MsgStopBatching : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + inline MsgStopBatching(BatchingAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId) {} + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgStopBatching(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + if (!mAdapter.isBatchingSession(mClient, mSessionId)) { + err = LOCATION_ERROR_ID_UNKNOWN; + } + if (LOCATION_ERROR_SUCCESS == err) { + if (mAdapter.isTripSession(mSessionId)) { + mAdapter.stopTripBatchingMultiplex(mClient, mSessionId); + } else { + mAdapter.stopBatching(mClient, mSessionId); + } + } + } + }; + + sendMsg(new MsgStopBatching(*this, *mLocApi, client, id)); +} + +void +BatchingAdapter::stopBatching(LocationAPI* client, uint32_t sessionId, bool restartNeeded, + const BatchingOptions& batchOptions) +{ + LocationSessionKey key(client, sessionId); + auto it = mBatchingSessions.find(key); + if (it != mBatchingSessions.end()) { + auto flpOptions = it->second; + // Assume stop will be OK, restore session if not + eraseBatchingSession(client, sessionId); + mLocApi->stopBatching(sessionId, + new LocApiResponse(*getContext(), + [this, client, sessionId, flpOptions, restartNeeded, batchOptions] + (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + saveBatchingSession(client, sessionId, batchOptions); + } else { + // if stopBatching is success, unregister for batch full event if this was the last + // batching session that is interested in batch full event + if (0 == autoReportBatchingSessionsCount() && + flpOptions.batchingMode != BATCHING_MODE_NO_AUTO_REPORT) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_DISABLED); + } + + if (restartNeeded) { + if (batchOptions.batchingMode == BATCHING_MODE_ROUTINE || + batchOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) { + startBatching(client, sessionId, batchOptions); + } else if (batchOptions.batchingMode == BATCHING_MODE_TRIP) { + startTripBatchingMultiplex(client, sessionId, batchOptions); + } + } + } + reportResponse(client, err, sessionId); + })); + } +} + +void +BatchingAdapter::getBatchedLocationsCommand(LocationAPI* client, uint32_t id, size_t count) +{ + LOC_LOGD("%s]: client %p id %u count %zu", __func__, client, id, count); + + struct MsgGetBatchedLocations : public LocMsg { + BatchingAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + size_t mCount; + inline MsgGetBatchedLocations(BatchingAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId, + size_t count) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId), + mCount(count) {} + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgGetBatchedLocations(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + if (!mAdapter.hasBatchingCallback(mClient)) { + err = LOCATION_ERROR_CALLBACK_MISSING; + } else if (!mAdapter.isBatchingSession(mClient, mSessionId)) { + err = LOCATION_ERROR_ID_UNKNOWN; + } + if (LOCATION_ERROR_SUCCESS == err) { + if (mAdapter.isTripSession(mSessionId)) { + mApi.getBatchedTripLocations(mCount, 0, + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, + mClient = mClient] (LocationError err) { + mAdapter.reportResponse(mClient, err, mSessionId); + })); + } else { + mApi.getBatchedLocations(mCount, new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, + mClient = mClient] (LocationError err) { + mAdapter.reportResponse(mClient, err, mSessionId); + })); + } + } else { + mAdapter.reportResponse(mClient, err, mSessionId); + } + } + }; + + sendMsg(new MsgGetBatchedLocations(*this, *mLocApi, client, id, count)); +} + +void +BatchingAdapter::reportLocationsEvent(const Location* locations, size_t count, + BatchingMode batchingMode) +{ + LOC_LOGD("%s]: count %zu batchMode %d", __func__, count, batchingMode); + + struct MsgReportLocations : public LocMsg { + BatchingAdapter& mAdapter; + Location* mLocations; + size_t mCount; + BatchingMode mBatchingMode; + inline MsgReportLocations(BatchingAdapter& adapter, + const Location* locations, + size_t count, + BatchingMode batchingMode) : + LocMsg(), + mAdapter(adapter), + mLocations(new Location[count]), + mCount(count), + mBatchingMode(batchingMode) + { + if (nullptr == mLocations) { + LOC_LOGE("%s]: new failed to allocate mLocations", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + mLocations[i] = locations[i]; + } + } + inline virtual ~MsgReportLocations() { + if (nullptr != mLocations) + delete[] mLocations; + } + inline virtual void proc() const { + mAdapter.reportLocations(mLocations, mCount, mBatchingMode); + } + }; + + sendMsg(new MsgReportLocations(*this, locations, count, batchingMode)); +} + +void +BatchingAdapter::reportLocations(Location* locations, size_t count, BatchingMode batchingMode) +{ + BatchingOptions batchOptions = {sizeof(BatchingOptions), batchingMode}; + + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.batchingCb) { + it->second.batchingCb(count, locations, batchOptions); + } + } +} + +void +BatchingAdapter::reportCompletedTripsEvent(uint32_t accumulated_distance) +{ + struct MsgReportCompletedTrips : public LocMsg { + BatchingAdapter& mAdapter; + uint32_t mAccumulatedDistance; + inline MsgReportCompletedTrips(BatchingAdapter& adapter, + uint32_t accumulated_distance) : + LocMsg(), + mAdapter(adapter), + mAccumulatedDistance(accumulated_distance) + { + } + inline virtual ~MsgReportCompletedTrips() { + } + inline virtual void proc() const { + + // Check if any trips are completed + std::list completedTripsList; + completedTripsList.clear(); + + for(auto itt = mAdapter.mTripSessions.begin(); itt != mAdapter.mTripSessions.end();) + { + TripSessionStatus &tripSession = itt->second; + + tripSession.accumulatedDistanceThisTrip = + tripSession.accumulatedDistanceOnTripRestart + + (mAccumulatedDistance - tripSession.accumulatedDistanceOngoingBatch); + if (tripSession.tripDistance <= tripSession.accumulatedDistanceThisTrip) { + // trip is completed + completedTripsList.push_back(itt->first); + itt = mAdapter.mTripSessions.erase(itt); + + if (tripSession.tripTBFInterval == mAdapter.mOngoingTripTBFInterval) { + // trip with ongoing TBF interval is completed + mAdapter.mTripWithOngoingTBFDropped = true; + } + + if (tripSession.tripDistance == mAdapter.mOngoingTripDistance) { + // trip with ongoing trip distance is completed + mAdapter.mTripWithOngoingTripDistanceDropped = true; + } + } else { + itt++; + } + } + + if (completedTripsList.size() > 0) { + mAdapter.reportBatchStatusChange(BATCHING_STATUS_TRIP_COMPLETED, + completedTripsList); + mAdapter.restartTripBatching(false, mAccumulatedDistance, 0); + } else { + mAdapter.printTripReport(); + } + } + }; + + LOC_LOGD("%s]: Accumulated Distance so far: %u", + __func__, accumulated_distance); + + sendMsg(new MsgReportCompletedTrips(*this, accumulated_distance)); +} + +void +BatchingAdapter::reportBatchStatusChange(BatchingStatus batchStatus, + std::list & completedTripsList) +{ + BatchingStatusInfo batchStatusInfo = + {sizeof(BatchingStatusInfo), batchStatus}; + + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.batchingStatusCb) { + it->second.batchingStatusCb(batchStatusInfo, completedTripsList); + } + } +} + +void +BatchingAdapter::reportBatchStatusChangeEvent(BatchingStatus batchStatus) +{ + struct MsgReportBatchStatus : public LocMsg { + BatchingAdapter& mAdapter; + BatchingStatus mBatchStatus; + inline MsgReportBatchStatus(BatchingAdapter& adapter, + BatchingStatus batchStatus) : + LocMsg(), + mAdapter(adapter), + mBatchStatus(batchStatus) + { + } + inline virtual ~MsgReportBatchStatus() { + } + inline virtual void proc() const { + std::list tempList; + tempList.clear(); + mAdapter.reportBatchStatusChange(mBatchStatus, tempList); + } + }; + + sendMsg(new MsgReportBatchStatus(*this, batchStatus)); +} + +void +BatchingAdapter::startTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions) +{ + if (mTripSessions.size() == 0) { + // if there is currenty no batching sessions interested in batch full event, then this + // new session will need to register for batch full event + if (0 == autoReportBatchingSessionsCount()) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_ENABLED); + } + + // Assume start will be OK, remove session if not + saveBatchingSession(client, sessionId, batchingOptions); + + mTripSessions[sessionId] = { 0, 0, 0, batchingOptions.minDistance, + batchingOptions.minInterval}; + mLocApi->startOutdoorTripBatching(batchingOptions.minDistance, + batchingOptions.minInterval, getBatchingTimeout(), new LocApiResponse(*getContext(), + [this, client, sessionId, batchingOptions] (LocationError err) { + if (err == LOCATION_ERROR_SUCCESS) { + mOngoingTripDistance = batchingOptions.minDistance; + mOngoingTripTBFInterval = batchingOptions.minInterval; + LOC_LOGD("%s] New Trip started ...", __func__); + printTripReport(); + } else { + eraseBatchingSession(client, sessionId); + mTripSessions.erase(sessionId); + // if we fail to start batching and we have already registered batch full event + // we need to undo that since no sessions are now interested in batch full event + if (0 == autoReportBatchingSessionsCount()) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_DISABLED); + } + } + reportResponse(client, err, sessionId); + })); + } else { + // query accumulated distance + mLocApi->queryAccumulatedTripDistance( + new LocApiResponseData(*getContext(), + [this, batchingOptions, sessionId, client] + (LocationError err, LocApiBatchData data) { + uint32_t accumulatedDistanceOngoingBatch = 0; + uint32_t numOfBatchedPositions = 0; + uint32_t ongoingTripDistance = mOngoingTripDistance; + uint32_t ongoingTripInterval = mOngoingTripTBFInterval; + bool needsRestart = false; + + // check if TBF of new session is lesser than ongoing TBF interval + if (ongoingTripInterval > batchingOptions.minInterval) { + ongoingTripInterval = batchingOptions.minInterval; + needsRestart = true; + } + accumulatedDistanceOngoingBatch = data.accumulatedDistance; + numOfBatchedPositions = data.numOfBatchedPositions; + TripSessionStatus newTripSession = { accumulatedDistanceOngoingBatch, 0, 0, + batchingOptions.minDistance, + batchingOptions.minInterval}; + if (err != LOCATION_ERROR_SUCCESS) { + // unable to query accumulated distance, assume remaining distance in + // ongoing batch is mongoingTripDistance. + if (batchingOptions.minDistance < ongoingTripDistance) { + ongoingTripDistance = batchingOptions.minDistance; + needsRestart = true; + } + } else { + // compute the remaining distance + uint32_t ongoing_trip_remaining_distance = ongoingTripDistance - + accumulatedDistanceOngoingBatch; + + // check if new trip distance is lesser than the ongoing batch remaining distance + if (batchingOptions.minDistance < ongoing_trip_remaining_distance) { + ongoingTripDistance = batchingOptions.minDistance; + needsRestart = true; + } else if (needsRestart == true) { + // needsRestart is anyways true , may be because of lesser TBF of new session. + ongoingTripDistance = ongoing_trip_remaining_distance; + } + mTripSessions[sessionId] = newTripSession; + LOC_LOGD("%s] New Trip started ...", __func__); + printTripReport(); + } + + if (needsRestart) { + mOngoingTripDistance = ongoingTripDistance; + mOngoingTripTBFInterval = ongoingTripInterval; + + // reset the accumulatedDistanceOngoingBatch for each session, + // and record the total accumulated distance so far for the session. + for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) { + TripSessionStatus &tripSessStatus = itt->second; + tripSessStatus.accumulatedDistanceOngoingBatch = 0; + tripSessStatus.accumulatedDistanceOnTripRestart = + tripSessStatus.accumulatedDistanceThisTrip; + } + mLocApi->reStartOutdoorTripBatching(ongoingTripDistance, ongoingTripInterval, + getBatchingTimeout(), new LocApiResponse(*getContext(), + [this, client, sessionId] (LocationError err) { + if (err != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s] New Trip restart failed!", __func__); + } + reportResponse(client, err, sessionId); + })); + } else { + reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId); + } + })); + } +} + +void +BatchingAdapter::stopTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId, + bool restartNeeded, const BatchingOptions& batchOptions) +{ + LocationError err = LOCATION_ERROR_SUCCESS; + + if (mTripSessions.size() == 1) { + mLocApi->stopOutdoorTripBatching(true, new LocApiResponse(*getContext(), + [this, restartNeeded, client, sessionId, batchOptions] + (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + // if stopOutdoorTripBatching is success, unregister for batch full event if this + // was the last batching session that is interested in batch full event + if (1 == autoReportBatchingSessionsCount()) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_DISABLED); + } + } + stopTripBatchingMultiplexCommon(err, client, sessionId, restartNeeded, batchOptions); + })); + return; + } + + stopTripBatchingMultiplexCommon(err, client, sessionId, restartNeeded, batchOptions); +} + +void +BatchingAdapter::stopTripBatchingMultiplexCommon(LocationError err, LocationAPI* client, + uint32_t sessionId, bool restartNeeded, const BatchingOptions& batchOptions) +{ + auto itt = mTripSessions.find(sessionId); + TripSessionStatus tripSess = itt->second; + if (tripSess.tripTBFInterval == mOngoingTripTBFInterval) { + // trip with ongoing trip interval is stopped + mTripWithOngoingTBFDropped = true; + } + + if (tripSess.tripDistance == mOngoingTripDistance) { + // trip with ongoing trip distance is stopped + mTripWithOngoingTripDistanceDropped = true; + } + + mTripSessions.erase(sessionId); + + if (mTripSessions.size() == 0) { + mOngoingTripDistance = 0; + mOngoingTripTBFInterval = 0; + } else { + restartTripBatching(true); + } + + if (restartNeeded) { + eraseBatchingSession(client, sessionId); + if (batchOptions.batchingMode == BATCHING_MODE_ROUTINE || + batchOptions.batchingMode == BATCHING_MODE_NO_AUTO_REPORT) { + startBatching(client, sessionId, batchOptions); + } else if (batchOptions.batchingMode == BATCHING_MODE_TRIP) { + startTripBatchingMultiplex(client, sessionId, batchOptions); + } + } + reportResponse(client, err, sessionId); +} + + +void +BatchingAdapter::restartTripBatching(bool queryAccumulatedDistance, uint32_t accDist, + uint32_t numbatchedPos) +{ + // does batch need restart with new trip distance / TBF interval + uint32_t minRemainingDistance = 0; + uint32_t minTBFInterval = 0; + + // if no more trips left, stop the ongoing trip + if (mTripSessions.size() == 0) { + mLocApi->stopOutdoorTripBatching(true, new LocApiResponse(*getContext(), + [] (LocationError /*err*/) {})); + mOngoingTripDistance = 0; + mOngoingTripTBFInterval = 0; + // unregister for batch full event if there are no more + // batching session that is interested in batch full event + if (0 == autoReportBatchingSessionsCount()) { + updateEvtMask(LOC_API_ADAPTER_BIT_BATCH_FULL, + LOC_REGISTRATION_MASK_DISABLED); + } + return; + } + + // record the min trip distance and min tbf interval of all ongoing sessions + for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) { + + TripSessionStatus tripSessStatus = itt->second; + + if ((minRemainingDistance == 0) || + (minRemainingDistance > (tripSessStatus.tripDistance + - tripSessStatus.accumulatedDistanceThisTrip))) { + minRemainingDistance = tripSessStatus.tripDistance - + tripSessStatus.accumulatedDistanceThisTrip; + } + + if ((minTBFInterval == 0) || + (minTBFInterval > tripSessStatus.tripTBFInterval)) { + minTBFInterval = tripSessStatus.tripTBFInterval; + } + } + + mLocApi->queryAccumulatedTripDistance( + new LocApiResponseData(*getContext(), + [this, queryAccumulatedDistance, minRemainingDistance, minTBFInterval, accDist, + numbatchedPos] (LocationError /*err*/, LocApiBatchData data) { + bool needsRestart = false; + + uint32_t ongoingTripDistance = mOngoingTripDistance; + uint32_t ongoingTripInterval = mOngoingTripTBFInterval; + uint32_t accumulatedDistance = accDist; + uint32_t numOfBatchedPositions = numbatchedPos; + + if (queryAccumulatedDistance) { + accumulatedDistance = data.accumulatedDistance; + numOfBatchedPositions = data.numOfBatchedPositions; + } + + if ((!mTripWithOngoingTripDistanceDropped) && + (ongoingTripDistance - accumulatedDistance != 0)) { + // if ongoing trip is already not completed still, + // check the min distance against the remaining distance + if (minRemainingDistance < + (ongoingTripDistance - accumulatedDistance)) { + ongoingTripDistance = minRemainingDistance; + needsRestart = true; + } + } else if (minRemainingDistance != 0) { + // else if ongoing trip is already completed / dropped, + // use the minRemainingDistance of ongoing sessions + ongoingTripDistance = minRemainingDistance; + needsRestart = true; + } + + if ((minTBFInterval < ongoingTripInterval) || + ((minTBFInterval != ongoingTripInterval) && + (mTripWithOngoingTBFDropped))) { + ongoingTripInterval = minTBFInterval; + needsRestart = true; + } + + if (needsRestart) { + mLocApi->reStartOutdoorTripBatching(ongoingTripDistance, ongoingTripInterval, + getBatchingTimeout(), new LocApiResponse(*getContext(), + [this, accumulatedDistance, ongoingTripDistance, ongoingTripInterval] + (LocationError err) { + + if (err == LOCATION_ERROR_SUCCESS) { + for(auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) { + TripSessionStatus &tripSessStatus = itt->second; + tripSessStatus.accumulatedDistanceThisTrip = + tripSessStatus.accumulatedDistanceOnTripRestart + + (accumulatedDistance - + tripSessStatus.accumulatedDistanceOngoingBatch); + + tripSessStatus.accumulatedDistanceOngoingBatch = 0; + tripSessStatus.accumulatedDistanceOnTripRestart = + tripSessStatus.accumulatedDistanceThisTrip; + } + + mOngoingTripDistance = ongoingTripDistance; + mOngoingTripTBFInterval = ongoingTripInterval; + } + })); + } + })); +} + +void +BatchingAdapter::printTripReport() +{ + IF_LOC_LOGD { + LOC_LOGD("Ongoing Trip Distance = %u, Ongoing Trip TBF Interval = %u", + mOngoingTripDistance, mOngoingTripTBFInterval); + + for (auto itt = mTripSessions.begin(); itt != mTripSessions.end(); itt++) { + TripSessionStatus tripSessStatus = itt->second; + + LOC_LOGD("tripDistance:%u tripTBFInterval:%u" + " trip accumulated Distance:%u" + " trip accumualted distance ongoing batch:%u" + " trip accumulated distance on trip restart %u \r\n", + tripSessStatus.tripDistance, tripSessStatus.tripTBFInterval, + tripSessStatus.accumulatedDistanceThisTrip, + tripSessStatus.accumulatedDistanceOngoingBatch, + tripSessStatus.accumulatedDistanceOnTripRestart); + } + } +} diff --git a/gps/batching/BatchingAdapter.h b/gps/batching/BatchingAdapter.h new file mode 100644 index 0000000..66f7c5f --- /dev/null +++ b/gps/batching/BatchingAdapter.h @@ -0,0 +1,152 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef BATCHING_ADAPTER_H +#define BATCHING_ADAPTER_H + +#include +#include +#include +#include + +using namespace loc_core; + +class BatchingAdapter : public LocAdapterBase { + + /* ==== BATCHING ======================================================================= */ + typedef struct { + uint32_t accumulatedDistanceOngoingBatch; + uint32_t accumulatedDistanceThisTrip; + uint32_t accumulatedDistanceOnTripRestart; + uint32_t tripDistance; + uint32_t tripTBFInterval; + } TripSessionStatus; + typedef std::map TripSessionStatusMap; + typedef std::map BatchingSessionMap; + + BatchingSessionMap mBatchingSessions; + TripSessionStatusMap mTripSessions; + uint32_t mOngoingTripDistance; + uint32_t mOngoingTripTBFInterval; + bool mTripWithOngoingTBFDropped; + bool mTripWithOngoingTripDistanceDropped; + + void startTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions); + void stopTripBatchingMultiplex(LocationAPI* client, uint32_t sessionId, + bool restartNeeded, + const BatchingOptions& batchOptions); + inline void stopTripBatchingMultiplex(LocationAPI* client, uint32_t id) { + BatchingOptions batchOptions; + stopTripBatchingMultiplex(client, id, false, batchOptions); + }; + void stopTripBatchingMultiplexCommon(LocationError err, + LocationAPI* client, + uint32_t sessionId, + bool restartNeeded, + const BatchingOptions& batchOptions); + void restartTripBatching(bool queryAccumulatedDistance, uint32_t accDist = 0, + uint32_t numbatchedPos = 0); + void printTripReport(); + + /* ==== CONFIGURATION ================================================================== */ + uint32_t mBatchingTimeout; + uint32_t mBatchingAccuracy; + size_t mBatchSize; + size_t mTripBatchSize; + +protected: + + /* ==== CLIENT ========================================================================= */ + virtual void updateClientsEventMask(); + virtual void stopClientSessions(LocationAPI* client); + +public: + BatchingAdapter(); + virtual ~BatchingAdapter() {} + + /* ==== SSR ============================================================================ */ + /* ======== EVENTS ====(Called from QMI Thread)========================================= */ + virtual void handleEngineUpEvent(); + /* ======== UTILITIES ================================================================== */ + void restartSessions(); + + /* ==== BATCHING ======================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + uint32_t startBatchingCommand(LocationAPI* client, BatchingOptions &batchOptions); + void updateBatchingOptionsCommand( + LocationAPI* client, uint32_t id, BatchingOptions& batchOptions); + void stopBatchingCommand(LocationAPI* client, uint32_t id); + void getBatchedLocationsCommand(LocationAPI* client, uint32_t id, size_t count); + /* ======== RESPONSES ================================================================== */ + void reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId); + /* ======== UTILITIES ================================================================== */ + bool hasBatchingCallback(LocationAPI* client); + bool isBatchingSession(LocationAPI* client, uint32_t sessionId); + bool isTripSession(uint32_t sessionId); + void saveBatchingSession(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions); + void eraseBatchingSession(LocationAPI* client, uint32_t sessionId); + uint32_t autoReportBatchingSessionsCount(); + void startBatching(LocationAPI* client, uint32_t sessionId, + const BatchingOptions& batchingOptions); + void stopBatching(LocationAPI* client, uint32_t sessionId, bool restartNeeded, + const BatchingOptions& batchOptions); + void stopBatching(LocationAPI* client, uint32_t sessionId) { + BatchingOptions batchOptions; + stopBatching(client, sessionId, false, batchOptions); + }; + + /* ==== REPORTS ======================================================================== */ + /* ======== EVENTS ====(Called from QMI Thread)========================================= */ + void reportLocationsEvent(const Location* locations, size_t count, + BatchingMode batchingMode); + void reportCompletedTripsEvent(uint32_t accumulatedDistance); + void reportBatchStatusChangeEvent(BatchingStatus batchStatus); + /* ======== UTILITIES ================================================================== */ + void reportLocations(Location* locations, size_t count, BatchingMode batchingMode); + void reportBatchStatusChange(BatchingStatus batchStatus, + std::list & completedTripsList); + + /* ==== CONFIGURATION ================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void readConfigCommand(); + void setConfigCommand(); + /* ======== UTILITIES ================================================================== */ + void setBatchSize(size_t batchSize) { mBatchSize = batchSize; } + size_t getBatchSize() { return mBatchSize; } + void setTripBatchSize(size_t batchSize) { mTripBatchSize = batchSize; } + size_t getTripBatchSize() { return mTripBatchSize; } + void setBatchingTimeout(uint32_t batchingTimeout) { mBatchingTimeout = batchingTimeout; } + uint32_t getBatchingTimeout() { return mBatchingTimeout; } + void setBatchingAccuracy(uint32_t accuracy) { mBatchingAccuracy = accuracy; } + uint32_t getBatchingAccuracy() { return mBatchingAccuracy; } + +}; + +#endif /* BATCHING_ADAPTER_H */ diff --git a/gps/batching/Makefile.am b/gps/batching/Makefile.am new file mode 100644 index 0000000..d5cba39 --- /dev/null +++ b/gps/batching/Makefile.am @@ -0,0 +1,44 @@ +AM_CFLAGS = \ + $(GPSUTILS_CFLAGS) \ + $(LOCCORE_CFLAGS) \ + -I./ \ + -std=c++1y \ + -D__func__=__PRETTY_FUNCTION__ \ + -fno-short-enums + +ACLOCAL_AMFLAGS = -I m4 + +requiredlibs = \ + $(GPSUTILS_LIBS) \ + $(LOCCORE_LIBS) \ + -llog + +h_sources = \ + BatchingAdapter.h + +libbatching_la_SOURCES = \ + location_batching.cpp \ + BatchingAdapter.cpp + +if USE_GLIB +libbatching_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +libbatching_la_LDFLAGS = -lstdc++ -g -Wl,-z,defs -lpthread $(requiredlibs) @GLIB_LIBS@ -shared -version-info 1:0:0 +libbatching_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +libbatching_la_CFLAGS = $(AM_CFLAGS) +libbatching_la_LDFLAGS = -Wl,-z,defs -lpthread $(requiredlibs) -shared -version-info 1:0:0 +libbatching_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +library_include_HEADERS = $(h_sources) + +library_includedir = $(pkgincludedir) + +#Create and Install libraries +lib_LTLIBRARIES = libbatching.la + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = location-batching.pc +sysconf_DATA = $(WORKSPACE)/hardware/qcom/gps/etc/flp.conf +EXTRA_DIST = $(pkgconfig_DATA) + diff --git a/gps/batching/configure.ac b/gps/batching/configure.ac new file mode 100644 index 0000000..4ca4998 --- /dev/null +++ b/gps/batching/configure.ac @@ -0,0 +1,74 @@ +# configure.ac -- Autoconf script for gps location-batching +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps location-batching package version 1.0.0 +AC_INIT([location-batching],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign subdir-objects]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([Makefile.am]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Checks for libraries. +PKG_CHECK_MODULES([GPSUTILS], [gps-utils]) +AC_SUBST([GPSUTILS_CFLAGS]) +AC_SUBST([GPSUTILS_LIBS]) + +PKG_CHECK_MODULES([LOCCORE], [loc-core]) +AC_SUBST([LOCCORE_CFLAGS]) +AC_SUBST([LOCCORE_LIBS]) + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x$with_locpla_includes" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + location-batching.pc + ]) + +AC_OUTPUT diff --git a/gps/batching/location-batching.pc.in b/gps/batching/location-batching.pc.in new file mode 100644 index 0000000..da1fbf4 --- /dev/null +++ b/gps/batching/location-batching.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: location-batching +Description: QTI GPS Batching +Version: @VERSION +Libs: -L${libdir} -lbatching +Cflags: -I${includedir}/location-batching diff --git a/gps/batching/location_batching.cpp b/gps/batching/location_batching.cpp new file mode 100644 index 0000000..571da72 --- /dev/null +++ b/gps/batching/location_batching.cpp @@ -0,0 +1,134 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "BatchingAdapter.h" +#include "location_interface.h" + +static BatchingAdapter* gBatchingAdapter = NULL; + +static void initialize(); +static void deinitialize(); + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks); +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb); +static void requestCapabilities(LocationAPI* client); + +static uint32_t startBatching(LocationAPI* client, BatchingOptions&); +static void stopBatching(LocationAPI* client, uint32_t id); +static void updateBatchingOptions(LocationAPI* client, uint32_t id, BatchingOptions&); +static void getBatchedLocations(LocationAPI* client, uint32_t id, size_t count); + +static const BatchingInterface gBatchingInterface = { + sizeof(BatchingInterface), + initialize, + deinitialize, + addClient, + removeClient, + requestCapabilities, + startBatching, + stopBatching, + updateBatchingOptions, + getBatchedLocations +}; + +#ifndef DEBUG_X86 +extern "C" const BatchingInterface* getBatchingInterface() +#else +const BatchingInterface* getBatchingInterface() +#endif // DEBUG_X86 +{ + return &gBatchingInterface; +} + +static void initialize() +{ + if (NULL == gBatchingAdapter) { + gBatchingAdapter = new BatchingAdapter(); + } +} + +static void deinitialize() +{ + if (NULL != gBatchingAdapter) { + delete gBatchingAdapter; + gBatchingAdapter = NULL; + } +} + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->addClientCommand(client, callbacks); + } +} + +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->removeClientCommand(client, rmClientCb); + } +} + +static void requestCapabilities(LocationAPI* client) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->requestCapabilitiesCommand(client); + } +} + +static uint32_t startBatching(LocationAPI* client, BatchingOptions &batchOptions) +{ + if (NULL != gBatchingAdapter) { + return gBatchingAdapter->startBatchingCommand(client, batchOptions); + } else { + return 0; + } +} + +static void stopBatching(LocationAPI* client, uint32_t id) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->stopBatchingCommand(client, id); + } +} + +static void updateBatchingOptions( + LocationAPI* client, uint32_t id, BatchingOptions& batchOptions) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->updateBatchingOptionsCommand(client, id, batchOptions); + } +} + +static void getBatchedLocations(LocationAPI* client, uint32_t id, size_t count) +{ + if (NULL != gBatchingAdapter) { + gBatchingAdapter->getBatchedLocationsCommand(client, id, count); + } +} + diff --git a/gps/configure.ac b/gps/configure.ac new file mode 100644 index 0000000..2a44051 --- /dev/null +++ b/gps/configure.ac @@ -0,0 +1,87 @@ +# configure.ac -- Autoconf script for gps loc_hal +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps loc-hal package version 1.0.0 +AC_INIT([loc-hal],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign subdir-objects]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([Makefile.am]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Checks for libraries. +PKG_CHECK_MODULES([GPSUTILS], [gps-utils]) +AC_SUBST([GPSUTILS_CFLAGS]) +AC_SUBST([GPSUTILS_LIBS]) + +PKG_CHECK_MODULES([LOCCORE], [loc-core]) +AC_SUBST([LOCCORE_CFLAGS]) +AC_SUBST([LOCCORE_LIBS]) + +AC_ARG_WITH([core_includes], + AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], + [Specify the location of the core headers]), + [core_incdir=$withval], + with_core_includes=no) + +if test "x$with_core_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${core_incdir}" +fi + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x$with_locpla_includes" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_SUBST([CPPFLAGS]) + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + gnss/Makefile \ + loc-hal.pc \ + ]) + +AC_OUTPUT diff --git a/gps/core/Android.bp b/gps/core/Android.bp new file mode 100644 index 0000000..ee8e807 --- /dev/null +++ b/gps/core/Android.bp @@ -0,0 +1,56 @@ + +cc_library_shared { + + name: "libloc_core", + vendor: true, + + sanitize: GNSS_SANITIZE, + + shared_libs: [ + "liblog", + "libutils", + "libcutils", + "libgps.utils", + "libdl", + "liblog", + ], + + srcs: [ + "LocApiBase.cpp", + "LocAdapterBase.cpp", + "ContextBase.cpp", + "LocContext.cpp", + "loc_core_log.cpp", + "data-items/DataItemsFactoryProxy.cpp", + "SystemStatusOsObserver.cpp", + "SystemStatus.cpp", + ], + + cflags: [ + "-fno-short-enums", + "-D_ANDROID_", + ] + GNSS_CFLAGS, + + local_include_dirs: [ + "data-items", + "observer", + ], + + header_libs: [ + "libutils_headers", + "libgps.utils_headers", + "libloc_pla_headers", + "liblocation_api_headers", + ], + +} + +cc_library_headers { + + name: "libloc_core_headers", + vendor: true, + export_include_dirs: ["."] + [ + "data-items", + "observer", + ], +} diff --git a/gps/core/ContextBase.cpp b/gps/core/ContextBase.cpp new file mode 100644 index 0000000..87e98dc --- /dev/null +++ b/gps/core/ContextBase.cpp @@ -0,0 +1,384 @@ +/* Copyright (c) 2011-2014,2016-2017,2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_CtxBase" + +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +#define SLL_LOC_API_LIB_NAME "libsynergy_loc_api.so" +#define LOC_APIV2_0_LIB_NAME "libloc_api_v02.so" +#define IS_SS5_HW_ENABLED 1 + +loc_gps_cfg_s_type ContextBase::mGps_conf {}; +loc_sap_cfg_s_type ContextBase::mSap_conf {}; +bool ContextBase::sIsEngineCapabilitiesKnown = false; +uint64_t ContextBase::sSupportedMsgMask = 0; +bool ContextBase::sGnssMeasurementSupported = false; +uint8_t ContextBase::sFeaturesSupported[MAX_FEATURE_LENGTH]; +GnssNMEARptRate ContextBase::sNmeaReportRate = GNSS_NMEA_REPORT_RATE_NHZ; +LocationCapabilitiesMask ContextBase::sQwesFeatureMask = 0; + +const loc_param_s_type ContextBase::mGps_conf_table[] = +{ + {"GPS_LOCK", &mGps_conf.GPS_LOCK, NULL, 'n'}, + {"SUPL_VER", &mGps_conf.SUPL_VER, NULL, 'n'}, + {"LPP_PROFILE", &mGps_conf.LPP_PROFILE, NULL, 'n'}, + {"A_GLONASS_POS_PROTOCOL_SELECT", &mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'}, + {"LPPE_CP_TECHNOLOGY", &mGps_conf.LPPE_CP_TECHNOLOGY, NULL, 'n'}, + {"LPPE_UP_TECHNOLOGY", &mGps_conf.LPPE_UP_TECHNOLOGY, NULL, 'n'}, + {"AGPS_CERT_WRITABLE_MASK", &mGps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'}, + {"SUPL_MODE", &mGps_conf.SUPL_MODE, NULL, 'n'}, + {"SUPL_ES", &mGps_conf.SUPL_ES, NULL, 'n'}, + {"INTERMEDIATE_POS", &mGps_conf.INTERMEDIATE_POS, NULL, 'n'}, + {"ACCURACY_THRES", &mGps_conf.ACCURACY_THRES, NULL, 'n'}, + {"NMEA_PROVIDER", &mGps_conf.NMEA_PROVIDER, NULL, 'n'}, + {"NMEA_REPORT_RATE", &mGps_conf.NMEA_REPORT_RATE, NULL, 's'}, + {"CAPABILITIES", &mGps_conf.CAPABILITIES, NULL, 'n'}, + {"XTRA_SERVER_1", &mGps_conf.XTRA_SERVER_1, NULL, 's'}, + {"XTRA_SERVER_2", &mGps_conf.XTRA_SERVER_2, NULL, 's'}, + {"XTRA_SERVER_3", &mGps_conf.XTRA_SERVER_3, NULL, 's'}, + {"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", + &mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL, NULL, 'n'}, + {"AGPS_CONFIG_INJECT", &mGps_conf.AGPS_CONFIG_INJECT, NULL, 'n'}, + {"EXTERNAL_DR_ENABLED", &mGps_conf.EXTERNAL_DR_ENABLED, NULL, 'n'}, + {"SUPL_HOST", &mGps_conf.SUPL_HOST, NULL, 's'}, + {"SUPL_PORT", &mGps_conf.SUPL_PORT, NULL, 'n'}, + {"MODEM_TYPE", &mGps_conf.MODEM_TYPE, NULL, 'n' }, + {"MO_SUPL_HOST", &mGps_conf.MO_SUPL_HOST, NULL, 's' }, + {"MO_SUPL_PORT", &mGps_conf.MO_SUPL_PORT, NULL, 'n' }, + {"CONSTRAINED_TIME_UNCERTAINTY_ENABLED", + &mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED, NULL, 'n'}, + {"CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD", + &mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD, NULL, 'f'}, + {"CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET", + &mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET, NULL, 'n'}, + {"POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED", + &mGps_conf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED, NULL, 'n'}, + {"PROXY_APP_PACKAGE_NAME", &mGps_conf.PROXY_APP_PACKAGE_NAME, NULL, 's' }, + {"CP_MTLR_ES", &mGps_conf.CP_MTLR_ES, NULL, 'n' }, + {"GNSS_DEPLOYMENT", &mGps_conf.GNSS_DEPLOYMENT, NULL, 'n'}, + {"CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED", + &mGps_conf.CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED, NULL, 'n'}, + {"NMEA_TAG_BLOCK_GROUPING_ENABLED", &mGps_conf.NMEA_TAG_BLOCK_GROUPING_ENABLED, NULL, 'n'}, + {"NI_SUPL_DENY_ON_NFW_LOCKED", &mGps_conf.NI_SUPL_DENY_ON_NFW_LOCKED, NULL, 'n'}, + {"ENABLE_NMEA_PRINT", &mGps_conf.ENABLE_NMEA_PRINT, NULL, 'n'} +}; + +const loc_param_s_type ContextBase::mSap_conf_table[] = +{ + {"GYRO_BIAS_RANDOM_WALK", &mSap_conf.GYRO_BIAS_RANDOM_WALK, &mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'}, + {"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"ANGLE_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"RATE_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, + {"SENSOR_ACCEL_BATCHES_PER_SEC", &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, NULL, 'n'}, + {"SENSOR_ACCEL_SAMPLES_PER_BATCH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, NULL, 'n'}, + {"SENSOR_GYRO_BATCHES_PER_SEC", &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC, NULL, 'n'}, + {"SENSOR_GYRO_SAMPLES_PER_BATCH", &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, NULL, 'n'}, + {"SENSOR_ACCEL_BATCHES_PER_SEC_HIGH", &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, NULL, 'n'}, + {"SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, NULL, 'n'}, + {"SENSOR_GYRO_BATCHES_PER_SEC_HIGH", &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, NULL, 'n'}, + {"SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH", &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, NULL, 'n'}, + {"SENSOR_CONTROL_MODE", &mSap_conf.SENSOR_CONTROL_MODE, NULL, 'n'}, + {"SENSOR_ALGORITHM_CONFIG_MASK", &mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK, NULL, 'n'} +}; + +void ContextBase::readConfig() +{ + static bool confReadDone = false; + if (!confReadDone) { + confReadDone = true; + /*Defaults for gps.conf*/ + mGps_conf.INTERMEDIATE_POS = 0; + mGps_conf.ACCURACY_THRES = 0; + mGps_conf.NMEA_PROVIDER = 0; + mGps_conf.GPS_LOCK = GNSS_CONFIG_GPS_LOCK_MO_AND_NI; + mGps_conf.SUPL_VER = 0x10000; + mGps_conf.SUPL_MODE = 0x1; + mGps_conf.SUPL_ES = 0; + mGps_conf.CP_MTLR_ES = 0; + mGps_conf.SUPL_HOST[0] = 0; + mGps_conf.SUPL_PORT = 0; + mGps_conf.CAPABILITIES = 0x7; + /* LTE Positioning Profile configuration is disable by default*/ + mGps_conf.LPP_PROFILE = 0; + /*By default no positioning protocol is selected on A-GLONASS system*/ + mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0; + /*Use emergency PDN by default*/ + mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = 1; + /* By default no LPPe CP technology is enabled*/ + mGps_conf.LPPE_CP_TECHNOLOGY = 0; + /* By default no LPPe UP technology is enabled*/ + mGps_conf.LPPE_UP_TECHNOLOGY = 0; + /* By default we use unknown modem type*/ + mGps_conf.MODEM_TYPE = 2; + + /*Defaults for sap.conf*/ + mSap_conf.GYRO_BIAS_RANDOM_WALK = 0; + mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2; + mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5; + mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2; + mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5; + mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH = 4; + mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH = 25; + mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH = 4; + mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH = 25; + mSap_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */ + mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK = 0; /* INS Disabled = FALSE*/ + /* Values MUST be set by OEMs in configuration for sensor-assisted + navigation to work. There are NO default values */ + mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY = 0; + mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY = 0; + mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY = 0; + mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY = 0; + mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0; + mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0; + + /* None of the 10 slots for agps certificates are writable by default */ + mGps_conf.AGPS_CERT_WRITABLE_MASK = 0; + + /* inject supl config to modem with config values from config.xml or gps.conf, default 1 */ + mGps_conf.AGPS_CONFIG_INJECT = 1; + + /* default configuration value of constrained time uncertainty mode: + feature disabled, time uncertainty threshold defined by modem, + and unlimited power budget */ +#ifdef FEATURE_AUTOMOTIVE + mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED = 1; +#else + mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED = 0; +#endif + mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD = 0.0; + mGps_conf.CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET = 0; + + /* default configuration value of position assisted clock estimator mode */ + mGps_conf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED = 0; + /* default configuration QTI GNSS H/W */ + mGps_conf.GNSS_DEPLOYMENT = 0; + mGps_conf.CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED = 0; + /* default NMEA Tag Block Grouping is disabled */ + mGps_conf.NMEA_TAG_BLOCK_GROUPING_ENABLED = 0; + /* default configuration for NI_SUPL_DENY_ON_NFW_LOCKED */ + mGps_conf.NI_SUPL_DENY_ON_NFW_LOCKED = 1; + /* By default NMEA Printing is disabled */ + mGps_conf.ENABLE_NMEA_PRINT = 0; + + UTIL_READ_CONF(LOC_PATH_GPS_CONF, mGps_conf_table); + UTIL_READ_CONF(LOC_PATH_SAP_CONF, mSap_conf_table); + + if (strncmp(mGps_conf.NMEA_REPORT_RATE, "1HZ", sizeof(mGps_conf.NMEA_REPORT_RATE)) == 0) { + /* NMEA reporting is configured at 1Hz*/ + sNmeaReportRate = GNSS_NMEA_REPORT_RATE_1HZ; + } else { + sNmeaReportRate = GNSS_NMEA_REPORT_RATE_NHZ; + } + LOC_LOGI("%s] GNSS Deployment: %s", __FUNCTION__, + ((mGps_conf.GNSS_DEPLOYMENT == 1) ? "SS5" : + ((mGps_conf.GNSS_DEPLOYMENT == 2) ? "QFUSION" : "QGNSS"))); + + switch (getTargetGnssType(loc_get_target())) { + case GNSS_GSS: + case GNSS_AUTO: + // For APQ targets, MSA/MSB capabilities should be reset + mGps_conf.CAPABILITIES &= ~(LOC_GPS_CAPABILITY_MSA | LOC_GPS_CAPABILITY_MSB); + break; + default: + break; + } + } +} + +uint32_t ContextBase::getCarrierCapabilities() { + #define carrierMSA (uint32_t)0x2 + #define carrierMSB (uint32_t)0x1 + #define gpsConfMSA (uint32_t)0x4 + #define gpsConfMSB (uint32_t)0x2 + uint32_t capabilities = mGps_conf.CAPABILITIES; + if ((mGps_conf.SUPL_MODE & carrierMSA) != carrierMSA) { + capabilities &= ~gpsConfMSA; + } + if ((mGps_conf.SUPL_MODE & carrierMSB) != carrierMSB) { + capabilities &= ~gpsConfMSB; + } + + LOC_LOGV("getCarrierCapabilities: CAPABILITIES %x, SUPL_MODE %x, carrier capabilities %x", + mGps_conf.CAPABILITIES, mGps_conf.SUPL_MODE, capabilities); + return capabilities; +} + +LBSProxyBase* ContextBase::getLBSProxy(const char* libName) +{ + LBSProxyBase* proxy = NULL; + LOC_LOGD("%s:%d]: getLBSProxy libname: %s\n", __func__, __LINE__, libName); + void* lib = dlopen(libName, RTLD_NOW); + + if ((void*)NULL != lib) { + getLBSProxy_t* getter = (getLBSProxy_t*)dlsym(lib, "getLBSProxy"); + if (NULL != getter) { + proxy = (*getter)(); + } + } + else + { + LOC_LOGW("%s:%d]: FAILED TO LOAD libname: %s\n", __func__, __LINE__, libName); + } + if (NULL == proxy) { + proxy = new LBSProxyBase(); + } + LOC_LOGD("%s:%d]: Exiting\n", __func__, __LINE__); + return proxy; +} + +LocApiBase* ContextBase::createLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask) +{ + LocApiBase* locApi = NULL; + const char* libname = LOC_APIV2_0_LIB_NAME; + + // Check the target + if (TARGET_NO_GNSS != loc_get_target()){ + + if (NULL == (locApi = mLBSProxy->getLocApi(exMask, this))) { + void *handle = NULL; + + if (IS_SS5_HW_ENABLED == mGps_conf.GNSS_DEPLOYMENT) { + libname = SLL_LOC_API_LIB_NAME; + } + + if ((handle = dlopen(libname, RTLD_NOW)) != NULL) { + LOC_LOGD("%s:%d]: %s is present", __func__, __LINE__, libname); + getLocApi_t* getter = (getLocApi_t*) dlsym(handle, "getLocApi"); + if (getter != NULL) { + LOC_LOGD("%s:%d]: getter is not NULL of %s", __func__, + __LINE__, libname); + locApi = (*getter)(exMask, this); + } + } + // only RPC is the option now + else { + LOC_LOGD("%s:%d]: libloc_api_v02.so is NOT present. Trying RPC", + __func__, __LINE__); + handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW); + if (NULL != handle) { + getLocApi_t* getter = (getLocApi_t*) dlsym(handle, "getLocApi"); + if (NULL != getter) { + LOC_LOGD("%s:%d]: getter is not NULL in RPC", __func__, + __LINE__); + locApi = (*getter)(exMask, this); + } + } + } + } + } + + // locApi could still be NULL at this time + // we would then create a dummy one + if (NULL == locApi) { + locApi = new LocApiBase(exMask, this); + } + + return locApi; +} + +ContextBase::ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + const char* libName) : + mLBSProxy(getLBSProxy(libName)), + mMsgTask(msgTask), + mLocApi(createLocApi(exMask)), + mLocApiProxy(mLocApi->getLocApiProxy()) +{ +} + +void ContextBase::setEngineCapabilities(uint64_t supportedMsgMask, + uint8_t *featureList, bool gnssMeasurementSupported) { + + if (ContextBase::sIsEngineCapabilitiesKnown == false) { + ContextBase::sSupportedMsgMask = supportedMsgMask; + ContextBase::sGnssMeasurementSupported = gnssMeasurementSupported; + if (featureList != NULL) { + memcpy((void *)ContextBase::sFeaturesSupported, + (void *)featureList, sizeof(ContextBase::sFeaturesSupported)); + } + + /* */ + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION)) { + static uint8_t isSapModeKnown = 0; + + if (!isSapModeKnown) { + /* Check if SAP is PREMIUM_ENV_AIDING in izat.conf */ + char conf_feature_sap[LOC_MAX_PARAM_STRING]; + loc_param_s_type izat_conf_feature_table[] = + { + { "SAP", &conf_feature_sap, &isSapModeKnown, 's' } + }; + UTIL_READ_CONF(LOC_PATH_IZAT_CONF, izat_conf_feature_table); + + /* Disable this feature if SAP is not PREMIUM_ENV_AIDING in izat.conf */ + if (strcmp(conf_feature_sap, "PREMIUM_ENV_AIDING") != 0) { + uint8_t arrayIndex = LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION >> 3; + uint8_t bitPos = LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION & 7; + + if (arrayIndex < MAX_FEATURE_LENGTH) { + /* To disable the feature we need to reset the bit on the "bitPos" + position, so shift a "1" to the left by "bitPos" */ + ContextBase::sFeaturesSupported[arrayIndex] &= ~(1 << bitPos); + } + } + } + } + ContextBase::sIsEngineCapabilitiesKnown = true; + } +} + + +bool ContextBase::isFeatureSupported(uint8_t featureVal) +{ + uint8_t arrayIndex = featureVal >> 3; + uint8_t bitPos = featureVal & 7; + + if (arrayIndex >= MAX_FEATURE_LENGTH) return false; + return ((ContextBase::sFeaturesSupported[arrayIndex] >> bitPos ) & 0x1); +} + +bool ContextBase::gnssConstellationConfig() { + return sGnssMeasurementSupported; +} + +} diff --git a/gps/core/ContextBase.h b/gps/core/ContextBase.h new file mode 100644 index 0000000..34cad60 --- /dev/null +++ b/gps/core/ContextBase.h @@ -0,0 +1,385 @@ +/* Copyright (c) 2011-2017, 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_CONTEXT_BASE__ +#define __LOC_CONTEXT_BASE__ + +#include +#include +#include +#include +#include +#include +#ifdef NO_UNORDERED_SET_OR_MAP + #include +#else + #include +#endif + +/* GPS.conf support */ +/* NOTE: the implementaiton of the parser casts number + fields to 32 bit. To ensure all 'n' fields working, + they must all be 32 bit fields. */ +typedef struct loc_gps_cfg_s +{ + uint32_t INTERMEDIATE_POS; + uint32_t ACCURACY_THRES; + uint32_t SUPL_VER; + uint32_t SUPL_MODE; + uint32_t SUPL_ES; + uint32_t CAPABILITIES; + uint32_t LPP_PROFILE; + char XTRA_SERVER_1[LOC_MAX_PARAM_STRING]; + char XTRA_SERVER_2[LOC_MAX_PARAM_STRING]; + char XTRA_SERVER_3[LOC_MAX_PARAM_STRING]; + uint32_t USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL; + uint32_t NMEA_PROVIDER; + char NMEA_REPORT_RATE[LOC_MAX_PARAM_NAME]; + GnssConfigGpsLock GPS_LOCK; + uint32_t A_GLONASS_POS_PROTOCOL_SELECT; + uint32_t AGPS_CERT_WRITABLE_MASK; + uint32_t AGPS_CONFIG_INJECT; + uint32_t LPPE_CP_TECHNOLOGY; + uint32_t LPPE_UP_TECHNOLOGY; + uint32_t EXTERNAL_DR_ENABLED; + char SUPL_HOST[LOC_MAX_PARAM_STRING]; + uint32_t SUPL_PORT; + uint32_t MODEM_TYPE; + char MO_SUPL_HOST[LOC_MAX_PARAM_STRING]; + uint32_t MO_SUPL_PORT; + uint32_t CONSTRAINED_TIME_UNCERTAINTY_ENABLED; + double CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD; + uint32_t CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET; + uint32_t POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED; + char PROXY_APP_PACKAGE_NAME[LOC_MAX_PARAM_STRING]; + uint32_t CP_MTLR_ES; + uint32_t GNSS_DEPLOYMENT; + uint32_t CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED; + uint32_t NI_SUPL_DENY_ON_NFW_LOCKED; + uint32_t ENABLE_NMEA_PRINT; + uint32_t NMEA_TAG_BLOCK_GROUPING_ENABLED; +} loc_gps_cfg_s_type; + +/* NOTE: the implementation of the parser casts number + fields to 32 bit. To ensure all 'n' fields working, + they must all be 32 bit fields. */ +/* Meanwhile, *_valid fields are 8 bit fields, and 'f' + fields are double. Rigid as they are, it is the + the status quo, until the parsing mechanism is + changed, that is. */ +typedef struct +{ + uint8_t GYRO_BIAS_RANDOM_WALK_VALID; + double GYRO_BIAS_RANDOM_WALK; + uint32_t SENSOR_ACCEL_BATCHES_PER_SEC; + uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH; + uint32_t SENSOR_GYRO_BATCHES_PER_SEC; + uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH; + uint32_t SENSOR_ACCEL_BATCHES_PER_SEC_HIGH; + uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH; + uint32_t SENSOR_GYRO_BATCHES_PER_SEC_HIGH; + uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH; + uint32_t SENSOR_CONTROL_MODE; + uint32_t SENSOR_ALGORITHM_CONFIG_MASK; + uint8_t ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double ACCEL_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double ANGLE_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double RATE_RANDOM_WALK_SPECTRAL_DENSITY; + uint8_t VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID; + double VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY; +} loc_sap_cfg_s_type; + +using namespace loc_util; + +namespace loc_core { + +class LocAdapterBase; + +class ContextBase { + static LBSProxyBase* getLBSProxy(const char* libName); + LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask); + static const loc_param_s_type mGps_conf_table[]; + static const loc_param_s_type mSap_conf_table[]; +protected: + const LBSProxyBase* mLBSProxy; + const MsgTask* mMsgTask; + LocApiBase* mLocApi; + LocApiProxyBase *mLocApiProxy; + +public: + ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + const char* libName); + inline virtual ~ContextBase() { + if (nullptr != mLocApi) { + mLocApi->destroy(); + mLocApi = nullptr; + } + if (nullptr != mLBSProxy) { + delete mLBSProxy; + mLBSProxy = nullptr; + } + } + + inline const MsgTask* getMsgTask() { return mMsgTask; } + inline LocApiBase* getLocApi() { return mLocApi; } + inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; } + inline bool hasAgpsExtendedCapabilities() { return mLBSProxy->hasAgpsExtendedCapabilities(); } + inline bool hasNativeXtraClient() { return mLBSProxy->hasNativeXtraClient(); } + inline void modemPowerVote(bool power) const { return mLBSProxy->modemPowerVote(power); } + inline IzatDevId_t getIzatDevId() const { + return mLBSProxy->getIzatDevId(); + } + inline void sendMsg(const LocMsg *msg) { getMsgTask()->sendMsg(msg); } + + static loc_gps_cfg_s_type mGps_conf; + static loc_sap_cfg_s_type mSap_conf; + static bool sIsEngineCapabilitiesKnown; + static uint64_t sSupportedMsgMask; + static uint8_t sFeaturesSupported[MAX_FEATURE_LENGTH]; + static bool sGnssMeasurementSupported; + static GnssNMEARptRate sNmeaReportRate; + static LocationCapabilitiesMask sQwesFeatureMask; + + void readConfig(); + static uint32_t getCarrierCapabilities(); + void setEngineCapabilities(uint64_t supportedMsgMask, + uint8_t *featureList, bool gnssMeasurementSupported); + + static inline bool isEngineCapabilitiesKnown() { + return sIsEngineCapabilitiesKnown; + } + + static inline bool isMessageSupported(LocCheckingMessagesID msgID) { + + // confirm if msgID is not larger than the number of bits in + // mSupportedMsg + if ((uint64_t)msgID > (sizeof(sSupportedMsgMask) << 3)) { + return false; + } else { + uint32_t messageChecker = 1 << msgID; + return (messageChecker & sSupportedMsgMask) == messageChecker; + } + } + + /* + Check if a feature is supported + */ + static bool isFeatureSupported(uint8_t featureVal); + + /* + Check if gnss measurement is supported + */ + static bool gnssConstellationConfig(); + + /* + set QWES feature status info + */ + static inline void setQwesFeatureStatus( + const std::unordered_map &featureMap) { + std::unordered_map::const_iterator itr; + static LocationQwesFeatureType locQwesFeatType[LOCATION_QWES_FEATURE_TYPE_MAX]; + for (itr = featureMap.begin(); itr != featureMap.end(); ++itr) { + LOC_LOGi("Feature : %d isValid: %d", itr->first, itr->second); + locQwesFeatType[itr->first] = itr->second; + switch (itr->first) { + case LOCATION_QWES_FEATURE_TYPE_CARRIER_PHASE: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_CARRIER_PHASE_BIT; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_CARRIER_PHASE_BIT; + } + break; + case LOCATION_QWES_FEATURE_TYPE_SV_POLYNOMIAL: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_SV_POLYNOMIAL_BIT; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_SV_POLYNOMIAL_BIT; + } + break; + case LOCATION_QWES_FEATURE_TYPE_GNSS_SINGLE_FREQUENCY: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_GNSS_SINGLE_FREQUENCY; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_GNSS_SINGLE_FREQUENCY; + } + break; + case LOCATION_QWES_FEATURE_TYPE_SV_EPH: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_SV_EPHEMERIS_BIT; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_SV_EPHEMERIS_BIT; + } + break; + case LOCATION_QWES_FEATURE_TYPE_GNSS_MULTI_FREQUENCY: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_GNSS_MULTI_FREQUENCY; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_GNSS_MULTI_FREQUENCY; + } + break; + case LOCATION_QWES_FEATURE_TYPE_PPE: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_PPE; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_PPE; + } + break; + case LOCATION_QWES_FEATURE_TYPE_QDR2: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_QDR2; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_QDR2; + } + break; + case LOCATION_QWES_FEATURE_TYPE_QDR3: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_QDR3; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_QDR3; + } + break; + case LOCATION_QWES_FEATURE_TYPE_VPE: + if (itr->second) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_VPE; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_VPE; + } + break; + } + } + + // Set CV2X basic when time freq and tunc is set + // CV2X_BASIC = LOCATION_QWES_FEATURE_TYPE_TIME_FREQUENCY & + // LOCATION_QWES_FEATURE_TYPE_TIME_UNCERTAINTY + + // Set CV2X premium when time freq and tunc is set + // CV2X_PREMIUM = CV2X_BASIC & LOCATION_QWES_FEATURE_TYPE_QDR3 & + // LOCATION_QWES_FEATURE_TYPE_CLOCK_ESTIMATE + + bool cv2xBasicEnabled = (1 == locQwesFeatType[LOCATION_QWES_FEATURE_TYPE_TIME_FREQUENCY]) && + (1 == locQwesFeatType[LOCATION_QWES_FEATURE_TYPE_TIME_UNCERTAINTY]); + bool cv2xPremiumEnabled = cv2xBasicEnabled && + (1 == locQwesFeatType[LOCATION_QWES_FEATURE_TYPE_QDR3]) && + (1 == locQwesFeatType[LOCATION_QWES_FEATURE_TYPE_CLOCK_ESTIMATE]); + + LOC_LOGd("CV2X_BASIC:%d, CV2X_PREMIUM:%d", cv2xBasicEnabled, cv2xPremiumEnabled); + if (cv2xBasicEnabled) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_BASIC; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_BASIC; + } + if (cv2xPremiumEnabled) { + sQwesFeatureMask |= LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_PREMIUM; + } else { + sQwesFeatureMask &= ~LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_PREMIUM; + } + } + + /* + get QWES feature status info + */ + static inline LocationCapabilitiesMask getQwesFeatureStatus() { + return (ContextBase::sQwesFeatureMask); + } + + +}; + +struct LocApiResponse: LocMsg { + private: + ContextBase& mContext; + std::function mProcImpl; + inline virtual void proc() const { + mProcImpl(mLocationError); + } + protected: + LocationError mLocationError; + public: + inline LocApiResponse(ContextBase& context, + std::function procImpl ) : + mContext(context), mProcImpl(procImpl) {} + + void returnToSender(const LocationError err) { + mLocationError = err; + mContext.sendMsg(this); + } +}; + +struct LocApiCollectiveResponse: LocMsg { + private: + ContextBase& mContext; + std::function errs)> mProcImpl; + inline virtual void proc() const { + mProcImpl(mLocationErrors); + } + protected: + std::vector mLocationErrors; + public: + inline LocApiCollectiveResponse(ContextBase& context, + std::function errs)> procImpl ) : + mContext(context), mProcImpl(procImpl) {} + inline virtual ~LocApiCollectiveResponse() { + } + + void returnToSender(std::vector& errs) { + mLocationErrors = errs; + mContext.sendMsg(this); + } +}; + + +template +struct LocApiResponseData: LocMsg { + private: + ContextBase& mContext; + std::function mProcImpl; + inline virtual void proc() const { + mProcImpl(mLocationError, mData); + } + protected: + LocationError mLocationError; + DATA mData; + public: + inline LocApiResponseData(ContextBase& context, + std::function procImpl ) : + mContext(context), mProcImpl(procImpl) {} + + void returnToSender(const LocationError err, const DATA data) { + mLocationError = err; + mData = data; + mContext.sendMsg(this); + } +}; + + +} // namespace loc_core + +#endif //__LOC_CONTEXT_BASE__ diff --git a/gps/core/EngineHubProxyBase.h b/gps/core/EngineHubProxyBase.h new file mode 100644 index 0000000..468a8f0 --- /dev/null +++ b/gps/core/EngineHubProxyBase.h @@ -0,0 +1,160 @@ +/* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef ENGINE_HUB_PROXY_BASE_H +#define ENGINE_HUB_PROXY_BASE_H +#ifdef NO_UNORDERED_SET_OR_MAP + #include +#else + #include +#endif + +namespace loc_core { + +using namespace loc_util; + +class EngineHubProxyBase { +public: + inline EngineHubProxyBase() { + } + inline virtual ~EngineHubProxyBase() {} + + // gnss session related functions + inline virtual bool gnssStartFix() { + return false; + } + + inline virtual bool gnssStopFix() { + return false; + } + + inline virtual bool gnssSetFixMode(const LocPosMode ¶ms) { + (void) params; + return false; + } + + inline virtual bool gnssDeleteAidingData(const GnssAidingData &aidingData) { + (void) aidingData; + return false; + } + + // GNSS reports + inline virtual bool gnssReportPosition(const UlpLocation &location, + const GpsLocationExtended &locationExtended, + enum loc_sess_status status) { + (void) location; + (void) locationExtended; + (void) status; + return false; + } + + inline virtual bool gnssReportSv(const GnssSvNotification& svNotify) { + (void) svNotify; + return false; + } + + inline virtual bool gnssReportSvMeasurement(const GnssSvMeasurementSet& svMeasurementSet) { + (void) svMeasurementSet; + return false; + } + + inline virtual bool gnssReportSvPolynomial(const GnssSvPolynomial& svPolynomial) { + (void) svPolynomial; + return false; + } + + inline virtual bool gnssReportSvEphemeris(const GnssSvEphemerisReport& svEphemeris) { + (void) svEphemeris; + return false; + } + + inline virtual bool gnssReportSystemInfo(const LocationSystemInfo& systemInfo) { + (void) systemInfo; + return false; + } + + inline virtual bool gnssReportKlobucharIonoModel(const GnssKlobucharIonoModel& ionoModel) { + (void) ionoModel; + return false; + } + + inline virtual bool gnssReportAdditionalSystemInfo( + const GnssAdditionalSystemInfo& additionalSystemInfo) { + (void) additionalSystemInfo; + return false; + } + + inline virtual bool configLeverArm(const LeverArmConfigInfo& configInfo) { + (void) configInfo; + return false; + } + + inline virtual bool configDeadReckoningEngineParams( + const DeadReckoningEngineConfig& dreConfig) { + (void) dreConfig; + return false; + } + + inline virtual bool configEngineRunState( + PositioningEngineMask engType, LocEngineRunState engState) { + (void) engType; + (void) engState; + return false; + } +}; + +typedef std::function + GnssAdapterReportEnginePositionsEventCb; + +typedef std::function + GnssAdapterReportSvEventCb; + +typedef std::function + GnssAdapterReqAidingDataCb; + +typedef std::function + GnssAdapterUpdateNHzRequirementCb; + +typedef std::function &featureMap)> + GnssAdapterUpdateQwesFeatureStatusCb; + +// potential parameters: message queue: MsgTask * msgTask; +// callback function to report back dr and ppe position and sv report +typedef EngineHubProxyBase* (getEngHubProxyFn)( + const MsgTask * msgTask, + IOsObserver* osObserver, + GnssAdapterReportEnginePositionsEventCb positionEventCb, + GnssAdapterReportSvEventCb svEventCb, + GnssAdapterReqAidingDataCb reqAidingDataCb, + GnssAdapterUpdateNHzRequirementCb updateNHzRequirementCb, + GnssAdapterUpdateQwesFeatureStatusCb updateQwesFeatureStatusCb); + +} // namespace loc_core + +#endif // ENGINE_HUB_PROXY_BASE_H diff --git a/gps/core/LBSProxyBase.h b/gps/core/LBSProxyBase.h new file mode 100644 index 0000000..564c60b --- /dev/null +++ b/gps/core/LBSProxyBase.h @@ -0,0 +1,70 @@ +/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef IZAT_PROXY_BASE_H +#define IZAT_PROXY_BASE_H +#include + +namespace loc_core { + +class LocApiBase; +class LocAdapterBase; +class ContextBase; + +class LBSProxyBase { + friend class ContextBase; + inline virtual LocApiBase* + getLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask, + ContextBase* context) const { + + (void)exMask; + (void)context; + return NULL; + } +protected: + inline LBSProxyBase() {} +public: + inline virtual ~LBSProxyBase() {} + inline virtual bool hasAgpsExtendedCapabilities() const { return false; } + inline virtual void modemPowerVote(bool power) const { + + (void)power; + } + virtual void injectFeatureConfig(ContextBase* context) const { + + (void)context; + } + inline virtual bool hasNativeXtraClient() const { return false; } + inline virtual IzatDevId_t getIzatDevId() const { return 0; } +}; + +typedef LBSProxyBase* (getLBSProxy_t)(); + +} // namespace loc_core + +#endif // IZAT_PROXY_BASE_H diff --git a/gps/core/LocAdapterBase.cpp b/gps/core/LocAdapterBase.cpp new file mode 100644 index 0000000..95f2728 --- /dev/null +++ b/gps/core/LocAdapterBase.cpp @@ -0,0 +1,439 @@ +/* Copyright (c) 2011-2014, 2016-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_LocAdapterBase" + +#include +#include +#include +#include +#include + +namespace loc_core { + +// This is the top level class, so the constructor will +// always gets called. Here we prepare for the default. +// But if getLocApi(targetEnumType target) is overriden, +// the right locApi should get created. +LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context, bool isMaster, + LocAdapterProxyBase *adapterProxyBase, + bool waitForDoneInit) : + mIsMaster(isMaster), mEvtMask(mask), mContext(context), + mLocApi(context->getLocApi()), mLocAdapterProxyBase(adapterProxyBase), + mMsgTask(context->getMsgTask()), + mIsEngineCapabilitiesKnown(ContextBase::sIsEngineCapabilitiesKnown) +{ + LOC_LOGd("waitForDoneInit: %d", waitForDoneInit); + if (!waitForDoneInit) { + mLocApi->addAdapter(this); + mAdapterAdded = true; + } else { + mAdapterAdded = false; + } +} + +uint32_t LocAdapterBase::mSessionIdCounter(1); + +uint32_t LocAdapterBase::generateSessionId() +{ + if (++mSessionIdCounter == 0xFFFFFFFF) + mSessionIdCounter = 1; + + return mSessionIdCounter; +} + +void LocAdapterBase::handleEngineUpEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineUpEvent(); + } +} + +void LocAdapterBase::handleEngineDownEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineDownEvent(); + } +} + +void LocAdapterBase:: + reportPositionEvent(const UlpLocation& location, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask, + GnssDataNotification* pDataNotify, + int msInWeek) +{ + if (mLocAdapterProxyBase != NULL) { + mLocAdapterProxyBase->reportPositionEvent((UlpLocation&)location, + (GpsLocationExtended&)locationExtended, + status, + loc_technology_mask); + } else { + DEFAULT_IMPL() + } +} + +void LocAdapterBase:: + reportSvEvent(const GnssSvNotification& /*svNotify*/, + bool /*fromEngineHub*/) +DEFAULT_IMPL() + +void LocAdapterBase:: + reportSvPolynomialEvent(GnssSvPolynomial &/*svPolynomial*/) +DEFAULT_IMPL() + +void LocAdapterBase:: + reportSvEphemerisEvent(GnssSvEphemerisReport &/*svEphemeris*/) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportStatus(LocGpsStatusValue /*status*/) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportNmeaEvent(const char* /*nmea*/, size_t /*length*/) +DEFAULT_IMPL() + +void LocAdapterBase:: + reportDataEvent(const GnssDataNotification& /*dataNotify*/, + int /*msInWeek*/) +DEFAULT_IMPL() + +bool LocAdapterBase:: + reportXtraServer(const char* /*url1*/, const char* /*url2*/, + const char* /*url3*/, const int /*maxlength*/) +DEFAULT_IMPL(false) + +void LocAdapterBase:: + reportLocationSystemInfoEvent(const LocationSystemInfo& /*locationSystemInfo*/) +DEFAULT_IMPL() + +bool LocAdapterBase:: + requestXtraData() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestTime() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestLocation() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestATL(int /*connHandle*/, LocAGpsType /*agps_type*/, + LocApnTypeMask /*apn_type_mask*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + releaseATL(int /*connHandle*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestNiNotifyEvent(const GnssNiNotification &/*notify*/, + const void* /*data*/, + const LocInEmergency emergencyState) +DEFAULT_IMPL(false) + +void LocAdapterBase:: +reportGnssMeasurementsEvent(const GnssMeasurements& /*gnssMeasurements*/, + int /*msInWeek*/) +DEFAULT_IMPL() + +bool LocAdapterBase:: + reportWwanZppFix(LocGpsLocation &/*zppLoc*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportZppBestAvailableFix(LocGpsLocation& /*zppLoc*/, + GpsLocationExtended& /*location_extended*/, LocPosTechMask /*tech_mask*/) +DEFAULT_IMPL(false) + +void LocAdapterBase::reportGnssSvIdConfigEvent(const GnssSvIdConfig& /*config*/) +DEFAULT_IMPL() + +void LocAdapterBase::reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& /*config*/) +DEFAULT_IMPL() + +void LocAdapterBase::reportGnssConfigEvent(uint32_t, /* session id*/ + const GnssConfig& /*gnssConfig*/) +DEFAULT_IMPL() + +bool LocAdapterBase:: + requestOdcpiEvent(OdcpiRequestInfo& /*request*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportGnssEngEnergyConsumedEvent(uint64_t /*energyConsumedSinceFirstBoot*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportDeleteAidingDataEvent(GnssAidingData & /*aidingData*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportKlobucharIonoModelEvent(GnssKlobucharIonoModel& /*ionoModel*/) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportGnssAdditionalSystemInfoEvent(GnssAdditionalSystemInfo& /*additionalSystemInfo*/) +DEFAULT_IMPL(false) + +void LocAdapterBase:: + reportNfwNotificationEvent(GnssNfwNotification& /*notification*/) +DEFAULT_IMPL() + +void +LocAdapterBase::geofenceBreachEvent(size_t /*count*/, uint32_t* /*hwIds*/, Location& /*location*/, + GeofenceBreachType /*breachType*/, uint64_t /*timestamp*/) +DEFAULT_IMPL() + +void +LocAdapterBase::geofenceStatusEvent(GeofenceStatusAvailable /*available*/) +DEFAULT_IMPL() + +void +LocAdapterBase::reportLocationsEvent(const Location* /*locations*/, size_t /*count*/, + BatchingMode /*batchingMode*/) +DEFAULT_IMPL() + +void +LocAdapterBase::reportCompletedTripsEvent(uint32_t /*accumulated_distance*/) +DEFAULT_IMPL() + +void +LocAdapterBase::reportBatchStatusChangeEvent(BatchingStatus /*batchStatus*/) +DEFAULT_IMPL() + +void +LocAdapterBase::reportPositionEvent(UlpLocation& /*location*/, + GpsLocationExtended& /*locationExtended*/, + enum loc_sess_status /*status*/, + LocPosTechMask /*loc_technology_mask*/) +DEFAULT_IMPL() + +void +LocAdapterBase::saveClient(LocationAPI* client, const LocationCallbacks& callbacks) +{ + mClientData[client] = callbacks; + updateClientsEventMask(); +} + +void +LocAdapterBase::eraseClient(LocationAPI* client) +{ + auto it = mClientData.find(client); + if (it != mClientData.end()) { + mClientData.erase(it); + } + updateClientsEventMask(); +} + +LocationCallbacks +LocAdapterBase::getClientCallbacks(LocationAPI* client) +{ + LocationCallbacks callbacks = {}; + auto it = mClientData.find(client); + if (it != mClientData.end()) { + callbacks = it->second; + } + return callbacks; +} + +LocationCapabilitiesMask +LocAdapterBase::getCapabilities() +{ + LocationCapabilitiesMask mask = 0; + + if (isEngineCapabilitiesKnown()) { + // time based tracking always supported + mask |= LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT; + if (ContextBase::isMessageSupported( + LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)){ + mask |= LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT | + LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT; + } + if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) { + mask |= LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT; + } + if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING)) { + mask |= LOCATION_CAPABILITIES_OUTDOOR_TRIP_BATCHING_BIT; + } + // geofence always supported + mask |= LOCATION_CAPABILITIES_GEOFENCE_BIT; + if (ContextBase::gnssConstellationConfig()) { + mask |= LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT; + } + uint32_t carrierCapabilities = ContextBase::getCarrierCapabilities(); + if (carrierCapabilities & LOC_GPS_CAPABILITY_MSB) { + mask |= LOCATION_CAPABILITIES_GNSS_MSB_BIT; + } + if (LOC_GPS_CAPABILITY_MSA & carrierCapabilities) { + mask |= LOCATION_CAPABILITIES_GNSS_MSA_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) { + mask |= LOCATION_CAPABILITIES_DEBUG_NMEA_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + mask |= LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_AGPM_V02)) { + mask |= LOCATION_CAPABILITIES_AGPM_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_LOCATION_PRIVACY)) { + mask |= LOCATION_CAPABILITIES_PRIVACY_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION)) { + mask |= LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_ROBUST_LOCATION)) { + mask |= LOCATION_CAPABILITIES_CONFORMITY_INDEX_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_EDGNSS)) { + mask |= LOCATION_CAPABILITIES_EDGNSS_BIT; + } + } else { + LOC_LOGE("%s]: attempt to get capabilities before they are known.", __func__); + } + + return mask; +} + +void +LocAdapterBase::broadcastCapabilities(LocationCapabilitiesMask mask) +{ + for (auto clientData : mClientData) { + if (nullptr != clientData.second.capabilitiesCb) { + clientData.second.capabilitiesCb(mask); + } + } +} + +void +LocAdapterBase::updateClientsEventMask() +DEFAULT_IMPL() + +void +LocAdapterBase::stopClientSessions(LocationAPI* client) +DEFAULT_IMPL() + +void +LocAdapterBase::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + struct MsgAddClient : public LocMsg { + LocAdapterBase& mAdapter; + LocationAPI* mClient; + const LocationCallbacks mCallbacks; + inline MsgAddClient(LocAdapterBase& adapter, + LocationAPI* client, + const LocationCallbacks& callbacks) : + LocMsg(), + mAdapter(adapter), + mClient(client), + mCallbacks(callbacks) {} + inline virtual void proc() const { + mAdapter.saveClient(mClient, mCallbacks); + } + }; + + sendMsg(new MsgAddClient(*this, client, callbacks)); +} + +void +LocAdapterBase::removeClientCommand(LocationAPI* client, + removeClientCompleteCallback rmClientCb) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + struct MsgRemoveClient : public LocMsg { + LocAdapterBase& mAdapter; + LocationAPI* mClient; + removeClientCompleteCallback mRmClientCb; + inline MsgRemoveClient(LocAdapterBase& adapter, + LocationAPI* client, + removeClientCompleteCallback rmCb) : + LocMsg(), + mAdapter(adapter), + mClient(client), + mRmClientCb(rmCb){} + inline virtual void proc() const { + mAdapter.stopClientSessions(mClient); + mAdapter.eraseClient(mClient); + if (nullptr != mRmClientCb) { + (mRmClientCb)(mClient); + } + } + }; + + sendMsg(new MsgRemoveClient(*this, client, rmClientCb)); +} + +void +LocAdapterBase::requestCapabilitiesCommand(LocationAPI* client) +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgRequestCapabilities : public LocMsg { + LocAdapterBase& mAdapter; + LocationAPI* mClient; + inline MsgRequestCapabilities(LocAdapterBase& adapter, + LocationAPI* client) : + LocMsg(), + mAdapter(adapter), + mClient(client) {} + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgRequestCapabilities(*this)); + return; + } + LocationCallbacks callbacks = mAdapter.getClientCallbacks(mClient); + if (callbacks.capabilitiesCb != nullptr) { + callbacks.capabilitiesCb(mAdapter.getCapabilities()); + } + } + }; + + sendMsg(new MsgRequestCapabilities(*this, client)); +} + +void +LocAdapterBase::reportLatencyInfoEvent(const GnssLatencyInfo& /*gnssLatencyInfo*/) +DEFAULT_IMPL() + +bool LocAdapterBase:: + reportQwesCapabilities(const std::unordered_map &featureMap) +DEFAULT_IMPL(false) + +} // namespace loc_core diff --git a/gps/core/LocAdapterBase.h b/gps/core/LocAdapterBase.h new file mode 100644 index 0000000..51b2306 --- /dev/null +++ b/gps/core/LocAdapterBase.h @@ -0,0 +1,246 @@ +/* Copyright (c) 2011-2014, 2016-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_API_ADAPTER_BASE_H +#define LOC_API_ADAPTER_BASE_H + +#include +#include +#include +#include + +#define MIN_TRACKING_INTERVAL (100) // 100 msec + +typedef struct LocationSessionKey { + LocationAPI* client; + uint32_t id; + inline LocationSessionKey(LocationAPI* _client, uint32_t _id) : + client(_client), id(_id) {} +} LocationSessionKey; +inline bool operator <(LocationSessionKey const& left, LocationSessionKey const& right) { + return left.id < right.id || (left.id == right.id && left.client < right.client); +} +inline bool operator ==(LocationSessionKey const& left, LocationSessionKey const& right) { + return left.id == right.id && left.client == right.client; +} +inline bool operator !=(LocationSessionKey const& left, LocationSessionKey const& right) { + return left.id != right.id || left.client != right.client; +} + +typedef void (*removeClientCompleteCallback)(LocationAPI* client); + +namespace loc_core { + +class LocAdapterProxyBase; + +class LocAdapterBase { +private: + static uint32_t mSessionIdCounter; + const bool mIsMaster; + bool mIsEngineCapabilitiesKnown = false; + +protected: + LOC_API_ADAPTER_EVENT_MASK_T mEvtMask; + ContextBase* mContext; + LocApiBase* mLocApi; + LocAdapterProxyBase* mLocAdapterProxyBase; + const MsgTask* mMsgTask; + bool mAdapterAdded; + + inline LocAdapterBase(const MsgTask* msgTask) : + mIsMaster(false), mEvtMask(0), mContext(NULL), mLocApi(NULL), + mLocAdapterProxyBase(NULL), mMsgTask(msgTask), mAdapterAdded(false) {} + + /* ==== CLIENT ========================================================================= */ + typedef std::map ClientDataMap; + ClientDataMap mClientData; + std::vector mPendingMsgs; // For temporal storage of msgs before Open is completed + /* ======== UTILITIES ================================================================== */ + void saveClient(LocationAPI* client, const LocationCallbacks& callbacks); + void eraseClient(LocationAPI* client); + LocationCallbacks getClientCallbacks(LocationAPI* client); + LocationCapabilitiesMask getCapabilities(); + void broadcastCapabilities(LocationCapabilitiesMask mask); + virtual void updateClientsEventMask(); + virtual void stopClientSessions(LocationAPI* client); + +public: + inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } + // When waitForDoneInit is not specified or specified as false, + // handleEngineUpEvent may be called on the child adapter object from + // a different thread before the constructor of the child + // object finishes. + // + // If the handleEngineUpEvent relies on member variables of the constructor + // of the child adapter to be initialized first, we need to specify the + // waitForDoneInit to *TRUE* to delay handleEngineUpEvent to get called + // until when the child adapter finishes its initialization and notify + // LocAdapterBase via doneInit method. + LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context, bool isMaster = false, + LocAdapterProxyBase *adapterProxyBase = NULL, + bool waitForDoneInit = false); + + inline void doneInit() { + if (!mAdapterAdded) { + mLocApi->addAdapter(this); + mAdapterAdded = true; + } + } + + inline LOC_API_ADAPTER_EVENT_MASK_T + checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const { + return mEvtMask & mask; + } + + inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const { + return mEvtMask; + } + + inline void sendMsg(const LocMsg* msg) const { + mMsgTask->sendMsg(msg); + } + + inline void sendMsg(const LocMsg* msg) { + mMsgTask->sendMsg(msg); + } + + inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status status) + { + switch(status) { + case (LOC_REGISTRATION_MASK_ENABLED): + mEvtMask = mEvtMask | event; + break; + case (LOC_REGISTRATION_MASK_DISABLED): + mEvtMask = mEvtMask &~ event; + break; + case (LOC_REGISTRATION_MASK_SET): + mEvtMask = event; + break; + } + mLocApi->updateEvtMask(); + } + + inline void updateNmeaMask(uint32_t mask) + { + mLocApi->updateNmeaMask(mask); + } + + inline bool isFeatureSupported(uint8_t featureVal) { + return ContextBase::isFeatureSupported(featureVal); + } + + static uint32_t generateSessionId(); + + inline bool isAdapterMaster() { + return mIsMaster; + } + + inline bool isEngineCapabilitiesKnown() { return mIsEngineCapabilitiesKnown;} + inline void setEngineCapabilitiesKnown(bool value) { mIsEngineCapabilitiesKnown = value;} + + virtual void handleEngineUpEvent(); + virtual void handleEngineDownEvent(); + virtual void reportPositionEvent(const UlpLocation& location, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask, + GnssDataNotification* pDataNotify = nullptr, + int msInWeek = -1); + virtual void reportEnginePositionsEvent(unsigned int count, + EngineLocationInfo* locationArr) { + (void)count; + (void)locationArr; + } + virtual void reportSvEvent(const GnssSvNotification& svNotify, + bool fromEngineHub=false); + virtual void reportDataEvent(const GnssDataNotification& dataNotify, int msInWeek); + virtual void reportNmeaEvent(const char* nmea, size_t length); + virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial); + virtual void reportSvEphemerisEvent(GnssSvEphemerisReport &svEphemeris); + virtual void reportStatus(LocGpsStatusValue status); + virtual bool reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + virtual void reportLocationSystemInfoEvent(const LocationSystemInfo& locationSystemInfo); + + virtual bool requestXtraData(); + virtual bool requestTime(); + virtual bool requestLocation(); + virtual bool requestATL(int connHandle, LocAGpsType agps_type, + LocApnTypeMask apn_type_mask); + virtual bool releaseATL(int connHandle); + virtual bool requestNiNotifyEvent(const GnssNiNotification ¬ify, const void* data, + const LocInEmergency emergencyState); + inline virtual bool isInSession() { return false; } + ContextBase* getContext() const { return mContext; } + virtual void reportGnssMeasurementsEvent(const GnssMeasurements& gnssMeasurements, + int msInWeek); + virtual bool reportWwanZppFix(LocGpsLocation &zppLoc); + virtual bool reportZppBestAvailableFix(LocGpsLocation &zppLoc, + GpsLocationExtended &location_extended, LocPosTechMask tech_mask); + virtual void reportGnssSvIdConfigEvent(const GnssSvIdConfig& config); + virtual void reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& config); + virtual void reportGnssConfigEvent(uint32_t sessionId, const GnssConfig& gnssConfig); + virtual bool requestOdcpiEvent(OdcpiRequestInfo& request); + virtual bool reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot); + virtual bool reportDeleteAidingDataEvent(GnssAidingData &aidingData); + virtual bool reportKlobucharIonoModelEvent(GnssKlobucharIonoModel& ionoModel); + virtual bool reportGnssAdditionalSystemInfoEvent( + GnssAdditionalSystemInfo& additionalSystemInfo); + virtual void reportNfwNotificationEvent(GnssNfwNotification& notification); + + virtual void geofenceBreachEvent(size_t count, uint32_t* hwIds, Location& location, + GeofenceBreachType breachType, uint64_t timestamp); + virtual void geofenceStatusEvent(GeofenceStatusAvailable available); + + virtual void reportPositionEvent(UlpLocation &location, + GpsLocationExtended &locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + + virtual void reportLocationsEvent(const Location* locations, size_t count, + BatchingMode batchingMode); + virtual void reportCompletedTripsEvent(uint32_t accumulated_distance); + virtual void reportBatchStatusChangeEvent(BatchingStatus batchStatus); + + /* ==== CLIENT ========================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks); + void removeClientCommand(LocationAPI* client, + removeClientCompleteCallback rmClientCb); + void requestCapabilitiesCommand(LocationAPI* client); + + virtual void reportLatencyInfoEvent(const GnssLatencyInfo& gnssLatencyInfo); + virtual bool reportQwesCapabilities( + const std::unordered_map &featureMap); +}; + +} // namespace loc_core + +#endif //LOC_API_ADAPTER_BASE_H diff --git a/gps/core/LocAdapterProxyBase.h b/gps/core/LocAdapterProxyBase.h new file mode 100644 index 0000000..727d424 --- /dev/null +++ b/gps/core/LocAdapterProxyBase.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2014, 2016-2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ADAPTER_PROXY_BASE_H +#define LOC_ADAPTER_PROXY_BASE_H + +#include +#include + +namespace loc_core { + +class LocAdapterProxyBase { +private: + LocAdapterBase *mLocAdapterBase; +protected: + inline LocAdapterProxyBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context, bool isMaster = false): + mLocAdapterBase(new LocAdapterBase(mask, context, isMaster, this)) { + } + inline virtual ~LocAdapterProxyBase() { + delete mLocAdapterBase; + } + inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event, + loc_registration_mask_status isEnabled) { + mLocAdapterBase->updateEvtMask(event,isEnabled); + } + + inline uint32_t generateSessionId() { + return mLocAdapterBase->generateSessionId(); + } +public: + inline ContextBase* getContext() const { + return mLocAdapterBase->getContext(); + } + + inline virtual void handleEngineUpEvent() {}; + inline virtual void handleEngineDownEvent() {}; + inline virtual void reportPositionEvent(UlpLocation &location, + GpsLocationExtended &locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) { + (void)location; + (void)locationExtended; + (void)status; + (void)loc_technology_mask; + } +}; + +} // namespace loc_core + +#endif //LOC_ADAPTER_PROXY_BASE_H diff --git a/gps/core/LocApiBase.cpp b/gps/core/LocApiBase.cpp new file mode 100644 index 0000000..6a0ff84 --- /dev/null +++ b/gps/core/LocApiBase.cpp @@ -0,0 +1,1069 @@ +/* Copyright (c) 2011-2014, 2016-2021 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 //Define to enable LOGV +#define LOG_TAG "LocSvc_LocApiBase" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +#define TO_ALL_LOCADAPTERS(call) TO_ALL_ADAPTERS(mLocAdapters, (call)) +#define TO_1ST_HANDLING_LOCADAPTERS(call) TO_1ST_HANDLING_ADAPTER(mLocAdapters, (call)) + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size) +{ + int i; + for (i = 0; i < data_size; i++) + { + char ch = data[i]; + if (i*2 + 3 <= string_size) + { + snprintf(&hexstring[i*2], 3, "%02X", ch); + } + else { + break; + } + } + return i; +} + +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size) +{ + const char addr_prefix = 0x91; + int i, idxOutput = 0; + + if (!data || !addr_string) { return 0; } + + if (data[0] != addr_prefix) + { + LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]); + addr_string[0] = '\0'; + return 0; // prefix not correct + } + + for (i = 1; i < data_size; i++) + { + unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4; + if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; } + if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; } + } + + addr_string[idxOutput] = '\0'; // Terminates the string + + return idxOutput; +} + +struct LocSsrMsg : public LocMsg { + LocApiBase* mLocApi; + inline LocSsrMsg(LocApiBase* locApi) : + LocMsg(), mLocApi(locApi) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->close(); + if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask())) { + // Notify adapters that engine up after SSR + mLocApi->handleEngineUpEvent(); + } + } + inline void locallog() const { + LOC_LOGV("LocSsrMsg"); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocOpenMsg : public LocMsg { + LocApiBase* mLocApi; + LocAdapterBase* mAdapter; + inline LocOpenMsg(LocApiBase* locApi, LocAdapterBase* adapter = nullptr) : + LocMsg(), mLocApi(locApi), mAdapter(adapter) + { + locallog(); + } + inline virtual void proc() const { + if (LOC_API_ADAPTER_ERR_SUCCESS == mLocApi->open(mLocApi->getEvtMask()) && + nullptr != mAdapter) { + mAdapter->handleEngineUpEvent(); + } + } + inline void locallog() const { + LOC_LOGv("LocOpen Mask: %" PRIx64 "\n", mLocApi->getEvtMask()); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocCloseMsg : public LocMsg { + LocApiBase* mLocApi; + inline LocCloseMsg(LocApiBase* locApi) : + LocMsg(), mLocApi(locApi) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->close(); + } + inline void locallog() const { + } + inline virtual void log() const { + locallog(); + } +}; + +MsgTask* LocApiBase::mMsgTask = nullptr; +volatile int32_t LocApiBase::mMsgTaskRefCount = 0; + +LocApiBase::LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask, + ContextBase* context) : + mContext(context), + mMask(0), mExcludedMask(excludedMask) +{ + memset(mLocAdapters, 0, sizeof(mLocAdapters)); + + android_atomic_inc(&mMsgTaskRefCount); + if (nullptr == mMsgTask) { + mMsgTask = new MsgTask("LocApiMsgTask"); + } +} + +LOC_API_ADAPTER_EVENT_MASK_T LocApiBase::getEvtMask() +{ + LOC_API_ADAPTER_EVENT_MASK_T mask = 0; + + TO_ALL_LOCADAPTERS(mask |= mLocAdapters[i]->getEvtMask()); + + return mask & ~mExcludedMask; +} + +bool LocApiBase::isMaster() +{ + bool isMaster = false; + + for (int i = 0; + !isMaster && i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + isMaster |= mLocAdapters[i]->isAdapterMaster(); + } + return isMaster; +} + +bool LocApiBase::isInSession() +{ + bool inSession = false; + + for (int i = 0; + !inSession && i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + inSession = mLocAdapters[i]->isInSession(); + } + + return inSession; +} + +bool LocApiBase::needReport(const UlpLocation& ulpLocation, + enum loc_sess_status status, + LocPosTechMask techMask) +{ + bool reported = false; + + if (LOC_SESS_SUCCESS == status) { + // this is a final fix + LocPosTechMask mask = + LOC_POS_TECH_MASK_SATELLITE | LOC_POS_TECH_MASK_SENSORS | LOC_POS_TECH_MASK_HYBRID; + // it is a Satellite fix or a sensor fix + reported = (mask & techMask); + } + else if (LOC_SESS_INTERMEDIATE == status && + LOC_SESS_INTERMEDIATE == ContextBase::mGps_conf.INTERMEDIATE_POS) { + // this is a intermediate fix and we accept intermediate + + // it is NOT the case that + // there is inaccuracy; and + // we care about inaccuracy; and + // the inaccuracy exceeds our tolerance + reported = !((ulpLocation.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ACCURACY) && + (ContextBase::mGps_conf.ACCURACY_THRES != 0) && + (ulpLocation.gpsLocation.accuracy > ContextBase::mGps_conf.ACCURACY_THRES)); + } + + return reported; +} + +void LocApiBase::addAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { + if (mLocAdapters[i] == NULL) { + mLocAdapters[i] = adapter; + sendMsg(new LocOpenMsg(this, adapter)); + break; + } + } +} + +void LocApiBase::removeAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; + i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + if (mLocAdapters[i] == adapter) { + mLocAdapters[i] = NULL; + + // shift the rest of the adapters up so that the pointers + // in the array do not have holes. This should be more + // performant, because the array maintenance is much much + // less frequent than event handlings, which need to linear + // search all the adapters + int j = i; + while (++i < MAX_ADAPTERS && mLocAdapters[i] != NULL); + + // i would be MAX_ADAPTERS or point to a NULL + i--; + // i now should point to a none NULL adapter within valid + // range although i could be equal to j, but it won't hurt. + // No need to check it, as it gains nothing. + mLocAdapters[j] = mLocAdapters[i]; + // this makes sure that we exit the for loop + mLocAdapters[i] = NULL; + + // if we have an empty list of adapters + if (0 == i) { + sendMsg(new LocCloseMsg(this)); + } else { + // else we need to remove the bit + sendMsg(new LocOpenMsg(this)); + } + } + } +} + +void LocApiBase::updateEvtMask() +{ + sendMsg(new LocOpenMsg(this)); +} + +void LocApiBase::updateNmeaMask(uint32_t mask) +{ + struct LocSetNmeaMsg : public LocMsg { + LocApiBase* mLocApi; + uint32_t mMask; + inline LocSetNmeaMsg(LocApiBase* locApi, uint32_t mask) : + LocMsg(), mLocApi(locApi), mMask(mask) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->setNMEATypesSync(mMask); + } + inline void locallog() const { + LOC_LOGv("LocSyncNmea NmeaMask: %" PRIx32 "\n", mMask); + } + inline virtual void log() const { + locallog(); + } + }; + + sendMsg(new LocSetNmeaMsg(this, mask)); +} + +void LocApiBase::handleEngineUpEvent() +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent()); +} + +void LocApiBase::handleEngineDownEvent() +{ // This will take care of renegotiating the loc handle + sendMsg(new LocSsrMsg(this)); + + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent()); +} + +void LocApiBase::reportPosition(UlpLocation& location, + GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask, + GnssDataNotification* pDataNotify, + int msInWeek) +{ + // print the location info before delivering + LOC_LOGD("flags: %d\n source: %d\n latitude: %f\n longitude: %f\n " + "altitude: %f\n speed: %f\n bearing: %f\n accuracy: %f\n " + "timestamp: %" PRId64 "\n" + "Session status: %d\n Technology mask: %u\n " + "SV used in fix (gps/glo/bds/gal/qzss) : \ + (0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 "/0x%" PRIx64 ")", + location.gpsLocation.flags, location.position_source, + location.gpsLocation.latitude, location.gpsLocation.longitude, + location.gpsLocation.altitude, location.gpsLocation.speed, + location.gpsLocation.bearing, location.gpsLocation.accuracy, + location.gpsLocation.timestamp, status, loc_technology_mask, + locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask, + locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask, + locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask, + locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask, + locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask, + locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask); + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportPositionEvent(location, locationExtended, + status, loc_technology_mask, + pDataNotify, msInWeek) + ); +} + +void LocApiBase::reportWwanZppFix(LocGpsLocation &zppLoc) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportWwanZppFix(zppLoc)); +} + +void LocApiBase::reportZppBestAvailableFix(LocGpsLocation &zppLoc, + GpsLocationExtended &location_extended, LocPosTechMask tech_mask) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportZppBestAvailableFix(zppLoc, + location_extended, tech_mask)); +} + +void LocApiBase::requestOdcpi(OdcpiRequestInfo& request) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestOdcpiEvent(request)); +} + +void LocApiBase::reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssEngEnergyConsumedEvent( + energyConsumedSinceFirstBoot)); +} + +void LocApiBase::reportDeleteAidingDataEvent(GnssAidingData& aidingData) { + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDeleteAidingDataEvent(aidingData)); +} + +void LocApiBase::reportKlobucharIonoModel(GnssKlobucharIonoModel & ionoModel) { + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportKlobucharIonoModelEvent(ionoModel)); +} + +void LocApiBase::reportGnssAdditionalSystemInfo(GnssAdditionalSystemInfo& additionalSystemInfo) { + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportGnssAdditionalSystemInfoEvent( + additionalSystemInfo)); +} + +void LocApiBase::sendNfwNotification(GnssNfwNotification& notification) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNfwNotificationEvent(notification)); + +} + +void LocApiBase::reportSv(GnssSvNotification& svNotify) +{ + const char* constellationString[] = { "Unknown", "GPS", "SBAS", "GLONASS", + "QZSS", "BEIDOU", "GALILEO", "NAVIC" }; + + // print the SV info before delivering + LOC_LOGV("num sv: %u\n" + " sv: constellation svid cN0 basebandCN0" + " elevation azimuth flags", + svNotify.count); + for (size_t i = 0; i < svNotify.count && i < GNSS_SV_MAX; i++) { + if (svNotify.gnssSvs[i].type > + sizeof(constellationString) / sizeof(constellationString[0]) - 1) { + svNotify.gnssSvs[i].type = GNSS_SV_TYPE_UNKNOWN; + } + // Display what we report to clients + LOC_LOGV(" %03zu: %*s %02d %f %f %f %f %f 0x%02X 0x%2X", + i, + 13, + constellationString[svNotify.gnssSvs[i].type], + svNotify.gnssSvs[i].svId, + svNotify.gnssSvs[i].cN0Dbhz, + svNotify.gnssSvs[i].basebandCarrierToNoiseDbHz, + svNotify.gnssSvs[i].elevation, + svNotify.gnssSvs[i].azimuth, + svNotify.gnssSvs[i].carrierFrequencyHz, + svNotify.gnssSvs[i].gnssSvOptionsMask, + svNotify.gnssSvs[i].gnssSignalTypeMask); + } + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportSvEvent(svNotify) + ); +} + +void LocApiBase::reportSvPolynomial(GnssSvPolynomial &svPolynomial) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportSvPolynomialEvent(svPolynomial) + ); +} + +void LocApiBase::reportSvEphemeris(GnssSvEphemerisReport & svEphemeris) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportSvEphemerisEvent(svEphemeris) + ); +} + +void LocApiBase::reportStatus(LocGpsStatusValue status) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status)); +} + +void LocApiBase::reportData(GnssDataNotification& dataNotify, int msInWeek) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportDataEvent(dataNotify, msInWeek)); +} + +void LocApiBase::reportNmea(const char* nmea, int length) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmeaEvent(nmea, length)); +} + +void LocApiBase::reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportXtraServer(url1, url2, url3, maxlength)); + +} + +void LocApiBase::reportLocationSystemInfo(const LocationSystemInfo& locationSystemInfo) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportLocationSystemInfoEvent(locationSystemInfo)); +} + +void LocApiBase::reportQwesCapabilities +( + const std::unordered_map &featureMap +) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportQwesCapabilities(featureMap)); +} +void LocApiBase::requestXtraData() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestXtraData()); +} + +void LocApiBase::requestTime() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestTime()); +} + +void LocApiBase::requestLocation() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation()); +} + +void LocApiBase::requestATL(int connHandle, LocAGpsType agps_type, + LocApnTypeMask apn_type_mask) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS( + mLocAdapters[i]->requestATL(connHandle, agps_type, apn_type_mask)); +} + +void LocApiBase::releaseATL(int connHandle) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->releaseATL(connHandle)); +} + +void LocApiBase::requestNiNotify(GnssNiNotification ¬ify, const void* data, + const LocInEmergency emergencyState) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS( + mLocAdapters[i]->requestNiNotifyEvent(notify, + data, + emergencyState)); +} + +void* LocApiBase :: getSibling() + DEFAULT_IMPL(NULL) + +LocApiProxyBase* LocApiBase :: getLocApiProxy() + DEFAULT_IMPL(NULL) + +void LocApiBase::reportGnssMeasurements(GnssMeasurements& gnssMeasurements, int msInWeek) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementsEvent(gnssMeasurements, msInWeek)); +} + +void LocApiBase::reportGnssSvIdConfig(const GnssSvIdConfig& config) +{ + // Print the config + LOC_LOGv("gloBlacklistSvMask: %" PRIu64 ", bdsBlacklistSvMask: %" PRIu64 ",\n" + "qzssBlacklistSvMask: %" PRIu64 ", galBlacklistSvMask: %" PRIu64 ",\n" + "navicBlacklistSvMask: %" PRIu64, + config.gloBlacklistSvMask, config.bdsBlacklistSvMask, + config.qzssBlacklistSvMask, config.galBlacklistSvMask, config.navicBlacklistSvMask); + + // Loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssSvIdConfigEvent(config)); +} + +void LocApiBase::reportGnssSvTypeConfig(const GnssSvTypeConfig& config) +{ + // Print the config + LOC_LOGv("blacklistedMask: %" PRIu64 ", enabledMask: %" PRIu64, + config.blacklistedSvTypesMask, config.enabledSvTypesMask); + + // Loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssSvTypeConfigEvent(config)); +} + +void LocApiBase::geofenceBreach(size_t count, uint32_t* hwIds, Location& location, + GeofenceBreachType breachType, uint64_t timestamp) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->geofenceBreachEvent(count, hwIds, location, breachType, + timestamp)); +} + +void LocApiBase::geofenceStatus(GeofenceStatusAvailable available) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->geofenceStatusEvent(available)); +} + +void LocApiBase::reportDBTPosition(UlpLocation &location, GpsLocationExtended &locationExtended, + enum loc_sess_status status, LocPosTechMask loc_technology_mask) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportPositionEvent(location, locationExtended, status, + loc_technology_mask)); +} + +void LocApiBase::reportLocations(Location* locations, size_t count, BatchingMode batchingMode) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportLocationsEvent(locations, count, batchingMode)); +} + +void LocApiBase::reportCompletedTrips(uint32_t accumulated_distance) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportCompletedTripsEvent(accumulated_distance)); +} + +void LocApiBase::handleBatchStatusEvent(BatchingStatus batchStatus) +{ + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportBatchStatusChangeEvent(batchStatus)); +} + +void LocApiBase::reportGnssConfig(uint32_t sessionId, const GnssConfig& gnssConfig) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssConfigEvent(sessionId, gnssConfig)); +} + +void LocApiBase::reportLatencyInfo(GnssLatencyInfo& gnssLatencyInfo) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportLatencyInfoEvent(gnssLatencyInfo)); +} + +enum loc_api_adapter_err LocApiBase:: + open(LOC_API_ADAPTER_EVENT_MASK_T /*mask*/) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + close() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +void LocApiBase::startFix(const LocPosMode& /*posMode*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::stopFix(LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + deleteAidingData(const GnssAidingData& /*data*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + injectPosition(double /*latitude*/, double /*longitude*/, float /*accuracy*/, + bool /*onDemandCpi*/) +DEFAULT_IMPL() + +void LocApiBase:: + injectPosition(const Location& /*location*/, bool /*onDemandCpi*/) +DEFAULT_IMPL() + +void LocApiBase:: + injectPosition(const GnssLocationInfoNotification & /*locationInfo*/, bool /*onDemandCpi*/) +DEFAULT_IMPL() + +void LocApiBase:: + setTime(LocGpsUtcTime /*time*/, int64_t /*timeReference*/, int /*uncertainty*/) +DEFAULT_IMPL() + +void LocApiBase:: + atlOpenStatus(int /*handle*/, int /*is_succ*/, char* /*apn*/, uint32_t /*apnLen*/, + AGpsBearerType /*bear*/, LocAGpsType /*agpsType*/, + LocApnTypeMask /*mask*/) +DEFAULT_IMPL() + +void LocApiBase:: + atlCloseStatus(int /*handle*/, int /*is_succ*/) +DEFAULT_IMPL() + +LocationError LocApiBase:: + setServerSync(const char* /*url*/, int /*len*/, LocServerType /*type*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +LocationError LocApiBase:: + setServerSync(unsigned int /*ip*/, int /*port*/, LocServerType /*type*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase:: + informNiResponse(GnssNiResponse /*userResponse*/, const void* /*passThroughData*/) +DEFAULT_IMPL() + +LocationError LocApiBase:: + setSUPLVersionSync(GnssConfigSuplVersion /*version*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setNMEATypesSync (uint32_t /*typesMask*/) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +LocationError LocApiBase:: + setLPPConfigSync(GnssConfigLppProfileMask /*profileMask*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + + +enum loc_api_adapter_err LocApiBase:: + setSensorPropertiesSync(bool /*gyroBiasVarianceRandomWalk_valid*/, + float /*gyroBiasVarianceRandomWalk*/, + bool /*accelBiasVarianceRandomWalk_valid*/, + float /*accelBiasVarianceRandomWalk*/, + bool /*angleBiasVarianceRandomWalk_valid*/, + float /*angleBiasVarianceRandomWalk*/, + bool /*rateBiasVarianceRandomWalk_valid*/, + float /*rateBiasVarianceRandomWalk*/, + bool /*velocityBiasVarianceRandomWalk_valid*/, + float /*velocityBiasVarianceRandomWalk*/) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorPerfControlConfigSync(int /*controlMode*/, + int /*accelSamplesPerBatch*/, + int /*accelBatchesPerSec*/, + int /*gyroSamplesPerBatch*/, + int /*gyroBatchesPerSec*/, + int /*accelSamplesPerBatchHigh*/, + int /*accelBatchesPerSecHigh*/, + int /*gyroSamplesPerBatchHigh*/, + int /*gyroBatchesPerSecHigh*/, + int /*algorithmConfig*/) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +LocationError LocApiBase:: + setAGLONASSProtocolSync(GnssConfigAGlonassPositionProtocolMask /*aGlonassProtocol*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +LocationError LocApiBase:: + setLPPeProtocolCpSync(GnssConfigLppeControlPlaneMask /*lppeCP*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +LocationError LocApiBase:: + setLPPeProtocolUpSync(GnssConfigLppeUserPlaneMask /*lppeUP*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +GnssConfigSuplVersion LocApiBase::convertSuplVersion(const uint32_t /*suplVersion*/) +DEFAULT_IMPL(GNSS_CONFIG_SUPL_VERSION_1_0_0) + +GnssConfigLppeControlPlaneMask LocApiBase::convertLppeCp(const uint32_t /*lppeControlPlaneMask*/) +DEFAULT_IMPL(0) + +GnssConfigLppeUserPlaneMask LocApiBase::convertLppeUp(const uint32_t /*lppeUserPlaneMask*/) +DEFAULT_IMPL(0) + +LocationError LocApiBase::setEmergencyExtensionWindowSync( + const uint32_t /*emergencyExtensionSeconds*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::setMeasurementCorrections( + const GnssMeasurementCorrections& /*gnssMeasurementCorrections*/) +DEFAULT_IMPL() + +void LocApiBase:: + getWwanZppFix() +DEFAULT_IMPL() + +void LocApiBase:: + getBestAvailableZppFix() +DEFAULT_IMPL() + +LocationError LocApiBase:: + setGpsLockSync(GnssConfigGpsLock /*lock*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase:: + requestForAidingData(GnssAidingDataSvMask /*svDataMask*/) +DEFAULT_IMPL() + +LocationError LocApiBase:: + setXtraVersionCheckSync(uint32_t /*check*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +LocationError LocApiBase::setBlacklistSvSync(const GnssSvIdConfig& /*config*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::setBlacklistSv(const GnssSvIdConfig& /*config*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::getBlacklistSv() +DEFAULT_IMPL() + +void LocApiBase::setConstellationControl(const GnssSvTypeConfig& /*config*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::getConstellationControl() +DEFAULT_IMPL() + +void LocApiBase::resetConstellationControl(LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + setConstrainedTuncMode(bool /*enabled*/, + float /*tuncConstraint*/, + uint32_t /*energyBudget*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + setPositionAssistedClockEstimatorMode(bool /*enabled*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::getGnssEnergyConsumed() +DEFAULT_IMPL() + + +void LocApiBase::addGeofence(uint32_t /*clientId*/, const GeofenceOption& /*options*/, + const GeofenceInfo& /*info*/, + LocApiResponseData* /*adapterResponseData*/) +DEFAULT_IMPL() + +void LocApiBase::removeGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::pauseGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::resumeGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::modifyGeofence(uint32_t /*hwId*/, uint32_t /*clientId*/, + const GeofenceOption& /*options*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::startTimeBasedTracking(const TrackingOptions& /*options*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::stopTimeBasedTracking(LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::startDistanceBasedTracking(uint32_t /*sessionId*/, + const LocationOptions& /*options*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::stopDistanceBasedTracking(uint32_t /*sessionId*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::startBatching(uint32_t /*sessionId*/, const LocationOptions& /*options*/, + uint32_t /*accuracy*/, uint32_t /*timeout*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::stopBatching(uint32_t /*sessionId*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase::startOutdoorTripBatchingSync(uint32_t /*tripDistance*/, + uint32_t /*tripTbf*/, uint32_t /*timeout*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::startOutdoorTripBatching(uint32_t /*tripDistance*/, uint32_t /*tripTbf*/, + uint32_t /*timeout*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::reStartOutdoorTripBatching(uint32_t /*ongoingTripDistance*/, + uint32_t /*ongoingTripInterval*/, uint32_t /*batchingTimeout,*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase::stopOutdoorTripBatchingSync(bool /*deallocBatchBuffer*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::stopOutdoorTripBatching(bool /*deallocBatchBuffer*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase::getBatchedLocationsSync(size_t /*count*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::getBatchedLocations(size_t /*count*/, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase::getBatchedTripLocationsSync(size_t /*count*/, + uint32_t /*accumulatedDistance*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::getBatchedTripLocations(size_t /*count*/, uint32_t /*accumulatedDistance*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase::queryAccumulatedTripDistanceSync(uint32_t& /*accumulated_trip_distance*/, + uint32_t& /*numOfBatchedPositions*/) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase::queryAccumulatedTripDistance( + LocApiResponseData* /*adapterResponseData*/) +DEFAULT_IMPL() + +void LocApiBase::setBatchSize(size_t /*size*/) +DEFAULT_IMPL() + +void LocApiBase::setTripBatchSize(size_t /*size*/) +DEFAULT_IMPL() + +void LocApiBase::addToCallQueue(LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase::updateSystemPowerState(PowerStateType /*powerState*/) +DEFAULT_IMPL() + +void LocApiBase:: + configRobustLocation(bool /*enabled*/, + bool /*enableForE911*/, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + getRobustLocationConfig(uint32_t sessionId, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + configMinGpsWeek(uint16_t minGpsWeek, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + getMinGpsWeek(uint32_t sessionId, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +LocationError LocApiBase:: + setParameterSync(const GnssConfig& gnssConfig) +DEFAULT_IMPL(LOCATION_ERROR_SUCCESS) + +void LocApiBase:: + getParameter(uint32_t sessionId, GnssConfigFlagsMask flags, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + configConstellationMultiBand(const GnssSvTypeConfig& secondaryBandConfig, + LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +void LocApiBase:: + getConstellationMultiBandConfig(uint32_t sessionId, LocApiResponse* /*adapterResponse*/) +DEFAULT_IMPL() + +int64_t ElapsedRealtimeEstimator::getElapsedRealtimeEstimateNanos(int64_t curDataTimeNanos, + bool isCurDataTimeTrustable, int64_t tbf) { + //The algorithm works follow below steps: + //When isCurDataTimeTrustable is meet (means Modem timestamp is already stable), + //1, Wait for mFixTimeStablizationThreshold fixes; While waiting for modem time + // stable, we set the traveltime to a default value; + //2, When the mFixTimeStablizationThreshold fix comes, we think now the mode time + // is already stable, calculate the initial AP-Modem clock diff(mCurrentClockDiff) + // using formula: + // mCurrentClockDiff = currentTimeNanos - locationTimeNanos - currentTravelTimeNanos + //3, since then, when the nth fix comes, + // 3.1 First update mCurrentClockDiff using below formula: + // mCurrentClockDiff = mCurrentClockDiff + (currentTimeNanos - sinceBootTimeNanos) + // - (mPrevUtcTimeNanos - mPrevBootTimeNanos) + // 3.2 Calculate currentTravelTimeNanos: + // currentTravelTimeNanos = currentTimeNanos - locationTimeNanos - mCurrentClockDiff + //4, It is possible that locationTimeNanos will jump, + // reset mFixTimeStablizationThreshold to default value, jump to step 2 to continue. + + int64_t currentTravelTimeNanos = mInitialTravelTime; + struct timespec currentTime; + int64_t sinceBootTimeNanos; + if (getCurrentTime(currentTime, sinceBootTimeNanos)) { + if (isCurDataTimeTrustable) { + if (tbf > 0 && tbf != curDataTimeNanos - mPrevDataTimeNanos) { + mFixTimeStablizationThreshold = 5; + } + int64_t currentTimeNanos = (int64_t)currentTime.tv_sec*1000000000 + currentTime.tv_nsec; + LOC_LOGd("sinceBootTimeNanos:%" PRIi64 " currentTimeNanos:%" PRIi64 "" + " locationTimeNanos:%" PRIi64 "", + sinceBootTimeNanos, currentTimeNanos, curDataTimeNanos); + if (mFixTimeStablizationThreshold == 0) { + currentTravelTimeNanos = mInitialTravelTime; + mCurrentClockDiff = currentTimeNanos - curDataTimeNanos - currentTravelTimeNanos; + } else if (mFixTimeStablizationThreshold < 0) { + mCurrentClockDiff = mCurrentClockDiff + (currentTimeNanos - sinceBootTimeNanos) + - (mPrevUtcTimeNanos - mPrevBootTimeNanos); + currentTravelTimeNanos = currentTimeNanos - curDataTimeNanos - mCurrentClockDiff; + } + + mPrevUtcTimeNanos = currentTimeNanos; + mPrevBootTimeNanos = sinceBootTimeNanos; + mPrevDataTimeNanos = curDataTimeNanos; + mFixTimeStablizationThreshold--; + } + } else { + return -1; + } + LOC_LOGd("Estimated travel time: %" PRIi64 "", currentTravelTimeNanos); + return (sinceBootTimeNanos - currentTravelTimeNanos); +} + +void ElapsedRealtimeEstimator::reset() { + mCurrentClockDiff = 0; + mPrevDataTimeNanos = 0; + mPrevUtcTimeNanos = 0; + mPrevBootTimeNanos = 0; + mFixTimeStablizationThreshold = 5; +} + +int64_t ElapsedRealtimeEstimator::getElapsedRealtimeQtimer(int64_t qtimerTicksAtOrigin) { + struct timespec currentTime; + int64_t sinceBootTimeNanos; + int64_t elapsedRealTimeNanos; + + if (getCurrentTime(currentTime, sinceBootTimeNanos)) { + uint64_t qtimerDiff = 0; + uint64_t qTimerTickCount = getQTimerTickCount(); + if (qTimerTickCount >= qtimerTicksAtOrigin) { + qtimerDiff = qTimerTickCount - qtimerTicksAtOrigin; + } + LOC_LOGd("sinceBootTimeNanos:%" PRIi64 " qtimerTicksAtOrigin=%" PRIi64 "" + " qTimerTickCount=%" PRIi64 " qtimerDiff=%" PRIi64 "", + sinceBootTimeNanos, qtimerTicksAtOrigin, qTimerTickCount, qtimerDiff); + uint64_t qTimerDiffNanos = qTimerTicksToNanos(double(qtimerDiff)); + + /* If the time difference between Qtimer on modem side and Qtimer on AP side + is greater than one second we assume this is a dual-SoC device such as + Kona and will try to get Qtimer on modem side and on AP side and + will adjust our difference accordingly */ + if (qTimerDiffNanos > 1000000000) { + uint64_t qtimerDelta = getQTimerDeltaNanos(); + if (qTimerDiffNanos >= qtimerDelta) { + qTimerDiffNanos -= qtimerDelta; + } + } + + LOC_LOGd("Qtimer travel time: %" PRIi64 "", qTimerDiffNanos); + if (sinceBootTimeNanos >= qTimerDiffNanos) { + elapsedRealTimeNanos = sinceBootTimeNanos - qTimerDiffNanos; + } else { + elapsedRealTimeNanos = -1; + } + } else { + elapsedRealTimeNanos = -1; + } + return elapsedRealTimeNanos; +} + +bool ElapsedRealtimeEstimator::getCurrentTime( + struct timespec& currentTime, int64_t& sinceBootTimeNanos) +{ + struct timespec sinceBootTime; + struct timespec sinceBootTimeTest; + bool clockGetTimeSuccess = false; + const uint32_t MAX_TIME_DELTA_VALUE_NANOS = 10000; + const uint32_t MAX_GET_TIME_COUNT = 20; + /* Attempt to get CLOCK_REALTIME and CLOCK_BOOTIME in succession without an interruption + or context switch (for up to MAX_GET_TIME_COUNT times) to avoid errors in the calculation */ + for (uint32_t i = 0; i < MAX_GET_TIME_COUNT; i++) { + if (clock_gettime(CLOCK_BOOTTIME, &sinceBootTime) != 0) { + break; + }; + if (clock_gettime(CLOCK_REALTIME, ¤tTime) != 0) { + break; + } + if (clock_gettime(CLOCK_BOOTTIME, &sinceBootTimeTest) != 0) { + break; + }; + sinceBootTimeNanos = (int64_t)sinceBootTime.tv_sec * 1000000000 + sinceBootTime.tv_nsec; + int64_t sinceBootTimeTestNanos = + (int64_t)sinceBootTimeTest.tv_sec * 1000000000 + sinceBootTimeTest.tv_nsec; + int64_t sinceBootTimeDeltaNanos = sinceBootTimeTestNanos - sinceBootTimeNanos; + + /* sinceBootTime and sinceBootTimeTest should have a close value if there was no + interruption or context switch between clock_gettime for CLOCK_BOOTIME and + clock_gettime for CLOCK_REALTIME */ + if (sinceBootTimeDeltaNanos < MAX_TIME_DELTA_VALUE_NANOS) { + clockGetTimeSuccess = true; + break; + } else { + LOC_LOGd("Delta:%" PRIi64 "ns time too large, retry number #%u...", + sinceBootTimeDeltaNanos, i + 1); + } + } + return clockGetTimeSuccess; +} +} // namespace loc_core diff --git a/gps/core/LocApiBase.h b/gps/core/LocApiBase.h new file mode 100644 index 0000000..121f795 --- /dev/null +++ b/gps/core/LocApiBase.h @@ -0,0 +1,375 @@ +/* Copyright (c) 2011-2014, 2016-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_API_BASE_H +#define LOC_API_BASE_H + +#include +#include +#include +#include +#include +#include +#include +#ifdef NO_UNORDERED_SET_OR_MAP + #include +#else + #include +#endif +#include +#include + +using namespace loc_util; + +namespace loc_core { + +class ContextBase; +struct LocApiResponse; +template struct LocApiResponseData; + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size); +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size); + +#define MAX_ADAPTERS 10 +#define MAX_FEATURE_LENGTH 100 + +#define TO_ALL_ADAPTERS(adapters, call) \ + for (int i = 0; i < MAX_ADAPTERS && NULL != (adapters)[i]; i++) { \ + call; \ + } + +#define TO_1ST_HANDLING_ADAPTER(adapters, call) \ + for (int i = 0; i mProcImpl; + inline virtual void proc() const { + mProcImpl(); + } + public: + inline LocApiMsg(std::function procImpl ) : + mProcImpl(procImpl) {} +}; + +class LocApiProxyBase { +public: + inline LocApiProxyBase() {} + inline virtual ~LocApiProxyBase() {} + inline virtual void* getSibling2() { return NULL; } + inline virtual double getGloRfLoss(uint32_t left, + uint32_t center, uint32_t right, uint8_t gloFrequency) { return 0.0; } +}; + +class LocApiBase { + friend struct LocSsrMsg; + //LocOpenMsg calls open() which makes it necessary to declare + //it as a friend + friend struct LocOpenMsg; + friend struct LocCloseMsg; + friend struct LocKillMsg; + friend class ContextBase; + static MsgTask* mMsgTask; + static volatile int32_t mMsgTaskRefCount; + LocAdapterBase* mLocAdapters[MAX_ADAPTERS]; + +protected: + ContextBase *mContext; + virtual enum loc_api_adapter_err + open(LOC_API_ADAPTER_EVENT_MASK_T mask); + virtual enum loc_api_adapter_err + close(); + LOC_API_ADAPTER_EVENT_MASK_T getEvtMask(); + LOC_API_ADAPTER_EVENT_MASK_T mMask; + uint32_t mNmeaMask; + LocApiBase(LOC_API_ADAPTER_EVENT_MASK_T excludedMask, + ContextBase* context = NULL); + inline virtual ~LocApiBase() { + android_atomic_dec(&mMsgTaskRefCount); + if (nullptr != mMsgTask && 0 == mMsgTaskRefCount) { + delete mMsgTask; + mMsgTask = nullptr; + } + } + bool isInSession(); + const LOC_API_ADAPTER_EVENT_MASK_T mExcludedMask; + bool isMaster(); + +public: + inline void sendMsg(const LocMsg* msg) const { + if (nullptr != mMsgTask) { + mMsgTask->sendMsg(msg); + } + } + inline void destroy() { + close(); + struct LocKillMsg : public LocMsg { + LocApiBase* mLocApi; + inline LocKillMsg(LocApiBase* locApi) : LocMsg(), mLocApi(locApi) {} + inline virtual void proc() const { + delete mLocApi; + } + }; + sendMsg(new LocKillMsg(this)); + } + + static bool needReport(const UlpLocation& ulpLocation, + enum loc_sess_status status, + LocPosTechMask techMask); + + void addAdapter(LocAdapterBase* adapter); + void removeAdapter(LocAdapterBase* adapter); + + // upward calls + void handleEngineUpEvent(); + void handleEngineDownEvent(); + void reportPosition(UlpLocation& location, + GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask = + LOC_POS_TECH_MASK_DEFAULT, + GnssDataNotification* pDataNotify = nullptr, + int msInWeek = -1); + void reportSv(GnssSvNotification& svNotify); + void reportSvPolynomial(GnssSvPolynomial &svPolynomial); + void reportSvEphemeris(GnssSvEphemerisReport &svEphemeris); + void reportStatus(LocGpsStatusValue status); + void reportNmea(const char* nmea, int length); + void reportData(GnssDataNotification& dataNotify, int msInWeek); + void reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + void reportLocationSystemInfo(const LocationSystemInfo& locationSystemInfo); + void requestXtraData(); + void requestTime(); + void requestLocation(); + void requestATL(int connHandle, LocAGpsType agps_type, LocApnTypeMask apn_type_mask); + void releaseATL(int connHandle); + void requestNiNotify(GnssNiNotification ¬ify, const void* data, + const LocInEmergency emergencyState); + void reportGnssMeasurements(GnssMeasurements& gnssMeasurements, int msInWeek); + void reportWwanZppFix(LocGpsLocation &zppLoc); + void reportZppBestAvailableFix(LocGpsLocation &zppLoc, GpsLocationExtended &location_extended, + LocPosTechMask tech_mask); + void reportGnssSvIdConfig(const GnssSvIdConfig& config); + void reportGnssSvTypeConfig(const GnssSvTypeConfig& config); + void requestOdcpi(OdcpiRequestInfo& request); + void reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot); + void reportDeleteAidingDataEvent(GnssAidingData& aidingData); + void reportKlobucharIonoModel(GnssKlobucharIonoModel& ionoModel); + void reportGnssAdditionalSystemInfo(GnssAdditionalSystemInfo& additionalSystemInfo); + void sendNfwNotification(GnssNfwNotification& notification); + void reportGnssConfig(uint32_t sessionId, const GnssConfig& gnssConfig); + void reportLatencyInfo(GnssLatencyInfo& gnssLatencyInfo); + void reportQwesCapabilities + ( + const std::unordered_map &featureMap + ); + + void geofenceBreach(size_t count, uint32_t* hwIds, Location& location, + GeofenceBreachType breachType, uint64_t timestamp); + void geofenceStatus(GeofenceStatusAvailable available); + void reportDBTPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + void reportLocations(Location* locations, size_t count, BatchingMode batchingMode); + void reportCompletedTrips(uint32_t accumulated_distance); + void handleBatchStatusEvent(BatchingStatus batchStatus); + + // downward calls + virtual void* getSibling(); + virtual LocApiProxyBase* getLocApiProxy(); + virtual void startFix(const LocPosMode& fixCriteria, LocApiResponse* adapterResponse); + virtual void stopFix(LocApiResponse* adapterResponse); + virtual void deleteAidingData(const GnssAidingData& data, LocApiResponse* adapterResponse); + virtual void injectPosition(double latitude, double longitude, float accuracy, + bool onDemandCpi); + virtual void injectPosition(const GnssLocationInfoNotification &locationInfo, + bool onDemandCpi=false); + virtual void injectPosition(const Location& location, bool onDemandCpi); + virtual void setTime(LocGpsUtcTime time, int64_t timeReference, int uncertainty); + virtual void atlOpenStatus(int handle, int is_succ, char* apn, uint32_t apnLen, + AGpsBearerType bear, LocAGpsType agpsType, LocApnTypeMask mask); + virtual void atlCloseStatus(int handle, int is_succ); + virtual LocationError setServerSync(const char* url, int len, LocServerType type); + virtual LocationError setServerSync(unsigned int ip, int port, LocServerType type); + virtual void informNiResponse(GnssNiResponse userResponse, const void* passThroughData); + virtual LocationError setSUPLVersionSync(GnssConfigSuplVersion version); + virtual enum loc_api_adapter_err setNMEATypesSync(uint32_t typesMask); + virtual LocationError setLPPConfigSync(GnssConfigLppProfileMask profileMask); + virtual enum loc_api_adapter_err setSensorPropertiesSync( + bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk); + virtual enum loc_api_adapter_err setSensorPerfControlConfigSync(int controlMode, + int accelSamplesPerBatch, int accelBatchesPerSec, int gyroSamplesPerBatch, + int gyroBatchesPerSec, int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig); + virtual LocationError + setAGLONASSProtocolSync(GnssConfigAGlonassPositionProtocolMask aGlonassProtocol); + virtual LocationError setLPPeProtocolCpSync(GnssConfigLppeControlPlaneMask lppeCP); + virtual LocationError setLPPeProtocolUpSync(GnssConfigLppeUserPlaneMask lppeUP); + virtual GnssConfigSuplVersion convertSuplVersion(const uint32_t suplVersion); + virtual GnssConfigLppeControlPlaneMask convertLppeCp(const uint32_t lppeControlPlaneMask); + virtual GnssConfigLppeUserPlaneMask convertLppeUp(const uint32_t lppeUserPlaneMask); + virtual LocationError setEmergencyExtensionWindowSync(const uint32_t emergencyExtensionSeconds); + virtual void setMeasurementCorrections( + const GnssMeasurementCorrections& gnssMeasurementCorrections); + + virtual void getWwanZppFix(); + virtual void getBestAvailableZppFix(); + virtual LocationError setGpsLockSync(GnssConfigGpsLock lock); + virtual void requestForAidingData(GnssAidingDataSvMask svDataMask); + virtual LocationError setXtraVersionCheckSync(uint32_t check); + /* Requests for SV/Constellation Control */ + virtual LocationError setBlacklistSvSync(const GnssSvIdConfig& config); + virtual void setBlacklistSv(const GnssSvIdConfig& config, + LocApiResponse *adapterResponse=nullptr); + virtual void getBlacklistSv(); + virtual void setConstellationControl(const GnssSvTypeConfig& config, + LocApiResponse *adapterResponse=nullptr); + virtual void getConstellationControl(); + virtual void resetConstellationControl(LocApiResponse *adapterResponse=nullptr); + + virtual void setConstrainedTuncMode(bool enabled, + float tuncConstraint, + uint32_t energyBudget, + LocApiResponse* adapterResponse=nullptr); + virtual void setPositionAssistedClockEstimatorMode(bool enabled, + LocApiResponse* adapterResponse=nullptr); + virtual void getGnssEnergyConsumed(); + + virtual void addGeofence(uint32_t clientId, const GeofenceOption& options, + const GeofenceInfo& info, LocApiResponseData* adapterResponseData); + virtual void removeGeofence(uint32_t hwId, uint32_t clientId, LocApiResponse* adapterResponse); + virtual void pauseGeofence(uint32_t hwId, uint32_t clientId, LocApiResponse* adapterResponse); + virtual void resumeGeofence(uint32_t hwId, uint32_t clientId, LocApiResponse* adapterResponse); + virtual void modifyGeofence(uint32_t hwId, uint32_t clientId, const GeofenceOption& options, + LocApiResponse* adapterResponse); + + virtual void startTimeBasedTracking(const TrackingOptions& options, + LocApiResponse* adapterResponse); + virtual void stopTimeBasedTracking(LocApiResponse* adapterResponse); + virtual void startDistanceBasedTracking(uint32_t sessionId, const LocationOptions& options, + LocApiResponse* adapterResponse); + virtual void stopDistanceBasedTracking(uint32_t sessionId, + LocApiResponse* adapterResponse = nullptr); + virtual void startBatching(uint32_t sessionId, const LocationOptions& options, + uint32_t accuracy, uint32_t timeout, LocApiResponse* adapterResponse); + virtual void stopBatching(uint32_t sessionId, LocApiResponse* adapterResponse); + virtual LocationError startOutdoorTripBatchingSync(uint32_t tripDistance, + uint32_t tripTbf, uint32_t timeout); + virtual void startOutdoorTripBatching(uint32_t tripDistance, + uint32_t tripTbf, uint32_t timeout, LocApiResponse* adapterResponse); + virtual void reStartOutdoorTripBatching(uint32_t ongoingTripDistance, + uint32_t ongoingTripInterval, uint32_t batchingTimeout, + LocApiResponse* adapterResponse); + virtual LocationError stopOutdoorTripBatchingSync(bool deallocBatchBuffer = true); + virtual void stopOutdoorTripBatching(bool deallocBatchBuffer = true, + LocApiResponse* adapterResponse = nullptr); + virtual LocationError getBatchedLocationsSync(size_t count); + virtual void getBatchedLocations(size_t count, LocApiResponse* adapterResponse); + virtual LocationError getBatchedTripLocationsSync(size_t count, uint32_t accumulatedDistance); + virtual void getBatchedTripLocations(size_t count, uint32_t accumulatedDistance, + LocApiResponse* adapterResponse); + virtual LocationError queryAccumulatedTripDistanceSync(uint32_t &accumulated_trip_distance, + uint32_t &numOfBatchedPositions); + virtual void queryAccumulatedTripDistance( + LocApiResponseData* adapterResponseData); + virtual void setBatchSize(size_t size); + virtual void setTripBatchSize(size_t size); + virtual void addToCallQueue(LocApiResponse* adapterResponse); + + void updateEvtMask(); + void updateNmeaMask(uint32_t mask); + + virtual void updateSystemPowerState(PowerStateType systemPowerState); + + virtual void configRobustLocation(bool enable, bool enableForE911, + LocApiResponse* adapterResponse=nullptr); + virtual void getRobustLocationConfig(uint32_t sessionId, LocApiResponse* adapterResponse); + virtual void configMinGpsWeek(uint16_t minGpsWeek, + LocApiResponse* adapterResponse=nullptr); + virtual void getMinGpsWeek(uint32_t sessionId, LocApiResponse* adapterResponse); + + virtual LocationError setParameterSync(const GnssConfig & gnssConfig); + virtual void getParameter(uint32_t sessionId, GnssConfigFlagsMask flags, + LocApiResponse* adapterResponse=nullptr); + + virtual void configConstellationMultiBand(const GnssSvTypeConfig& secondaryBandConfig, + LocApiResponse* adapterResponse=nullptr); + virtual void getConstellationMultiBandConfig(uint32_t sessionId, + LocApiResponse* adapterResponse=nullptr); +}; + +class ElapsedRealtimeEstimator { +private: + int64_t mCurrentClockDiff; + int64_t mPrevUtcTimeNanos; + int64_t mPrevBootTimeNanos; + int64_t mFixTimeStablizationThreshold; + int64_t mInitialTravelTime; + int64_t mPrevDataTimeNanos; +public: + + ElapsedRealtimeEstimator(int64_t travelTimeNanosEstimate): + mInitialTravelTime(travelTimeNanosEstimate) {reset();} + int64_t getElapsedRealtimeEstimateNanos(int64_t curDataTimeNanos, + bool isCurDataTimeTrustable, int64_t tbf); + inline int64_t getElapsedRealtimeUncNanos() { return 5000000;} + void reset(); + + static int64_t getElapsedRealtimeQtimer(int64_t qtimerTicksAtOrigin); + static bool getCurrentTime(struct timespec& currentTime, int64_t& sinceBootTimeNanos); +}; + +typedef LocApiBase* (getLocApi_t)(LOC_API_ADAPTER_EVENT_MASK_T exMask, + ContextBase *context); + +} // namespace loc_core + +#endif //LOC_API_BASE_H diff --git a/gps/core/LocContext.cpp b/gps/core/LocContext.cpp new file mode 100644 index 0000000..272c08c --- /dev/null +++ b/gps/core/LocContext.cpp @@ -0,0 +1,87 @@ +/* Copyright (c) 2011-2014, 2016-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_Ctx" + +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +const MsgTask* LocContext::mMsgTask = NULL; +ContextBase* LocContext::mContext = NULL; +// the name must be shorter than 15 chars +const char* LocContext::mLocationHalName = "Loc_hal_worker"; +#ifndef USE_GLIB +const char* LocContext::mLBSLibName = "liblbs_core.so"; +#else +const char* LocContext::mLBSLibName = "liblbs_core.so.1"; +#endif + +pthread_mutex_t LocContext::mGetLocContextMutex = PTHREAD_MUTEX_INITIALIZER; + +const MsgTask* LocContext::getMsgTask(const char* name) +{ + if (NULL == mMsgTask) { + mMsgTask = new MsgTask(name); + } + return mMsgTask; +} + +ContextBase* LocContext::getLocContext(const char* name) +{ + pthread_mutex_lock(&LocContext::mGetLocContextMutex); + LOC_LOGD("%s:%d]: querying ContextBase with tCreator", __func__, __LINE__); + if (NULL == mContext) { + LOC_LOGD("%s:%d]: creating msgTask with tCreator", __func__, __LINE__); + const MsgTask* msgTask = getMsgTask(name); + mContext = new LocContext(msgTask); + } + pthread_mutex_unlock(&LocContext::mGetLocContextMutex); + + return mContext; +} + +void LocContext :: injectFeatureConfig(ContextBase *curContext) +{ + LOC_LOGD("%s:%d]: Calling LBSProxy (%p) to inject feature config", + __func__, __LINE__, ((LocContext *)curContext)->mLBSProxy); + ((LocContext *)curContext)->mLBSProxy->injectFeatureConfig(curContext); +} + +LocContext::LocContext(const MsgTask* msgTask) : + ContextBase(msgTask, 0, mLBSLibName) +{ +} + +} diff --git a/gps/core/LocContext.h b/gps/core/LocContext.h new file mode 100644 index 0000000..628ed93 --- /dev/null +++ b/gps/core/LocContext.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2011-2014, 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_CONTEXT__ +#define __LOC_CONTEXT__ + +#include +#include +#include +#include + +namespace loc_core { + +class LocContext : public ContextBase { + static const MsgTask* mMsgTask; + static ContextBase* mContext; + static const MsgTask* getMsgTask(const char* name); + static pthread_mutex_t mGetLocContextMutex; + +protected: + LocContext(const MsgTask* msgTask); + inline virtual ~LocContext() {} + +public: + static const char* mLBSLibName; + static const char* mLocationHalName; + + static ContextBase* getLocContext(const char* name); + + static void injectFeatureConfig(ContextBase *context); +}; + +} + +#endif //__LOC_CONTEXT__ diff --git a/gps/core/Makefile.am b/gps/core/Makefile.am new file mode 100644 index 0000000..291dbb5 --- /dev/null +++ b/gps/core/Makefile.am @@ -0,0 +1,74 @@ +ACLOCAL_AMFLAGS = -I m4 + +AM_CFLAGS = -I./ \ + $(LOCPLA_CFLAGS) \ + $(GPSUTILS_CFLAGS) \ + -I./data-items/ \ + -I./data-items/common \ + -I./observer \ + -I$(WORKSPACE)/gps-noship/flp \ + -D__func__=__PRETTY_FUNCTION__ \ + -fno-short-enums \ + -std=c++11 + +libloc_core_la_h_sources = \ + LocApiBase.h \ + LocAdapterBase.h \ + ContextBase.h \ + LocContext.h \ + LBSProxyBase.h \ + loc_core_log.h \ + LocAdapterProxyBase.h \ + EngineHubProxyBase.h \ + data-items/DataItemId.h \ + data-items/IDataItemCore.h \ + data-items/DataItemConcreteTypesBase.h \ + observer/IDataItemObserver.h \ + observer/IDataItemSubscription.h \ + observer/IFrameworkActionReq.h \ + observer/IOsObserver.h \ + SystemStatusOsObserver.h \ + SystemStatus.h + +libloc_core_la_c_sources = \ + LocApiBase.cpp \ + LocAdapterBase.cpp \ + ContextBase.cpp \ + LocContext.cpp \ + loc_core_log.cpp \ + data-items/DataItemsFactoryProxy.cpp \ + SystemStatusOsObserver.cpp \ + SystemStatus.cpp + +if USE_EXTERNAL_AP +AM_CFLAGS += -DFEATURE_EXTERNAL_AP +endif + +library_includedir = $(pkgincludedir) + +library_include_HEADERS = $(libloc_core_la_h_sources) + +libloc_core_la_SOURCES = $(libloc_core_la_c_sources) + +if USE_GLIB +libloc_core_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +libloc_core_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 +libloc_core_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +libloc_core_la_CFLAGS = $(AM_CFLAGS) +libloc_core_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0 +libloc_core_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +if USE_FEATURE_AUTOMOTIVE +AM_CFLAGS += -DFEATURE_AUTOMOTIVE +endif + +libloc_core_la_LIBADD = -ldl $(GPSUTILS_LIBS) + +#Create and Install libraries +lib_LTLIBRARIES = libloc_core.la + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = loc-core.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/core/SystemStatus.cpp b/gps/core/SystemStatus.cpp new file mode 100644 index 0000000..d792577 --- /dev/null +++ b/gps/core/SystemStatus.cpp @@ -0,0 +1,1760 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "LocSvc_SystemStatus" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core +{ + +/****************************************************************************** + SystemStatusNmeaBase - base class for all NMEA parsers +******************************************************************************/ +class SystemStatusNmeaBase +{ +protected: + std::vector mField; + + SystemStatusNmeaBase(const char *str_in, uint32_t len_in) + { + // check size and talker + if (!loc_nmea_is_debug(str_in, len_in)) { + return; + } + + std::string parser(str_in); + std::string::size_type index = 0; + + // verify checksum field + index = parser.find("*"); + if (index == std::string::npos) { + return; + } + parser[index] = ','; + + // tokenize parser + while (1) { + std::string str; + index = parser.find(","); + if (index == std::string::npos) { + break; + } + str = parser.substr(0, index); + parser = parser.substr(index + 1); + mField.push_back(str); + } + } + + virtual ~SystemStatusNmeaBase() { } + +public: + static const uint32_t NMEA_MINSIZE = DEBUG_NMEA_MINSIZE; + static const uint32_t NMEA_MAXSIZE = DEBUG_NMEA_MAXSIZE; +}; + +/****************************************************************************** + SystemStatusPQWM1 +******************************************************************************/ +class SystemStatusPQWM1 +{ +public: + uint16_t mGpsWeek; // x1 + uint32_t mGpsTowMs; // x2 + uint8_t mTimeValid; // x3 + uint8_t mTimeSource; // x4 + int32_t mTimeUnc; // x5 + int32_t mClockFreqBias; // x6 + int32_t mClockFreqBiasUnc; // x7 + uint8_t mXoState; // x8 + int32_t mPgaGain; // x9 + uint32_t mGpsBpAmpI; // xA + uint32_t mGpsBpAmpQ; // xB + uint32_t mAdcI; // xC + uint32_t mAdcQ; // xD + uint32_t mJammerGps; // xE + uint32_t mJammerGlo; // xF + uint32_t mJammerBds; // x10 + uint32_t mJammerGal; // x11 + uint32_t mRecErrorRecovery; // x12 + double mAgcGps; // x13 + double mAgcGlo; // x14 + double mAgcBds; // x15 + double mAgcGal; // x16 + int32_t mLeapSeconds;// x17 + int32_t mLeapSecUnc; // x18 + uint32_t mGloBpAmpI; // x19 + uint32_t mGloBpAmpQ; // x1A + uint32_t mBdsBpAmpI; // x1B + uint32_t mBdsBpAmpQ; // x1C + uint32_t mGalBpAmpI; // x1D + uint32_t mGalBpAmpQ; // x1E + uint64_t mTimeUncNs; // x1F +}; + +// parser +class SystemStatusPQWM1parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eGpsWeek = 1, + eGpsTowMs = 2, + eTimeValid = 3, + eTimeSource = 4, + eTimeUnc = 5, + eClockFreqBias = 6, + eClockFreqBiasUnc = 7, + eXoState = 8, + ePgaGain = 9, + eGpsBpAmpI = 10, + eGpsBpAmpQ = 11, + eAdcI = 12, + eAdcQ = 13, + eJammerGps = 14, + eJammerGlo = 15, + eJammerBds = 16, + eJammerGal = 17, + eRecErrorRecovery = 18, + eAgcGps = 19, + eAgcGlo = 20, + eAgcBds = 21, + eAgcGal = 22, + eMax0 = eAgcGal, + eLeapSeconds = 23, + eLeapSecUnc = 24, + eGloBpAmpI = 25, + eGloBpAmpQ = 26, + eBdsBpAmpI = 27, + eBdsBpAmpQ = 28, + eGalBpAmpI = 29, + eGalBpAmpQ = 30, + eTimeUncNs = 31, + eMax + }; + SystemStatusPQWM1 mM1; + +public: + inline uint16_t getGpsWeek() { return mM1.mGpsWeek; } + inline uint32_t getGpsTowMs() { return mM1.mGpsTowMs; } + inline uint8_t getTimeValid() { return mM1.mTimeValid; } + inline uint8_t getTimeSource() { return mM1.mTimeSource; } + inline int32_t getTimeUnc() { return mM1.mTimeUnc; } + inline int32_t getClockFreqBias() { return mM1.mClockFreqBias; } + inline int32_t getClockFreqBiasUnc() { return mM1.mClockFreqBiasUnc; } + inline uint8_t getXoState() { return mM1.mXoState;} + inline int32_t getPgaGain() { return mM1.mPgaGain; } + inline uint32_t getGpsBpAmpI() { return mM1.mGpsBpAmpI; } + inline uint32_t getGpsBpAmpQ() { return mM1.mGpsBpAmpQ; } + inline uint32_t getAdcI() { return mM1.mAdcI; } + inline uint32_t getAdcQ() { return mM1.mAdcQ; } + inline uint32_t getJammerGps() { return mM1.mJammerGps; } + inline uint32_t getJammerGlo() { return mM1.mJammerGlo; } + inline uint32_t getJammerBds() { return mM1.mJammerBds; } + inline uint32_t getJammerGal() { return mM1.mJammerGal; } + inline uint32_t getAgcGps() { return mM1.mAgcGps; } + inline uint32_t getAgcGlo() { return mM1.mAgcGlo; } + inline uint32_t getAgcBds() { return mM1.mAgcBds; } + inline uint32_t getAgcGal() { return mM1.mAgcGal; } + inline uint32_t getRecErrorRecovery() { return mM1.mRecErrorRecovery; } + inline int32_t getLeapSeconds(){ return mM1.mLeapSeconds; } + inline int32_t getLeapSecUnc() { return mM1.mLeapSecUnc; } + inline uint32_t getGloBpAmpI() { return mM1.mGloBpAmpI; } + inline uint32_t getGloBpAmpQ() { return mM1.mGloBpAmpQ; } + inline uint32_t getBdsBpAmpI() { return mM1.mBdsBpAmpI; } + inline uint32_t getBdsBpAmpQ() { return mM1.mBdsBpAmpQ; } + inline uint32_t getGalBpAmpI() { return mM1.mGalBpAmpI; } + inline uint32_t getGalBpAmpQ() { return mM1.mGalBpAmpQ; } + inline uint64_t getTimeUncNs() { return mM1.mTimeUncNs; } + + SystemStatusPQWM1parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + memset(&mM1, 0, sizeof(mM1)); + if (mField.size() <= eMax0) { + LOC_LOGE("PQWM1parser - invalid size=%zu", mField.size()); + mM1.mTimeValid = 0; + return; + } + mM1.mGpsWeek = atoi(mField[eGpsWeek].c_str()); + mM1.mGpsTowMs = atoi(mField[eGpsTowMs].c_str()); + mM1.mTimeValid = atoi(mField[eTimeValid].c_str()); + mM1.mTimeSource = atoi(mField[eTimeSource].c_str()); + mM1.mTimeUnc = atoi(mField[eTimeUnc].c_str()); + mM1.mClockFreqBias = atoi(mField[eClockFreqBias].c_str()); + mM1.mClockFreqBiasUnc = atoi(mField[eClockFreqBiasUnc].c_str()); + mM1.mXoState = atoi(mField[eXoState].c_str()); + mM1.mPgaGain = atoi(mField[ePgaGain].c_str()); + mM1.mGpsBpAmpI = atoi(mField[eGpsBpAmpI].c_str()); + mM1.mGpsBpAmpQ = atoi(mField[eGpsBpAmpQ].c_str()); + mM1.mAdcI = atoi(mField[eAdcI].c_str()); + mM1.mAdcQ = atoi(mField[eAdcQ].c_str()); + mM1.mJammerGps = atoi(mField[eJammerGps].c_str()); + mM1.mJammerGlo = atoi(mField[eJammerGlo].c_str()); + mM1.mJammerBds = atoi(mField[eJammerBds].c_str()); + mM1.mJammerGal = atoi(mField[eJammerGal].c_str()); + mM1.mRecErrorRecovery = atoi(mField[eRecErrorRecovery].c_str()); + mM1.mAgcGps = atof(mField[eAgcGps].c_str()); + mM1.mAgcGlo = atof(mField[eAgcGlo].c_str()); + mM1.mAgcBds = atof(mField[eAgcBds].c_str()); + mM1.mAgcGal = atof(mField[eAgcGal].c_str()); + if (mField.size() > eLeapSecUnc) { + mM1.mLeapSeconds = atoi(mField[eLeapSeconds].c_str()); + mM1.mLeapSecUnc = atoi(mField[eLeapSecUnc].c_str()); + } + if (mField.size() > eGalBpAmpQ) { + mM1.mGloBpAmpI = atoi(mField[eGloBpAmpI].c_str()); + mM1.mGloBpAmpQ = atoi(mField[eGloBpAmpQ].c_str()); + mM1.mBdsBpAmpI = atoi(mField[eBdsBpAmpI].c_str()); + mM1.mBdsBpAmpQ = atoi(mField[eBdsBpAmpQ].c_str()); + mM1.mGalBpAmpI = atoi(mField[eGalBpAmpI].c_str()); + mM1.mGalBpAmpQ = atoi(mField[eGalBpAmpQ].c_str()); + } + if (mField.size() > eTimeUncNs) { + mM1.mTimeUncNs = strtoull(mField[eTimeUncNs].c_str(), nullptr, 10); + } + } + + inline SystemStatusPQWM1& get() { return mM1;} //getparser +}; + +/****************************************************************************** + SystemStatusPQWP1 +******************************************************************************/ +class SystemStatusPQWP1 +{ +public: + uint8_t mEpiValidity; // x4 + float mEpiLat; // x5 + float mEpiLon; // x6 + float mEpiAlt; // x7 + float mEpiHepe; // x8 + float mEpiAltUnc; // x9 + uint8_t mEpiSrc; // x10 +}; + +class SystemStatusPQWP1parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eUtcTime = 1, + eEpiValidity = 2, + eEpiLat = 3, + eEpiLon = 4, + eEpiAlt = 5, + eEpiHepe = 6, + eEpiAltUnc = 7, + eEpiSrc = 8, + eMax + }; + SystemStatusPQWP1 mP1; + +public: + inline uint8_t getEpiValidity() { return mP1.mEpiValidity; } + inline float getEpiLat() { return mP1.mEpiLat; } + inline float getEpiLon() { return mP1.mEpiLon; } + inline float getEpiAlt() { return mP1.mEpiAlt; } + inline float getEpiHepe() { return mP1.mEpiHepe; } + inline float getEpiAltUnc() { return mP1.mEpiAltUnc; } + inline uint8_t getEpiSrc() { return mP1.mEpiSrc; } + + SystemStatusPQWP1parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP1, 0, sizeof(mP1)); + mP1.mEpiValidity = strtol(mField[eEpiValidity].c_str(), NULL, 16); + mP1.mEpiLat = atof(mField[eEpiLat].c_str()); + mP1.mEpiLon = atof(mField[eEpiLon].c_str()); + mP1.mEpiAlt = atof(mField[eEpiAlt].c_str()); + mP1.mEpiHepe = atoi(mField[eEpiHepe].c_str()); + mP1.mEpiAltUnc = atof(mField[eEpiAltUnc].c_str()); + mP1.mEpiSrc = atoi(mField[eEpiSrc].c_str()); + } + + inline SystemStatusPQWP1& get() { return mP1;} +}; + +/****************************************************************************** + SystemStatusPQWP2 +******************************************************************************/ +class SystemStatusPQWP2 +{ +public: + float mBestLat; // x4 + float mBestLon; // x5 + float mBestAlt; // x6 + float mBestHepe; // x7 + float mBestAltUnc; // x8 +}; + +class SystemStatusPQWP2parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eUtcTime = 1, + eBestLat = 2, + eBestLon = 3, + eBestAlt = 4, + eBestHepe = 5, + eBestAltUnc = 6, + eMax + }; + SystemStatusPQWP2 mP2; + +public: + inline float getBestLat() { return mP2.mBestLat; } + inline float getBestLon() { return mP2.mBestLon; } + inline float getBestAlt() { return mP2.mBestAlt; } + inline float getBestHepe() { return mP2.mBestHepe; } + inline float getBestAltUnc() { return mP2.mBestAltUnc; } + + SystemStatusPQWP2parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP2, 0, sizeof(mP2)); + mP2.mBestLat = atof(mField[eBestLat].c_str()); + mP2.mBestLon = atof(mField[eBestLon].c_str()); + mP2.mBestAlt = atof(mField[eBestAlt].c_str()); + mP2.mBestHepe = atof(mField[eBestHepe].c_str()); + mP2.mBestAltUnc = atof(mField[eBestAltUnc].c_str()); + } + + inline SystemStatusPQWP2& get() { return mP2;} +}; + +/****************************************************************************** + SystemStatusPQWP3 +******************************************************************************/ +class SystemStatusPQWP3 +{ +public: + uint8_t mXtraValidMask; + uint32_t mGpsXtraAge; + uint32_t mGloXtraAge; + uint32_t mBdsXtraAge; + uint32_t mGalXtraAge; + uint32_t mQzssXtraAge; + uint32_t mNavicXtraAge; + uint32_t mGpsXtraValid; + uint32_t mGloXtraValid; + uint64_t mBdsXtraValid; + uint64_t mGalXtraValid; + uint8_t mQzssXtraValid; + uint32_t mNavicXtraValid; +}; + +class SystemStatusPQWP3parser : public SystemStatusNmeaBase +{ +private: + // todo: update for navic once available + enum + { + eTalker = 0, + eUtcTime = 1, + eXtraValidMask = 2, + eGpsXtraAge = 3, + eGloXtraAge = 4, + eBdsXtraAge = 5, + eGalXtraAge = 6, + eQzssXtraAge = 7, + eGpsXtraValid = 8, + eGloXtraValid = 9, + eBdsXtraValid = 10, + eGalXtraValid = 11, + eQzssXtraValid = 12, + eMax + }; + SystemStatusPQWP3 mP3; + +public: + inline uint8_t getXtraValid() { return mP3.mXtraValidMask; } + inline uint32_t getGpsXtraAge() { return mP3.mGpsXtraAge; } + inline uint32_t getGloXtraAge() { return mP3.mGloXtraAge; } + inline uint32_t getBdsXtraAge() { return mP3.mBdsXtraAge; } + inline uint32_t getGalXtraAge() { return mP3.mGalXtraAge; } + inline uint32_t getQzssXtraAge() { return mP3.mQzssXtraAge; } + inline uint32_t getNavicXtraAge() { return mP3.mNavicXtraAge; } + inline uint32_t getGpsXtraValid() { return mP3.mGpsXtraValid; } + inline uint32_t getGloXtraValid() { return mP3.mGloXtraValid; } + inline uint64_t getBdsXtraValid() { return mP3.mBdsXtraValid; } + inline uint64_t getGalXtraValid() { return mP3.mGalXtraValid; } + inline uint8_t getQzssXtraValid() { return mP3.mQzssXtraValid; } + inline uint32_t getNavicXtraValid() { return mP3.mNavicXtraValid; } + + SystemStatusPQWP3parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP3, 0, sizeof(mP3)); + // todo: update for navic once available + mP3.mXtraValidMask = strtol(mField[eXtraValidMask].c_str(), NULL, 16); + mP3.mGpsXtraAge = atoi(mField[eGpsXtraAge].c_str()); + mP3.mGloXtraAge = atoi(mField[eGloXtraAge].c_str()); + mP3.mBdsXtraAge = atoi(mField[eBdsXtraAge].c_str()); + mP3.mGalXtraAge = atoi(mField[eGalXtraAge].c_str()); + mP3.mQzssXtraAge = atoi(mField[eQzssXtraAge].c_str()); + mP3.mGpsXtraValid = strtol(mField[eGpsXtraValid].c_str(), NULL, 16); + mP3.mGloXtraValid = strtol(mField[eGloXtraValid].c_str(), NULL, 16); + mP3.mBdsXtraValid = strtol(mField[eBdsXtraValid].c_str(), NULL, 16); + mP3.mGalXtraValid = strtol(mField[eGalXtraValid].c_str(), NULL, 16); + mP3.mQzssXtraValid = strtol(mField[eQzssXtraValid].c_str(), NULL, 16); + } + + inline SystemStatusPQWP3& get() { return mP3;} +}; + +/****************************************************************************** + SystemStatusPQWP4 +******************************************************************************/ +class SystemStatusPQWP4 +{ +public: + uint32_t mGpsEpheValid; + uint32_t mGloEpheValid; + uint64_t mBdsEpheValid; + uint64_t mGalEpheValid; + uint8_t mQzssEpheValid; +}; + +class SystemStatusPQWP4parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eUtcTime = 1, + eGpsEpheValid = 2, + eGloEpheValid = 3, + eBdsEpheValid = 4, + eGalEpheValid = 5, + eQzssEpheValid = 6, + eMax + }; + SystemStatusPQWP4 mP4; + +public: + inline uint32_t getGpsEpheValid() { return mP4.mGpsEpheValid; } + inline uint32_t getGloEpheValid() { return mP4.mGloEpheValid; } + inline uint64_t getBdsEpheValid() { return mP4.mBdsEpheValid; } + inline uint64_t getGalEpheValid() { return mP4.mGalEpheValid; } + inline uint8_t getQzssEpheValid() { return mP4.mQzssEpheValid; } + + SystemStatusPQWP4parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP4, 0, sizeof(mP4)); + mP4.mGpsEpheValid = strtol(mField[eGpsEpheValid].c_str(), NULL, 16); + mP4.mGloEpheValid = strtol(mField[eGloEpheValid].c_str(), NULL, 16); + mP4.mBdsEpheValid = strtol(mField[eBdsEpheValid].c_str(), NULL, 16); + mP4.mGalEpheValid = strtol(mField[eGalEpheValid].c_str(), NULL, 16); + mP4.mQzssEpheValid = strtol(mField[eQzssEpheValid].c_str(), NULL, 16); + } + + inline SystemStatusPQWP4& get() { return mP4;} +}; + +/****************************************************************************** + SystemStatusPQWP5 +******************************************************************************/ +class SystemStatusPQWP5 +{ +public: + uint32_t mGpsUnknownMask; + uint32_t mGloUnknownMask; + uint64_t mBdsUnknownMask; + uint64_t mGalUnknownMask; + uint8_t mQzssUnknownMask; + uint32_t mNavicUnknownMask; + uint32_t mGpsGoodMask; + uint32_t mGloGoodMask; + uint64_t mBdsGoodMask; + uint64_t mGalGoodMask; + uint8_t mQzssGoodMask; + uint32_t mNavicGoodMask; + uint32_t mGpsBadMask; + uint32_t mGloBadMask; + uint64_t mBdsBadMask; + uint64_t mGalBadMask; + uint8_t mQzssBadMask; + uint32_t mNavicBadMask; +}; + +class SystemStatusPQWP5parser : public SystemStatusNmeaBase +{ +private: + // todo: update for navic once available + enum + { + eTalker = 0, + eUtcTime = 1, + eGpsUnknownMask = 2, + eGloUnknownMask = 3, + eBdsUnknownMask = 4, + eGalUnknownMask = 5, + eQzssUnknownMask = 6, + eGpsGoodMask = 7, + eGloGoodMask = 8, + eBdsGoodMask = 9, + eGalGoodMask = 10, + eQzssGoodMask = 11, + eGpsBadMask = 12, + eGloBadMask = 13, + eBdsBadMask = 14, + eGalBadMask = 15, + eQzssBadMask = 16, + eMax + }; + SystemStatusPQWP5 mP5; + +public: + inline uint32_t getGpsUnknownMask() { return mP5.mGpsUnknownMask; } + inline uint32_t getGloUnknownMask() { return mP5.mGloUnknownMask; } + inline uint64_t getBdsUnknownMask() { return mP5.mBdsUnknownMask; } + inline uint64_t getGalUnknownMask() { return mP5.mGalUnknownMask; } + inline uint8_t getQzssUnknownMask() { return mP5.mQzssUnknownMask; } + inline uint32_t getNavicUnknownMask() { return mP5.mNavicUnknownMask; } + inline uint32_t getGpsGoodMask() { return mP5.mGpsGoodMask; } + inline uint32_t getGloGoodMask() { return mP5.mGloGoodMask; } + inline uint64_t getBdsGoodMask() { return mP5.mBdsGoodMask; } + inline uint64_t getGalGoodMask() { return mP5.mGalGoodMask; } + inline uint8_t getQzssGoodMask() { return mP5.mQzssGoodMask; } + inline uint32_t getNavicGoodMask() { return mP5.mNavicGoodMask; } + inline uint32_t getGpsBadMask() { return mP5.mGpsBadMask; } + inline uint32_t getGloBadMask() { return mP5.mGloBadMask; } + inline uint64_t getBdsBadMask() { return mP5.mBdsBadMask; } + inline uint64_t getGalBadMask() { return mP5.mGalBadMask; } + inline uint8_t getQzssBadMask() { return mP5.mQzssBadMask; } + inline uint32_t getNavicBadMask() { return mP5.mNavicBadMask; } + + SystemStatusPQWP5parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP5, 0, sizeof(mP5)); + // todo: update for navic once available + mP5.mGpsUnknownMask = strtol(mField[eGpsUnknownMask].c_str(), NULL, 16); + mP5.mGloUnknownMask = strtol(mField[eGloUnknownMask].c_str(), NULL, 16); + mP5.mBdsUnknownMask = strtol(mField[eBdsUnknownMask].c_str(), NULL, 16); + mP5.mGalUnknownMask = strtol(mField[eGalUnknownMask].c_str(), NULL, 16); + mP5.mQzssUnknownMask = strtol(mField[eQzssUnknownMask].c_str(), NULL, 16); + mP5.mGpsGoodMask = strtol(mField[eGpsGoodMask].c_str(), NULL, 16); + mP5.mGloGoodMask = strtol(mField[eGloGoodMask].c_str(), NULL, 16); + mP5.mBdsGoodMask = strtol(mField[eBdsGoodMask].c_str(), NULL, 16); + mP5.mGalGoodMask = strtol(mField[eGalGoodMask].c_str(), NULL, 16); + mP5.mQzssGoodMask = strtol(mField[eQzssGoodMask].c_str(), NULL, 16); + mP5.mGpsBadMask = strtol(mField[eGpsBadMask].c_str(), NULL, 16); + mP5.mGloBadMask = strtol(mField[eGloBadMask].c_str(), NULL, 16); + mP5.mBdsBadMask = strtol(mField[eBdsBadMask].c_str(), NULL, 16); + mP5.mGalBadMask = strtol(mField[eGalBadMask].c_str(), NULL, 16); + mP5.mQzssBadMask = strtol(mField[eQzssBadMask].c_str(), NULL, 16); + } + + inline SystemStatusPQWP5& get() { return mP5;} +}; + +/****************************************************************************** + SystemStatusPQWP6parser +******************************************************************************/ +class SystemStatusPQWP6 +{ +public: + uint32_t mFixInfoMask; +}; + +class SystemStatusPQWP6parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eUtcTime = 1, + eFixInfoMask = 2, + eMax + }; + SystemStatusPQWP6 mP6; + +public: + inline uint32_t getFixInfoMask() { return mP6.mFixInfoMask; } + + SystemStatusPQWP6parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + if (mField.size() < eMax) { + return; + } + memset(&mP6, 0, sizeof(mP6)); + mP6.mFixInfoMask = strtol(mField[eFixInfoMask].c_str(), NULL, 16); + } + + inline SystemStatusPQWP6& get() { return mP6;} +}; + +/****************************************************************************** + SystemStatusPQWP7parser +******************************************************************************/ +class SystemStatusPQWP7 +{ +public: + SystemStatusNav mNav[SV_ALL_NUM]; +}; + +class SystemStatusPQWP7parser : public SystemStatusNmeaBase +{ +private: + enum + { + eTalker = 0, + eUtcTime = 1, + eMin = 2 + SV_ALL_NUM_MIN*3, + eMax = 2 + SV_ALL_NUM*3 + }; + SystemStatusPQWP7 mP7; + +public: + SystemStatusPQWP7parser(const char *str_in, uint32_t len_in) + : SystemStatusNmeaBase(str_in, len_in) + { + uint32_t svLimit = SV_ALL_NUM; + if (mField.size() < eMin) { + LOC_LOGE("PQWP7parser - invalid size=%zu", mField.size()); + return; + } + if (mField.size() < eMax) { + // Try reducing limit, accounting for possibly missing NAVIC support + svLimit = SV_ALL_NUM_MIN; + } + + memset(mP7.mNav, 0, sizeof(mP7.mNav)); + for (uint32_t i=0; i +bool SystemStatus::setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s) +{ + if (s.ignore()) { + return false; + } + if (!report.empty() && report.back().equals(static_cast(s.collate(report.back())))) { + // there is no change - just update reported timestamp + report.back().mUtcReported = s.mUtcReported; + return false; + } + + // first event or updated + report.push_back(s); + if (report.size() > s.maxItem) { + report.erase(report.begin()); + } + return true; +} + +template +void SystemStatus::setDefaultIteminReport(TYPE_REPORT& report, const TYPE_ITEM& s) +{ + report.push_back(s); + if (report.size() > s.maxItem) { + report.erase(report.begin()); + } +} + +template +void SystemStatus::getIteminReport(TYPE_REPORT& reportout, const TYPE_ITEM& c) const +{ + reportout.clear(); + if (c.size() >= 1) { + reportout.push_back(c.back()); + reportout.back().dump(); + } +} + +/****************************************************************************** +@brief API to set report data into internal buffer + +@param[In] data pointer to the NMEA string +@param[In] len length of the NMEA string + +@return true when the NMEA is consumed by the method. +******************************************************************************/ +bool SystemStatus::setNmeaString(const char *data, uint32_t len) +{ + if (!loc_nmea_is_debug(data, len)) { + return false; + } + + char buf[SystemStatusNmeaBase::NMEA_MAXSIZE + 1] = { 0 }; + strlcpy(buf, data, sizeof(buf)); + + pthread_mutex_lock(&mMutexSystemStatus); + + // parse the received nmea strings here + if (0 == strncmp(data, "$PQWM1", SystemStatusNmeaBase::NMEA_MINSIZE)) { + SystemStatusPQWM1 s = SystemStatusPQWM1parser(buf, len).get(); + setIteminReport(mCache.mTimeAndClock, SystemStatusTimeAndClock(s)); + setIteminReport(mCache.mXoState, SystemStatusXoState(s)); + setIteminReport(mCache.mRfAndParams, SystemStatusRfAndParams(s)); + setIteminReport(mCache.mErrRecovery, SystemStatusErrRecovery(s)); + } + else if (0 == strncmp(data, "$PQWP1", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mInjectedPosition, + SystemStatusInjectedPosition(SystemStatusPQWP1parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP2", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mBestPosition, + SystemStatusBestPosition(SystemStatusPQWP2parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP3", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mXtra, + SystemStatusXtra(SystemStatusPQWP3parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP4", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mEphemeris, + SystemStatusEphemeris(SystemStatusPQWP4parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP5", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mSvHealth, + SystemStatusSvHealth(SystemStatusPQWP5parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP6", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mPdr, + SystemStatusPdr(SystemStatusPQWP6parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWP7", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mNavData, + SystemStatusNavData(SystemStatusPQWP7parser(buf, len).get())); + } + else if (0 == strncmp(data, "$PQWS1", SystemStatusNmeaBase::NMEA_MINSIZE)) { + setIteminReport(mCache.mPositionFailure, + SystemStatusPositionFailure(SystemStatusPQWS1parser(buf, len).get())); + } + else { + // do nothing + } + + pthread_mutex_unlock(&mMutexSystemStatus); + return true; +} + +/****************************************************************************** +@brief API to set report position data into internal buffer + +@param[In] UlpLocation + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::eventPosition(const UlpLocation& location, + const GpsLocationExtended& locationEx) +{ + bool ret = false; + pthread_mutex_lock(&mMutexSystemStatus); + + ret = setIteminReport(mCache.mLocation, SystemStatusLocation(location, locationEx)); + LOC_LOGV("eventPosition - lat=%f lon=%f alt=%f speed=%f", + location.gpsLocation.latitude, + location.gpsLocation.longitude, + location.gpsLocation.altitude, + location.gpsLocation.speed); + + pthread_mutex_unlock(&mMutexSystemStatus); + return ret; +} + +/****************************************************************************** +@brief API to set report DataItem event into internal buffer + +@param[In] DataItem + +@return true when info is updatated +******************************************************************************/ +bool SystemStatus::eventDataItemNotify(IDataItemCore* dataitem) +{ + bool ret = false; + pthread_mutex_lock(&mMutexSystemStatus); + switch(dataitem->getId()) + { + case AIRPLANEMODE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mAirplaneMode, + SystemStatusAirplaneMode(*(static_cast(dataitem)))); + break; + case ENH_DATA_ITEM_ID: + ret = setIteminReport(mCache.mENH, + SystemStatusENH(*(static_cast(dataitem)))); + break; + case GPSSTATE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mGPSState, + SystemStatusGpsState(*(static_cast(dataitem)))); + break; + case NLPSTATUS_DATA_ITEM_ID: + ret = setIteminReport(mCache.mNLPStatus, + SystemStatusNLPStatus(*(static_cast(dataitem)))); + break; + case WIFIHARDWARESTATE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mWifiHardwareState, + SystemStatusWifiHardwareState(*(static_cast(dataitem)))); + break; + case NETWORKINFO_DATA_ITEM_ID: + ret = setIteminReport(mCache.mNetworkInfo, + SystemStatusNetworkInfo(*(static_cast(dataitem)))); + break; + case RILSERVICEINFO_DATA_ITEM_ID: + ret = setIteminReport(mCache.mRilServiceInfo, + SystemStatusServiceInfo(*(static_cast(dataitem)))); + break; + case RILCELLINFO_DATA_ITEM_ID: + ret = setIteminReport(mCache.mRilCellInfo, + SystemStatusRilCellInfo(*(static_cast(dataitem)))); + break; + case SERVICESTATUS_DATA_ITEM_ID: + ret = setIteminReport(mCache.mServiceStatus, + SystemStatusServiceStatus(*(static_cast(dataitem)))); + break; + case MODEL_DATA_ITEM_ID: + ret = setIteminReport(mCache.mModel, + SystemStatusModel(*(static_cast(dataitem)))); + break; + case MANUFACTURER_DATA_ITEM_ID: + ret = setIteminReport(mCache.mManufacturer, + SystemStatusManufacturer(*(static_cast(dataitem)))); + break; + case ASSISTED_GPS_DATA_ITEM_ID: + ret = setIteminReport(mCache.mAssistedGps, + SystemStatusAssistedGps(*(static_cast(dataitem)))); + break; + case SCREEN_STATE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mScreenState, + SystemStatusScreenState(*(static_cast(dataitem)))); + break; + case POWER_CONNECTED_STATE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mPowerConnectState, + SystemStatusPowerConnectState(*(static_cast(dataitem)))); + break; + case TIMEZONE_CHANGE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mTimeZoneChange, + SystemStatusTimeZoneChange(*(static_cast(dataitem)))); + break; + case TIME_CHANGE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mTimeChange, + SystemStatusTimeChange(*(static_cast(dataitem)))); + break; + case WIFI_SUPPLICANT_STATUS_DATA_ITEM_ID: + ret = setIteminReport(mCache.mWifiSupplicantStatus, + SystemStatusWifiSupplicantStatus(*(static_cast(dataitem)))); + break; + case SHUTDOWN_STATE_DATA_ITEM_ID: + ret = setIteminReport(mCache.mShutdownState, + SystemStatusShutdownState(*(static_cast(dataitem)))); + break; + case TAC_DATA_ITEM_ID: + ret = setIteminReport(mCache.mTac, + SystemStatusTac(*(static_cast(dataitem)))); + break; + case MCCMNC_DATA_ITEM_ID: + ret = setIteminReport(mCache.mMccMnc, + SystemStatusMccMnc(*(static_cast(dataitem)))); + break; + case BTLE_SCAN_DATA_ITEM_ID: + ret = setIteminReport(mCache.mBtDeviceScanDetail, + SystemStatusBtDeviceScanDetail(*(static_cast(dataitem)))); + break; + case BT_SCAN_DATA_ITEM_ID: + ret = setIteminReport(mCache.mBtLeDeviceScanDetail, + SystemStatusBtleDeviceScanDetail(*(static_cast(dataitem)))); + break; + default: + break; + } + pthread_mutex_unlock(&mMutexSystemStatus); + return ret; +} + +/****************************************************************************** +@brief API to get report data into a given buffer + +@param[In] reference to report buffer +@param[In] bool flag to identify latest only or entire buffer + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::getReport(SystemStatusReports& report, bool isLatestOnly) const +{ + pthread_mutex_lock(&mMutexSystemStatus); + + if (isLatestOnly) { + // push back only the latest report and return it + getIteminReport(report.mLocation, mCache.mLocation); + + getIteminReport(report.mTimeAndClock, mCache.mTimeAndClock); + getIteminReport(report.mXoState, mCache.mXoState); + getIteminReport(report.mRfAndParams, mCache.mRfAndParams); + getIteminReport(report.mErrRecovery, mCache.mErrRecovery); + + getIteminReport(report.mInjectedPosition, mCache.mInjectedPosition); + getIteminReport(report.mBestPosition, mCache.mBestPosition); + getIteminReport(report.mXtra, mCache.mXtra); + getIteminReport(report.mEphemeris, mCache.mEphemeris); + getIteminReport(report.mSvHealth, mCache.mSvHealth); + getIteminReport(report.mPdr, mCache.mPdr); + getIteminReport(report.mNavData, mCache.mNavData); + + getIteminReport(report.mPositionFailure, mCache.mPositionFailure); + + getIteminReport(report.mAirplaneMode, mCache.mAirplaneMode); + getIteminReport(report.mENH, mCache.mENH); + getIteminReport(report.mGPSState, mCache.mGPSState); + getIteminReport(report.mNLPStatus, mCache.mNLPStatus); + getIteminReport(report.mWifiHardwareState, mCache.mWifiHardwareState); + getIteminReport(report.mNetworkInfo, mCache.mNetworkInfo); + getIteminReport(report.mRilServiceInfo, mCache.mRilServiceInfo); + getIteminReport(report.mRilCellInfo, mCache.mRilCellInfo); + getIteminReport(report.mServiceStatus, mCache.mServiceStatus); + getIteminReport(report.mModel, mCache.mModel); + getIteminReport(report.mManufacturer, mCache.mManufacturer); + getIteminReport(report.mAssistedGps, mCache.mAssistedGps); + getIteminReport(report.mScreenState, mCache.mScreenState); + getIteminReport(report.mPowerConnectState, mCache.mPowerConnectState); + getIteminReport(report.mTimeZoneChange, mCache.mTimeZoneChange); + getIteminReport(report.mTimeChange, mCache.mTimeChange); + getIteminReport(report.mWifiSupplicantStatus, mCache.mWifiSupplicantStatus); + getIteminReport(report.mShutdownState, mCache.mShutdownState); + getIteminReport(report.mTac, mCache.mTac); + getIteminReport(report.mMccMnc, mCache.mMccMnc); + getIteminReport(report.mBtDeviceScanDetail, mCache.mBtDeviceScanDetail); + getIteminReport(report.mBtLeDeviceScanDetail, mCache.mBtLeDeviceScanDetail); + } + else { + // copy entire reports and return them + report.mLocation.clear(); + + report.mTimeAndClock.clear(); + report.mXoState.clear(); + report.mRfAndParams.clear(); + report.mErrRecovery.clear(); + + report.mInjectedPosition.clear(); + report.mBestPosition.clear(); + report.mXtra.clear(); + report.mEphemeris.clear(); + report.mSvHealth.clear(); + report.mPdr.clear(); + report.mNavData.clear(); + + report.mPositionFailure.clear(); + + report.mAirplaneMode.clear(); + report.mENH.clear(); + report.mGPSState.clear(); + report.mNLPStatus.clear(); + report.mWifiHardwareState.clear(); + report.mNetworkInfo.clear(); + report.mRilServiceInfo.clear(); + report.mRilCellInfo.clear(); + report.mServiceStatus.clear(); + report.mModel.clear(); + report.mManufacturer.clear(); + report.mAssistedGps.clear(); + report.mScreenState.clear(); + report.mPowerConnectState.clear(); + report.mTimeZoneChange.clear(); + report.mTimeChange.clear(); + report.mWifiSupplicantStatus.clear(); + report.mShutdownState.clear(); + report.mTac.clear(); + report.mMccMnc.clear(); + report.mBtDeviceScanDetail.clear(); + report.mBtLeDeviceScanDetail.clear(); + + report = mCache; + } + + pthread_mutex_unlock(&mMutexSystemStatus); + return true; +} + +/****************************************************************************** +@brief API to set default report data + +@param[In] none + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::setDefaultGnssEngineStates(void) +{ + pthread_mutex_lock(&mMutexSystemStatus); + + setDefaultIteminReport(mCache.mLocation, SystemStatusLocation()); + + setDefaultIteminReport(mCache.mTimeAndClock, SystemStatusTimeAndClock()); + setDefaultIteminReport(mCache.mXoState, SystemStatusXoState()); + setDefaultIteminReport(mCache.mRfAndParams, SystemStatusRfAndParams()); + setDefaultIteminReport(mCache.mErrRecovery, SystemStatusErrRecovery()); + + setDefaultIteminReport(mCache.mInjectedPosition, SystemStatusInjectedPosition()); + setDefaultIteminReport(mCache.mBestPosition, SystemStatusBestPosition()); + setDefaultIteminReport(mCache.mXtra, SystemStatusXtra()); + setDefaultIteminReport(mCache.mEphemeris, SystemStatusEphemeris()); + setDefaultIteminReport(mCache.mSvHealth, SystemStatusSvHealth()); + setDefaultIteminReport(mCache.mPdr, SystemStatusPdr()); + setDefaultIteminReport(mCache.mNavData, SystemStatusNavData()); + + setDefaultIteminReport(mCache.mPositionFailure, SystemStatusPositionFailure()); + + pthread_mutex_unlock(&mMutexSystemStatus); + return true; +} + +/****************************************************************************** +@brief API to handle connection status update event from GnssRil + +@param[In] Connection status + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::eventConnectionStatus(bool connected, int8_t type, + bool roaming, NetworkHandle networkHandle, + string& apn) +{ + // send networkinof dataitem to systemstatus observer clients + SystemStatusNetworkInfo s(type, "", "", connected, roaming, + (uint64_t) networkHandle, apn); + mSysStatusObsvr.notify({&s}); + + return true; +} + +/****************************************************************************** +@brief API to update power connect state + +@param[In] power connect status + +@return true when successfully done +******************************************************************************/ +bool SystemStatus::updatePowerConnectState(bool charging) +{ + SystemStatusPowerConnectState s(charging); + mSysStatusObsvr.notify({&s}); + return true; +} +} // namespace loc_core + diff --git a/gps/core/SystemStatus.h b/gps/core/SystemStatus.h new file mode 100644 index 0000000..097e7cc --- /dev/null +++ b/gps/core/SystemStatus.h @@ -0,0 +1,924 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __SYSTEM_STATUS__ +#define __SYSTEM_STATUS__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define GPS_MIN (1) //1-32 +#define SBAS_MIN (33) +#define GLO_MIN (65) //65-88 +#define QZSS_MIN (193) //193-197 +#define BDS_MIN (201) //201-237 +#define GAL_MIN (301) //301-336 +#define NAVIC_MIN (401) //401-414 + +#define GPS_NUM (32) +#define SBAS_NUM (32) +#define GLO_NUM (24) +#define QZSS_NUM (5) +#define BDS_NUM (37) +#define GAL_NUM (36) +#define NAVIC_NUM (14) +#define SV_ALL_NUM_MIN (GPS_NUM + GLO_NUM + QZSS_NUM + BDS_NUM + GAL_NUM) //=134 +#define SV_ALL_NUM (SV_ALL_NUM_MIN + NAVIC_NUM) //=148 + +namespace loc_core +{ + +/****************************************************************************** + SystemStatus report data structure +******************************************************************************/ +class SystemStatusItemBase +{ +public: + timespec mUtcTime; + timespec mUtcReported; + static const uint32_t maxItem = 5; + + SystemStatusItemBase() { + timeval tv; + gettimeofday(&tv, NULL); + mUtcTime.tv_sec = tv.tv_sec; + mUtcTime.tv_nsec = tv.tv_usec*1000ULL; + mUtcReported = mUtcTime; + }; + virtual ~SystemStatusItemBase() {}; + inline virtual SystemStatusItemBase& collate(SystemStatusItemBase&) { + return *this; + } + virtual void dump(void) {}; + inline virtual bool ignore() { return false; }; +}; + +class SystemStatusLocation : public SystemStatusItemBase +{ +public: + bool mValid; + UlpLocation mLocation; + GpsLocationExtended mLocationEx; + inline SystemStatusLocation() : + mValid(false) {} + inline SystemStatusLocation(const UlpLocation& location, + const GpsLocationExtended& locationEx) : + mValid(true), + mLocation(location), + mLocationEx(locationEx) {} + bool equals(const SystemStatusLocation& peer); + void dump(void) override; +}; + +class SystemStatusPQWM1; +class SystemStatusTimeAndClock : public SystemStatusItemBase +{ +public: + uint16_t mGpsWeek; + uint32_t mGpsTowMs; + uint8_t mTimeValid; + uint8_t mTimeSource; + int32_t mTimeUnc; + int32_t mClockFreqBias; + int32_t mClockFreqBiasUnc; + int32_t mLeapSeconds; + int32_t mLeapSecUnc; + uint64_t mTimeUncNs; + inline SystemStatusTimeAndClock() : + mGpsWeek(0), + mGpsTowMs(0), + mTimeValid(0), + mTimeSource(0), + mTimeUnc(0), + mClockFreqBias(0), + mClockFreqBiasUnc(0), + mLeapSeconds(0), + mLeapSecUnc(0), + mTimeUncNs(0ULL) {} + inline SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea); + bool equals(const SystemStatusTimeAndClock& peer); + void dump(void) override; +}; + +class SystemStatusXoState : public SystemStatusItemBase +{ +public: + uint8_t mXoState; + inline SystemStatusXoState() : + mXoState(0) {} + inline SystemStatusXoState(const SystemStatusPQWM1& nmea); + bool equals(const SystemStatusXoState& peer); + void dump(void) override; +}; + +class SystemStatusRfAndParams : public SystemStatusItemBase +{ +public: + int32_t mPgaGain; + uint32_t mGpsBpAmpI; + uint32_t mGpsBpAmpQ; + uint32_t mAdcI; + uint32_t mAdcQ; + uint32_t mJammerGps; + uint32_t mJammerGlo; + uint32_t mJammerBds; + uint32_t mJammerGal; + double mAgcGps; + double mAgcGlo; + double mAgcBds; + double mAgcGal; + uint32_t mGloBpAmpI; + uint32_t mGloBpAmpQ; + uint32_t mBdsBpAmpI; + uint32_t mBdsBpAmpQ; + uint32_t mGalBpAmpI; + uint32_t mGalBpAmpQ; + inline SystemStatusRfAndParams() : + mPgaGain(0), + mGpsBpAmpI(0), + mGpsBpAmpQ(0), + mAdcI(0), + mAdcQ(0), + mJammerGps(0), + mJammerGlo(0), + mJammerBds(0), + mJammerGal(0), + mAgcGps(0), + mAgcGlo(0), + mAgcBds(0), + mAgcGal(0), + mGloBpAmpI(0), + mGloBpAmpQ(0), + mBdsBpAmpI(0), + mBdsBpAmpQ(0), + mGalBpAmpI(0), + mGalBpAmpQ(0) {} + inline SystemStatusRfAndParams(const SystemStatusPQWM1& nmea); + bool equals(const SystemStatusRfAndParams& peer); + void dump(void) override; +}; + +class SystemStatusErrRecovery : public SystemStatusItemBase +{ +public: + uint32_t mRecErrorRecovery; + inline SystemStatusErrRecovery() : + mRecErrorRecovery(0) {}; + inline SystemStatusErrRecovery(const SystemStatusPQWM1& nmea); + bool equals(const SystemStatusErrRecovery& peer); + inline bool ignore() override { return 0 == mRecErrorRecovery; }; + void dump(void) override; +}; + +class SystemStatusPQWP1; +class SystemStatusInjectedPosition : public SystemStatusItemBase +{ +public: + uint8_t mEpiValidity; + float mEpiLat; + float mEpiLon; + float mEpiAlt; + float mEpiHepe; + float mEpiAltUnc; + uint8_t mEpiSrc; + inline SystemStatusInjectedPosition() : + mEpiValidity(0), + mEpiLat(0), + mEpiLon(0), + mEpiAlt(0), + mEpiHepe(0), + mEpiAltUnc(0), + mEpiSrc(0) {} + inline SystemStatusInjectedPosition(const SystemStatusPQWP1& nmea); + bool equals(const SystemStatusInjectedPosition& peer); + void dump(void) override; +}; + +class SystemStatusPQWP2; +class SystemStatusBestPosition : public SystemStatusItemBase +{ +public: + bool mValid; + float mBestLat; + float mBestLon; + float mBestAlt; + float mBestHepe; + float mBestAltUnc; + inline SystemStatusBestPosition() : + mValid(false), + mBestLat(0), + mBestLon(0), + mBestAlt(0), + mBestHepe(0), + mBestAltUnc(0) {} + inline SystemStatusBestPosition(const SystemStatusPQWP2& nmea); + bool equals(const SystemStatusBestPosition& peer); + void dump(void) override; +}; + +class SystemStatusPQWP3; +class SystemStatusXtra : public SystemStatusItemBase +{ +public: + uint8_t mXtraValidMask; + uint32_t mGpsXtraAge; + uint32_t mGloXtraAge; + uint32_t mBdsXtraAge; + uint32_t mGalXtraAge; + uint32_t mQzssXtraAge; + uint32_t mNavicXtraAge; + uint32_t mGpsXtraValid; + uint32_t mGloXtraValid; + uint64_t mBdsXtraValid; + uint64_t mGalXtraValid; + uint8_t mQzssXtraValid; + uint32_t mNavicXtraValid; + inline SystemStatusXtra() : + mXtraValidMask(0), + mGpsXtraAge(0), + mGloXtraAge(0), + mBdsXtraAge(0), + mGalXtraAge(0), + mQzssXtraAge(0), + mNavicXtraAge(0), + mGpsXtraValid(0), + mGloXtraValid(0), + mBdsXtraValid(0ULL), + mGalXtraValid(0ULL), + mQzssXtraValid(0), + mNavicXtraValid(0) {} + inline SystemStatusXtra(const SystemStatusPQWP3& nmea); + bool equals(const SystemStatusXtra& peer); + void dump(void) override; +}; + +class SystemStatusPQWP4; +class SystemStatusEphemeris : public SystemStatusItemBase +{ +public: + uint32_t mGpsEpheValid; + uint32_t mGloEpheValid; + uint64_t mBdsEpheValid; + uint64_t mGalEpheValid; + uint8_t mQzssEpheValid; + inline SystemStatusEphemeris() : + mGpsEpheValid(0), + mGloEpheValid(0), + mBdsEpheValid(0ULL), + mGalEpheValid(0ULL), + mQzssEpheValid(0) {} + inline SystemStatusEphemeris(const SystemStatusPQWP4& nmea); + bool equals(const SystemStatusEphemeris& peer); + void dump(void) override; +}; + +class SystemStatusPQWP5; +class SystemStatusSvHealth : public SystemStatusItemBase +{ +public: + uint32_t mGpsUnknownMask; + uint32_t mGloUnknownMask; + uint64_t mBdsUnknownMask; + uint64_t mGalUnknownMask; + uint8_t mQzssUnknownMask; + uint32_t mNavicUnknownMask; + uint32_t mGpsGoodMask; + uint32_t mGloGoodMask; + uint64_t mBdsGoodMask; + uint64_t mGalGoodMask; + uint8_t mQzssGoodMask; + uint32_t mNavicGoodMask; + uint32_t mGpsBadMask; + uint32_t mGloBadMask; + uint64_t mBdsBadMask; + uint64_t mGalBadMask; + uint8_t mQzssBadMask; + uint32_t mNavicBadMask; + inline SystemStatusSvHealth() : + mGpsUnknownMask(0), + mGloUnknownMask(0), + mBdsUnknownMask(0ULL), + mGalUnknownMask(0ULL), + mQzssUnknownMask(0), + mNavicUnknownMask(0), + mGpsGoodMask(0), + mGloGoodMask(0), + mBdsGoodMask(0ULL), + mGalGoodMask(0ULL), + mQzssGoodMask(0), + mNavicGoodMask(0), + mGpsBadMask(0), + mGloBadMask(0), + mBdsBadMask(0ULL), + mGalBadMask(0ULL), + mQzssBadMask(0), + mNavicBadMask(0) {} + inline SystemStatusSvHealth(const SystemStatusPQWP5& nmea); + bool equals(const SystemStatusSvHealth& peer); + void dump(void) override; +}; + +class SystemStatusPQWP6; +class SystemStatusPdr : public SystemStatusItemBase +{ +public: + uint32_t mFixInfoMask; + inline SystemStatusPdr() : + mFixInfoMask(0) {} + inline SystemStatusPdr(const SystemStatusPQWP6& nmea); + bool equals(const SystemStatusPdr& peer); + void dump(void) override; +}; + +class SystemStatusPQWP7; +struct SystemStatusNav +{ + GnssEphemerisType mType; + GnssEphemerisSource mSource; + int32_t mAgeSec; +}; + +class SystemStatusNavData : public SystemStatusItemBase +{ +public: + SystemStatusNav mNav[SV_ALL_NUM]; + inline SystemStatusNavData() { + for (uint32_t i=0; i(curInfo)).mAllTypes; + string& apn = (static_cast(curInfo)).mApn; + // Replace current with cached table for now and then update + memcpy(mAllNetworkHandles, + (static_cast(curInfo)).getNetworkHandle(), + sizeof(mAllNetworkHandles)); + // Update the apn for non-mobile type connections. + if (TYPE_MOBILE != mType && apn.compare("") != 0) { + mApn = apn; + } + if (mConnected) { + mAllTypes |= allTypes; + for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) { + if (mNetworkHandle == mAllNetworkHandles[i].networkHandle) { + LOC_LOGD("collate duplicate detected, not updating"); + break; + } + if (NETWORK_HANDLE_UNKNOWN == mAllNetworkHandles[i].networkHandle) { + mAllNetworkHandles[i].networkHandle = mNetworkHandle; + mAllNetworkHandles[i].networkType = (loc_core::NetworkType) mType; + break; + } + } + } else if (0 != mAllTypes) { + uint8_t deletedIndex = MAX_NETWORK_HANDLES; + uint8_t lastValidIndex = 0; + uint8_t typeCount = 0; + for (; lastValidIndex < MAX_NETWORK_HANDLES && + NETWORK_HANDLE_UNKNOWN != mAllNetworkHandles[lastValidIndex].networkHandle; + ++lastValidIndex) { + // Maintain count for number of network handles still + // connected for given type + if (mType == (int32_t)mAllNetworkHandles[lastValidIndex].networkType) { + if (mNetworkHandle == mAllNetworkHandles[lastValidIndex].networkHandle) { + deletedIndex = lastValidIndex; + } else { + typeCount++; + } + } + + } + if (lastValidIndex > 0) { + --lastValidIndex; + } + + if (MAX_NETWORK_HANDLES != deletedIndex) { + LOC_LOGd("deletedIndex:%u, lastValidIndex:%u, typeCount:%u", + deletedIndex, lastValidIndex, typeCount); + mAllNetworkHandles[deletedIndex] = mAllNetworkHandles[lastValidIndex]; + mAllNetworkHandles[lastValidIndex].networkHandle = NETWORK_HANDLE_UNKNOWN; + mAllNetworkHandles[lastValidIndex].networkType = TYPE_UNKNOWN; + } + + // If no more handles of given type, set bitmask + if (0 == typeCount) { + mAllTypes = (allTypes & (~mAllTypes)); + LOC_LOGD("mAllTypes:%" PRIx64, mAllTypes); + } + } // else (mConnected == false && mAllTypes == 0) + // we keep mAllTypes as 0, which means no more connections. + + if (nullptr != mSrcObjPtr) { + // this is critical, changing mAllTypes of the original obj + mSrcObjPtr->mAllTypes = mAllTypes; + memcpy(mSrcObjPtr->mAllNetworkHandles, + mAllNetworkHandles, + sizeof(mSrcObjPtr->mAllNetworkHandles)); + } + return *this; + } + inline void dump(void) override { + LOC_LOGD("NetworkInfo: mAllTypes=%" PRIx64 " connected=%u mType=%x mApn=%s", + mAllTypes, mConnected, mType, mApn.c_str()); + } +}; + +class SystemStatusServiceInfo : public SystemStatusItemBase, + public RilServiceInfoDataItemBase +{ +public: + inline SystemStatusServiceInfo() : + RilServiceInfoDataItemBase() {} + inline SystemStatusServiceInfo(const RilServiceInfoDataItemBase& itemBase) : + RilServiceInfoDataItemBase(itemBase) {} + inline bool equals(const SystemStatusServiceInfo& peer) { + return static_cast(peer) == + static_cast(*this); + } +}; + +class SystemStatusRilCellInfo : public SystemStatusItemBase, + public RilCellInfoDataItemBase +{ +public: + inline SystemStatusRilCellInfo() : + RilCellInfoDataItemBase() {} + inline SystemStatusRilCellInfo(const RilCellInfoDataItemBase& itemBase) : + RilCellInfoDataItemBase(itemBase) {} + inline bool equals(const SystemStatusRilCellInfo& peer) { + return static_cast(peer) == + static_cast(*this); + } +}; + +class SystemStatusServiceStatus : public SystemStatusItemBase, + public ServiceStatusDataItemBase +{ +public: + inline SystemStatusServiceStatus(int32_t mServiceState=0) : + ServiceStatusDataItemBase(mServiceState) {} + inline SystemStatusServiceStatus(const ServiceStatusDataItemBase& itemBase) : + ServiceStatusDataItemBase(itemBase) {} + inline bool equals(const SystemStatusServiceStatus& peer) { + return (mServiceState == peer.mServiceState); + } +}; + +class SystemStatusModel : public SystemStatusItemBase, + public ModelDataItemBase +{ +public: + inline SystemStatusModel(string name="") : + ModelDataItemBase(name) {} + inline SystemStatusModel(const ModelDataItemBase& itemBase) : + ModelDataItemBase(itemBase) {} + inline bool equals(const SystemStatusModel& peer) { + return (mModel == peer.mModel); + } +}; + +class SystemStatusManufacturer : public SystemStatusItemBase, + public ManufacturerDataItemBase +{ +public: + inline SystemStatusManufacturer(string name="") : + ManufacturerDataItemBase(name) {} + inline SystemStatusManufacturer(const ManufacturerDataItemBase& itemBase) : + ManufacturerDataItemBase(itemBase) {} + inline bool equals(const SystemStatusManufacturer& peer) { + return (mManufacturer == peer.mManufacturer); + } +}; + +class SystemStatusAssistedGps : public SystemStatusItemBase, + public AssistedGpsDataItemBase +{ +public: + inline SystemStatusAssistedGps(bool enabled=false) : + AssistedGpsDataItemBase(enabled) {} + inline SystemStatusAssistedGps(const AssistedGpsDataItemBase& itemBase) : + AssistedGpsDataItemBase(itemBase) {} + inline bool equals(const SystemStatusAssistedGps& peer) { + return (mEnabled == peer.mEnabled); + } +}; + +class SystemStatusScreenState : public SystemStatusItemBase, + public ScreenStateDataItemBase +{ +public: + inline SystemStatusScreenState(bool state=false) : + ScreenStateDataItemBase(state) {} + inline SystemStatusScreenState(const ScreenStateDataItemBase& itemBase) : + ScreenStateDataItemBase(itemBase) {} + inline bool equals(const SystemStatusScreenState& peer) { + return (mState == peer.mState); + } +}; + +class SystemStatusPowerConnectState : public SystemStatusItemBase, + public PowerConnectStateDataItemBase +{ +public: + inline SystemStatusPowerConnectState(bool state=false) : + PowerConnectStateDataItemBase(state) {} + inline SystemStatusPowerConnectState(const PowerConnectStateDataItemBase& itemBase) : + PowerConnectStateDataItemBase(itemBase) {} + inline bool equals(const SystemStatusPowerConnectState& peer) { + return (mState == peer.mState); + } +}; + +class SystemStatusTimeZoneChange : public SystemStatusItemBase, + public TimeZoneChangeDataItemBase +{ +public: + inline SystemStatusTimeZoneChange( + int64_t currTimeMillis=0ULL, int32_t rawOffset=0, int32_t dstOffset=0) : + TimeZoneChangeDataItemBase(currTimeMillis, rawOffset, dstOffset) {} + inline SystemStatusTimeZoneChange(const TimeZoneChangeDataItemBase& itemBase) : + TimeZoneChangeDataItemBase(itemBase) {} + inline bool equals(const SystemStatusTimeZoneChange& peer) { + return ((mCurrTimeMillis == peer.mCurrTimeMillis) && + (mRawOffsetTZ == peer.mRawOffsetTZ) && + (mDstOffsetTZ == peer.mDstOffsetTZ)); + } +}; + +class SystemStatusTimeChange : public SystemStatusItemBase, + public TimeChangeDataItemBase +{ +public: + inline SystemStatusTimeChange( + int64_t currTimeMillis=0ULL, int32_t rawOffset=0, int32_t dstOffset=0) : + TimeChangeDataItemBase(currTimeMillis, rawOffset, dstOffset) {} + inline SystemStatusTimeChange(const TimeChangeDataItemBase& itemBase) : + TimeChangeDataItemBase(itemBase) {} + inline bool equals(const SystemStatusTimeChange& peer) { + return ((mCurrTimeMillis == peer.mCurrTimeMillis) && + (mRawOffsetTZ == peer.mRawOffsetTZ) && + (mDstOffsetTZ == peer.mDstOffsetTZ)); + } +}; + +class SystemStatusWifiSupplicantStatus : public SystemStatusItemBase, + public WifiSupplicantStatusDataItemBase +{ +public: + inline SystemStatusWifiSupplicantStatus() : + WifiSupplicantStatusDataItemBase() {} + inline SystemStatusWifiSupplicantStatus(const WifiSupplicantStatusDataItemBase& itemBase) : + WifiSupplicantStatusDataItemBase(itemBase) {} + inline bool equals(const SystemStatusWifiSupplicantStatus& peer) { + return ((mState == peer.mState) && + (mApMacAddressValid == peer.mApMacAddressValid) && + (mWifiApSsidValid == peer.mWifiApSsidValid) && + (mWifiApSsid == peer.mWifiApSsid)); + } +}; + +class SystemStatusShutdownState : public SystemStatusItemBase, + public ShutdownStateDataItemBase +{ +public: + inline SystemStatusShutdownState(bool state=false) : + ShutdownStateDataItemBase(state) {} + inline SystemStatusShutdownState(const ShutdownStateDataItemBase& itemBase) : + ShutdownStateDataItemBase(itemBase) {} + inline bool equals(const SystemStatusShutdownState& peer) { + return (mState == peer.mState); + } +}; + +class SystemStatusTac : public SystemStatusItemBase, + public TacDataItemBase +{ +public: + inline SystemStatusTac(std::string value="") : + TacDataItemBase(value) {} + inline SystemStatusTac(const TacDataItemBase& itemBase) : + TacDataItemBase(itemBase) {} + inline bool equals(const SystemStatusTac& peer) { + return (mValue == peer.mValue); + } + inline void dump(void) override { + LOC_LOGD("Tac: value=%s", mValue.c_str()); + } +}; + +class SystemStatusMccMnc : public SystemStatusItemBase, + public MccmncDataItemBase +{ +public: + inline SystemStatusMccMnc(std::string value="") : + MccmncDataItemBase(value) {} + inline SystemStatusMccMnc(const MccmncDataItemBase& itemBase) : + MccmncDataItemBase(itemBase) {} + inline bool equals(const SystemStatusMccMnc& peer) { + return (mValue == peer.mValue); + } + inline void dump(void) override { + LOC_LOGD("TacMccMnc value=%s", mValue.c_str()); + } +}; + +class SystemStatusBtDeviceScanDetail : public SystemStatusItemBase, + public BtDeviceScanDetailsDataItemBase +{ +public: + inline SystemStatusBtDeviceScanDetail() : + BtDeviceScanDetailsDataItemBase() {} + inline SystemStatusBtDeviceScanDetail(const BtDeviceScanDetailsDataItemBase& itemBase) : + BtDeviceScanDetailsDataItemBase(itemBase) {} + inline bool equals(const SystemStatusBtDeviceScanDetail& peer) { + return ((mApSrnRssi == peer.mApSrnRssi) && + (0 == memcmp(mApSrnMacAddress, peer.mApSrnMacAddress, sizeof(mApSrnMacAddress))) && + (mApSrnTimestamp == peer.mApSrnTimestamp) && + (mRequestTimestamp == peer.mRequestTimestamp) && + (mReceiveTimestamp == peer.mReceiveTimestamp)); + } +}; + +class SystemStatusBtleDeviceScanDetail : public SystemStatusItemBase, + public BtLeDeviceScanDetailsDataItemBase +{ +public: + inline SystemStatusBtleDeviceScanDetail() : + BtLeDeviceScanDetailsDataItemBase() {} + inline SystemStatusBtleDeviceScanDetail(const BtLeDeviceScanDetailsDataItemBase& itemBase) : + BtLeDeviceScanDetailsDataItemBase(itemBase) {} + inline bool equals(const SystemStatusBtleDeviceScanDetail& peer) { + return ((mApSrnRssi == peer.mApSrnRssi) && + (0 == memcmp(mApSrnMacAddress, peer.mApSrnMacAddress, sizeof(mApSrnMacAddress))) && + (mApSrnTimestamp == peer.mApSrnTimestamp) && + (mRequestTimestamp == peer.mRequestTimestamp) && + (mReceiveTimestamp == peer.mReceiveTimestamp)); + } +}; + +/****************************************************************************** + SystemStatusReports +******************************************************************************/ +class SystemStatusReports +{ +public: + // from QMI_LOC indication + std::vector mLocation; + + // from ME debug NMEA + std::vector mTimeAndClock; + std::vector mXoState; + std::vector mRfAndParams; + std::vector mErrRecovery; + + // from PE debug NMEA + std::vector mInjectedPosition; + std::vector mBestPosition; + std::vector mXtra; + std::vector mEphemeris; + std::vector mSvHealth; + std::vector mPdr; + std::vector mNavData; + + // from SM debug NMEA + std::vector mPositionFailure; + + // from dataitems observer + std::vector mAirplaneMode; + std::vector mENH; + std::vector mGPSState; + std::vector mNLPStatus; + std::vector mWifiHardwareState; + std::vector mNetworkInfo; + std::vector mRilServiceInfo; + std::vector mRilCellInfo; + std::vector mServiceStatus; + std::vector mModel; + std::vector mManufacturer; + std::vector mAssistedGps; + std::vector mScreenState; + std::vector mPowerConnectState; + std::vector mTimeZoneChange; + std::vector mTimeChange; + std::vector mWifiSupplicantStatus; + std::vector mShutdownState; + std::vector mTac; + std::vector mMccMnc; + std::vector mBtDeviceScanDetail; + std::vector mBtLeDeviceScanDetail; +}; + +/****************************************************************************** + SystemStatus +******************************************************************************/ +class SystemStatus +{ +private: + static SystemStatus *mInstance; + SystemStatusOsObserver mSysStatusObsvr; + // ctor + SystemStatus(const MsgTask* msgTask); + // dtor + inline ~SystemStatus() {} + + // Data members + static pthread_mutex_t mMutexSystemStatus; + SystemStatusReports mCache; + + template + bool setIteminReport(TYPE_REPORT& report, TYPE_ITEM&& s); + + // set default dataitem derived item in report cache + template + void setDefaultIteminReport(TYPE_REPORT& report, const TYPE_ITEM& s); + + template + void getIteminReport(TYPE_REPORT& reportout, const TYPE_ITEM& c) const; + +public: + // Static methods + static SystemStatus* getInstance(const MsgTask* msgTask); + static void destroyInstance(); + IOsObserver* getOsObserver(); + + // Helpers + bool eventPosition(const UlpLocation& location,const GpsLocationExtended& locationEx); + bool eventDataItemNotify(IDataItemCore* dataitem); + bool setNmeaString(const char *data, uint32_t len); + bool getReport(SystemStatusReports& reports, bool isLatestonly = false) const; + bool setDefaultGnssEngineStates(void); + bool eventConnectionStatus(bool connected, int8_t type, + bool roaming, NetworkHandle networkHandle, string& apn); + bool updatePowerConnectState(bool charging); + void resetNetworkInfo(); +}; + +} // namespace loc_core + +#endif //__SYSTEM_STATUS__ + diff --git a/gps/core/SystemStatusOsObserver.cpp b/gps/core/SystemStatusOsObserver.cpp new file mode 100644 index 0000000..8fd9564 --- /dev/null +++ b/gps/core/SystemStatusOsObserver.cpp @@ -0,0 +1,592 @@ +/* Copyright (c) 2015-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "LocSvc_SystemStatusOsObserver" + +#include +#include +#include +#include +#include + +namespace loc_core +{ +template +COUT SystemStatusOsObserver::containerTransfer(CINT& inContainer) { + COUT outContainer = {}; + for (auto item : inContainer) { + outContainer.insert(outContainer.begin(), item); + } + return outContainer; +} + +SystemStatusOsObserver::~SystemStatusOsObserver() { + // Close data-item library handle + DataItemsFactoryProxy::closeDataItemLibraryHandle(); + + // Destroy cache + for (auto each : mDataItemCache) { + if (nullptr != each.second) { + delete each.second; + } + } + + mDataItemCache.clear(); +} + +void SystemStatusOsObserver::setSubscriptionObj(IDataItemSubscription* subscriptionObj) +{ + struct SetSubsObj : public LocMsg { + ObserverContext& mContext; + IDataItemSubscription* mSubsObj; + inline SetSubsObj(ObserverContext& context, IDataItemSubscription* subscriptionObj) : + mContext(context), mSubsObj(subscriptionObj) {} + void proc() const { + LOC_LOGi("SetSubsObj::enter"); + mContext.mSubscriptionObj = mSubsObj; + + if (!mContext.mSSObserver->mDataItemToClients.empty()) { + list dis( + containerTransfer, list>( + mContext.mSSObserver->mDataItemToClients.getKeys())); + mContext.mSubscriptionObj->subscribe(dis, mContext.mSSObserver); + mContext.mSubscriptionObj->requestData(dis, mContext.mSSObserver); + } + LOC_LOGi("SetSubsObj::exit"); + } + }; + + if (nullptr == subscriptionObj) { + LOC_LOGw("subscriptionObj is NULL"); + } else { + mContext.mMsgTask->sendMsg(new SetSubsObj(mContext, subscriptionObj)); + } +} + +/****************************************************************************** + IDataItemSubscription Overrides +******************************************************************************/ +void SystemStatusOsObserver::subscribe(const list& l, IDataItemObserver* client, + bool toRequestData) +{ + struct HandleSubscribeReq : public LocMsg { + inline HandleSubscribeReq(SystemStatusOsObserver* parent, + list& l, IDataItemObserver* client, bool requestData) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)), + diItemlist(l), + mToRequestData(requestData) {} + + void proc() const { + unordered_set dataItemsToSubscribe = {}; + mParent->mDataItemToClients.add(mDataItemSet, {mClient}, &dataItemsToSubscribe); + mParent->mClientToDataItems.add(mClient, mDataItemSet); + + mParent->sendCachedDataItems(mDataItemSet, mClient); + + // Send subscription set to framework + if (nullptr != mParent->mContext.mSubscriptionObj) { + if (mToRequestData) { + LOC_LOGD("Request Data sent to framework for the following"); + mParent->mContext.mSubscriptionObj->requestData(diItemlist, mParent); + } else if (!dataItemsToSubscribe.empty()) { + LOC_LOGD("Subscribe Request sent to framework for the following"); + mParent->logMe(dataItemsToSubscribe); + mParent->mContext.mSubscriptionObj->subscribe( + containerTransfer, list>( + std::move(dataItemsToSubscribe)), + mParent); + } + } + } + mutable SystemStatusOsObserver* mParent; + IDataItemObserver* mClient; + const unordered_set mDataItemSet; + const list diItemlist; + bool mToRequestData; + }; + + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg( + new HandleSubscribeReq(this, (list&)l, client, toRequestData)); + } +} + +void SystemStatusOsObserver::updateSubscription( + const list& l, IDataItemObserver* client) +{ + struct HandleUpdateSubscriptionReq : public LocMsg { + HandleUpdateSubscriptionReq(SystemStatusOsObserver* parent, + list& l, IDataItemObserver* client) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)) {} + + void proc() const { + unordered_set dataItemsToSubscribe = {}; + unordered_set dataItemsToUnsubscribe = {}; + unordered_set clients({mClient}); + // below removes clients from all entries keyed with the return of the + // mClientToDataItems.update() call. If leaving an empty set of clients as the + // result, the entire entry will be removed. dataItemsToUnsubscribe will be + // populated to keep the keys of the removed entries. + mParent->mDataItemToClients.trimOrRemove( + // this call updates map; removes + // the DataItemId's that are not new to the clietn from mDataItemSet; + // and returns a set of mDataItemSet's that are no longer used by client. + // This unused set of mDataItemSet's is passed to trimOrRemove method of + // map to remove the client from the + // corresponding entries, and gets a set of the entries that are + // removed from the map as a result. + mParent->mClientToDataItems.update(mClient, + (unordered_set&)mDataItemSet), + clients, &dataItemsToUnsubscribe, nullptr); + // below adds mClient to map, and populates + // new keys added to that map, which are DataItemIds to be subscribed. + mParent->mDataItemToClients.add(mDataItemSet, clients, &dataItemsToSubscribe); + + // Send First Response + mParent->sendCachedDataItems(mDataItemSet, mClient); + + if (nullptr != mParent->mContext.mSubscriptionObj) { + // Send subscription set to framework + if (!dataItemsToSubscribe.empty()) { + LOC_LOGD("Subscribe Request sent to framework for the following"); + mParent->logMe(dataItemsToSubscribe); + + mParent->mContext.mSubscriptionObj->subscribe( + containerTransfer, list>( + std::move(dataItemsToSubscribe)), + mParent); + } + + // Send unsubscribe to framework + if (!dataItemsToUnsubscribe.empty()) { + LOC_LOGD("Unsubscribe Request sent to framework for the following"); + mParent->logMe(dataItemsToUnsubscribe); + + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); + } + } + } + SystemStatusOsObserver* mParent; + IDataItemObserver* mClient; + unordered_set mDataItemSet; + }; + + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg( + new HandleUpdateSubscriptionReq(this, (list&)l, client)); + } +} + +void SystemStatusOsObserver::unsubscribe( + const list& l, IDataItemObserver* client) +{ + struct HandleUnsubscribeReq : public LocMsg { + HandleUnsubscribeReq(SystemStatusOsObserver* parent, + list& l, IDataItemObserver* client) : + mParent(parent), mClient(client), + mDataItemSet(containerTransfer, unordered_set>(l)) {} + + void proc() const { + unordered_set dataItemsUnusedByClient = {}; + unordered_set clientToRemove = {}; + unordered_set dataItemsToUnsubscribe = {}; + mParent->mClientToDataItems.trimOrRemove({mClient}, mDataItemSet, &clientToRemove, + &dataItemsUnusedByClient); + mParent->mDataItemToClients.trimOrRemove(dataItemsUnusedByClient, {mClient}, + &dataItemsToUnsubscribe, nullptr); + + if (nullptr != mParent->mContext.mSubscriptionObj && !dataItemsToUnsubscribe.empty()) { + LOC_LOGD("Unsubscribe Request sent to framework for the following data items"); + mParent->logMe(dataItemsToUnsubscribe); + + // Send unsubscribe to framework + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); + } + } + SystemStatusOsObserver* mParent; + IDataItemObserver* mClient; + unordered_set mDataItemSet; + }; + + if (l.empty() || nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg(new HandleUnsubscribeReq(this, (list&)l, client)); + } +} + +void SystemStatusOsObserver::unsubscribeAll(IDataItemObserver* client) +{ + struct HandleUnsubscribeAllReq : public LocMsg { + HandleUnsubscribeAllReq(SystemStatusOsObserver* parent, + IDataItemObserver* client) : + mParent(parent), mClient(client) {} + + void proc() const { + unordered_set diByClient = mParent->mClientToDataItems.getValSet(mClient); + + if (!diByClient.empty()) { + unordered_set dataItemsToUnsubscribe; + mParent->mClientToDataItems.remove(mClient); + mParent->mDataItemToClients.trimOrRemove(diByClient, {mClient}, + &dataItemsToUnsubscribe, nullptr); + + if (!dataItemsToUnsubscribe.empty() && + nullptr != mParent->mContext.mSubscriptionObj) { + + LOC_LOGD("Unsubscribe Request sent to framework for the following data items"); + mParent->logMe(dataItemsToUnsubscribe); + + // Send unsubscribe to framework + mParent->mContext.mSubscriptionObj->unsubscribe( + containerTransfer, list>( + std::move(dataItemsToUnsubscribe)), + mParent); + } + } + } + SystemStatusOsObserver* mParent; + IDataItemObserver* mClient; + }; + + if (nullptr == client) { + LOC_LOGw("Data item set is empty or client is nullptr"); + } else { + mContext.mMsgTask->sendMsg(new HandleUnsubscribeAllReq(this, client)); + } +} + +/****************************************************************************** + IDataItemObserver Overrides +******************************************************************************/ +void SystemStatusOsObserver::notify(const list& dlist) +{ + struct HandleNotify : public LocMsg { + HandleNotify(SystemStatusOsObserver* parent, vector& v) : + mParent(parent), mDiVec(std::move(v)) {} + + inline virtual ~HandleNotify() { + for (auto item : mDiVec) { + delete item; + } + } + + void proc() const { + // Update Cache with received data items and prepare + // list of data items to be sent. + unordered_set dataItemIdsToBeSent = {}; + for (auto item : mDiVec) { + if (mParent->updateCache(item)) { + dataItemIdsToBeSent.insert(item->getId()); + } + } + + // Send data item to all subscribed clients + unordered_set clientSet = {}; + for (auto each : dataItemIdsToBeSent) { + auto clients = mParent->mDataItemToClients.getValSetPtr(each); + if (nullptr != clients) { + clientSet.insert(clients->begin(), clients->end()); + } + } + + for (auto client : clientSet) { + unordered_set dataItemIdsForThisClient( + mParent->mClientToDataItems.getValSet(client)); + for (auto itr = dataItemIdsForThisClient.begin(); + itr != dataItemIdsForThisClient.end(); ) { + if (dataItemIdsToBeSent.find(*itr) == dataItemIdsToBeSent.end()) { + itr = dataItemIdsForThisClient.erase(itr); + } else { + itr++; + } + } + + mParent->sendCachedDataItems(dataItemIdsForThisClient, client); + } + } + SystemStatusOsObserver* mParent; + const vector mDiVec; + }; + + if (!dlist.empty()) { + vector dataItemVec(dlist.size()); + + for (auto each : dlist) { + + IDataItemCore* di = DataItemsFactoryProxy::createNewDataItem(each->getId()); + if (nullptr == di) { + LOC_LOGw("Unable to create dataitem:%d", each->getId()); + continue; + } + + // Copy contents into the newly created data item + di->copy(each); + + // add this dataitem if updated from last one + dataItemVec.push_back(di); + IF_LOC_LOGD { + string dv; + di->stringify(dv); + LOC_LOGd("notify: DataItem In Value:%s", dv.c_str()); + } + } + + if (!dataItemVec.empty()) { + mContext.mMsgTask->sendMsg(new HandleNotify(this, dataItemVec)); + } + } +} + +/****************************************************************************** + IFrameworkActionReq Overrides +******************************************************************************/ +void SystemStatusOsObserver::turnOn(DataItemId dit, int timeOut) +{ + if (nullptr == mContext.mFrameworkActionReqObj) { + LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__); + return; + } + + // Check if data item exists in mActiveRequestCount + DataItemIdToInt::iterator citer = mActiveRequestCount.find(dit); + if (citer == mActiveRequestCount.end()) { + // Data item not found in map + // Add reference count as 1 and add dataitem to map + pair cpair(dit, 1); + mActiveRequestCount.insert(cpair); + LOC_LOGD("Sending turnOn request"); + + // Send action turn on to framework + struct HandleTurnOnMsg : public LocMsg { + HandleTurnOnMsg(IFrameworkActionReq* framework, + DataItemId dit, int timeOut) : + mFrameworkActionReqObj(framework), mDataItemId(dit), mTimeOut(timeOut) {} + virtual ~HandleTurnOnMsg() {} + void proc() const { + mFrameworkActionReqObj->turnOn(mDataItemId, mTimeOut); + } + IFrameworkActionReq* mFrameworkActionReqObj; + DataItemId mDataItemId; + int mTimeOut; + }; + mContext.mMsgTask->sendMsg( + new (nothrow) HandleTurnOnMsg(mContext.mFrameworkActionReqObj, dit, timeOut)); + } + else { + // Found in map, update reference count + citer->second++; + LOC_LOGD("turnOn - Data item:%d Num_refs:%d", dit, citer->second); + } +} + +void SystemStatusOsObserver::turnOff(DataItemId dit) +{ + if (nullptr == mContext.mFrameworkActionReqObj) { + LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__); + return; + } + + // Check if data item exists in mActiveRequestCount + DataItemIdToInt::iterator citer = mActiveRequestCount.find(dit); + if (citer != mActiveRequestCount.end()) { + // found + citer->second--; + LOC_LOGD("turnOff - Data item:%d Remaining:%d", dit, citer->second); + if(citer->second == 0) { + // if this was last reference, remove item from map and turn off module + mActiveRequestCount.erase(citer); + + // Send action turn off to framework + struct HandleTurnOffMsg : public LocMsg { + HandleTurnOffMsg(IFrameworkActionReq* framework, DataItemId dit) : + mFrameworkActionReqObj(framework), mDataItemId(dit) {} + virtual ~HandleTurnOffMsg() {} + void proc() const { + mFrameworkActionReqObj->turnOff(mDataItemId); + } + IFrameworkActionReq* mFrameworkActionReqObj; + DataItemId mDataItemId; + }; + mContext.mMsgTask->sendMsg( + new (nothrow) HandleTurnOffMsg(mContext.mFrameworkActionReqObj, dit)); + } + } +} + +#ifdef USE_GLIB +bool SystemStatusOsObserver::connectBackhaul(const string& clientName) +{ + bool result = false; + + if (mContext.mFrameworkActionReqObj != NULL) { + struct HandleConnectBackhaul : public LocMsg { + HandleConnectBackhaul(IFrameworkActionReq* fwkActReq, const string& clientName) : + mClientName(clientName), mFwkActionReqObj(fwkActReq) {} + virtual ~HandleConnectBackhaul() {} + void proc() const { + LOC_LOGi("HandleConnectBackhaul::enter"); + mFwkActionReqObj->connectBackhaul(mClientName); + LOC_LOGi("HandleConnectBackhaul::exit"); + } + IFrameworkActionReq* mFwkActionReqObj; + string mClientName; + }; + mContext.mMsgTask->sendMsg( + new (nothrow) HandleConnectBackhaul(mContext.mFrameworkActionReqObj, clientName)); + result = true; + } + else { + LOC_LOGe("Framework action request object is NULL.Caching connect request: %s", + clientName.c_str()); + ClientBackhaulReqCache::const_iterator iter = mBackHaulConnReqCache.find(clientName); + if (iter == mBackHaulConnReqCache.end()) { + // not found in set. first time receiving from request from client + LOC_LOGe("Adding client to BackHaulConnReqCache list"); + mBackHaulConnReqCache.insert(clientName); + } + result = false; + } + return result; + +} + +bool SystemStatusOsObserver::disconnectBackhaul(const string& clientName) +{ + bool result = false; + + if (mContext.mFrameworkActionReqObj != NULL) { + struct HandleDisconnectBackhaul : public LocMsg { + HandleDisconnectBackhaul(IFrameworkActionReq* fwkActReq, const string& clientName) : + mClientName(clientName), mFwkActionReqObj(fwkActReq) {} + virtual ~HandleDisconnectBackhaul() {} + void proc() const { + LOC_LOGi("HandleDisconnectBackhaul::enter"); + mFwkActionReqObj->disconnectBackhaul(mClientName); + LOC_LOGi("HandleDisconnectBackhaul::exit"); + } + IFrameworkActionReq* mFwkActionReqObj; + string mClientName; + }; + mContext.mMsgTask->sendMsg( + new (nothrow) HandleDisconnectBackhaul(mContext.mFrameworkActionReqObj, + clientName)); + } + else { + LOC_LOGe("Framework action request object is NULL.Caching disconnect request: %s", + clientName.c_str()); + // Check if client has requested for backhaul connection. + ClientBackhaulReqCache::const_iterator iter = mBackHaulConnReqCache.find(clientName); + if (iter != mBackHaulConnReqCache.end()) { + // client found, remove from set. + LOC_LOGd("Removing client from BackHaulConnReqCache list"); + mBackHaulConnReqCache.erase(iter); + } + result = false; + } + return result; +} +#endif +/****************************************************************************** + Helpers +******************************************************************************/ +void SystemStatusOsObserver::sendCachedDataItems( + const unordered_set& s, IDataItemObserver* to) +{ + if (nullptr == to) { + LOC_LOGv("client pointer is NULL."); + } else { + string clientName; + to->getName(clientName); + list dataItems = {}; + + for (auto each : s) { + auto citer = mDataItemCache.find(each); + if (citer != mDataItemCache.end()) { + string dv; + citer->second->stringify(dv); + LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str()); + dataItems.push_front(citer->second); + } + } + + if (dataItems.empty()) { + LOC_LOGv("No items to notify."); + } else { + to->notify(dataItems); + } + } +} + +bool SystemStatusOsObserver::updateCache(IDataItemCore* d) +{ + bool dataItemUpdated = false; + + // Request systemstatus to record this dataitem in its cache + // if the return is false, it means that SystemStatus is not + // handling it, so SystemStatusOsObserver also doesn't. + // So it has to be true to proceed. + if (nullptr != d && mSystemStatus->eventDataItemNotify(d)) { + auto citer = mDataItemCache.find(d->getId()); + if (citer == mDataItemCache.end()) { + // New data item; not found in cache + IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(d->getId()); + if (nullptr != dataitem) { + // Copy the contents of the data item + dataitem->copy(d); + // Insert in mDataItemCache + mDataItemCache.insert(std::make_pair(d->getId(), dataitem)); + dataItemUpdated = true; + } + } else { + // Found in cache; Update cache if necessary + citer->second->copy(d, &dataItemUpdated); + } + + if (dataItemUpdated) { + LOC_LOGV("DataItem:%d updated:%d", d->getId(), dataItemUpdated); + } + } + + return dataItemUpdated; +} + +} // namespace loc_core + diff --git a/gps/core/SystemStatusOsObserver.h b/gps/core/SystemStatusOsObserver.h new file mode 100644 index 0000000..c0f56d8 --- /dev/null +++ b/gps/core/SystemStatusOsObserver.h @@ -0,0 +1,181 @@ +/* Copyright (c) 2015-2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __SYSTEM_STATUS_OSOBSERVER__ +#define __SYSTEM_STATUS_OSOBSERVER__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace loc_core +{ +/****************************************************************************** + SystemStatusOsObserver +******************************************************************************/ +using namespace std; +using namespace loc_util; + +// Forward Declarations +class IDataItemCore; +class SystemStatus; +class SystemStatusOsObserver; +typedef map> ObserverReqCache; +typedef LocUnorderedSetMap ClientToDataItems; +typedef LocUnorderedSetMap DataItemToClients; +typedef unordered_map DataItemIdToCore; +typedef unordered_map DataItemIdToInt; +#ifdef USE_GLIB +// Cache details of backhaul client requests +typedef unordered_set ClientBackhaulReqCache; +#endif + +struct ObserverContext { + IDataItemSubscription* mSubscriptionObj; + IFrameworkActionReq* mFrameworkActionReqObj; + const MsgTask* mMsgTask; + SystemStatusOsObserver* mSSObserver; + + inline ObserverContext(const MsgTask* msgTask, SystemStatusOsObserver* observer) : + mSubscriptionObj(NULL), mFrameworkActionReqObj(NULL), + mMsgTask(msgTask), mSSObserver(observer) {} +}; + +// Clients wanting to get data from OS/Framework would need to +// subscribe with OSObserver using IDataItemSubscription interface. +// Such clients would need to implement IDataItemObserver interface +// to receive data when it becomes available. +class SystemStatusOsObserver : public IOsObserver { + +public: + // ctor + inline SystemStatusOsObserver(SystemStatus* systemstatus, const MsgTask* msgTask) : + mSystemStatus(systemstatus), mContext(msgTask, this), + mAddress("SystemStatusOsObserver"), + mClientToDataItems(MAX_DATA_ITEM_ID), mDataItemToClients(MAX_DATA_ITEM_ID) {} + + // dtor + ~SystemStatusOsObserver(); + + template + static COUT containerTransfer(CINT& s); + template + inline static COUT containerTransfer(CINT&& s) { + return containerTransfer(s); + } + + // To set the subscription object + virtual void setSubscriptionObj(IDataItemSubscription* subscriptionObj); + + // To set the framework action request object + inline void setFrameworkActionReqObj(IFrameworkActionReq* frameworkActionReqObj) { + mContext.mFrameworkActionReqObj = frameworkActionReqObj; +#ifdef USE_GLIB + uint32_t numBackHaulClients = mBackHaulConnReqCache.size(); + if (numBackHaulClients > 0) { + // For each client, invoke connectbackhaul. + for (auto clientName : mBackHaulConnReqCache) { + LOC_LOGd("Invoke connectBackhaul for client: %s", clientName.c_str()); + connectBackhaul(clientName); + } + // Clear the set + mBackHaulConnReqCache.clear(); + } +#endif + } + + // IDataItemSubscription Overrides + inline virtual void subscribe(const list& l, IDataItemObserver* client) override { + subscribe(l, client, false); + } + virtual void updateSubscription(const list& l, IDataItemObserver* client) override; + inline virtual void requestData(const list& l, IDataItemObserver* client) override { + subscribe(l, client, true); + } + virtual void unsubscribe(const list& l, IDataItemObserver* client) override; + virtual void unsubscribeAll(IDataItemObserver* client) override; + + // IDataItemObserver Overrides + virtual void notify(const list& dlist) override; + inline virtual void getName(string& name) override { + name = mAddress; + } + + // IFrameworkActionReq Overrides + virtual void turnOn(DataItemId dit, int timeOut = 0) override; + virtual void turnOff(DataItemId dit) override; +#ifdef USE_GLIB + virtual bool connectBackhaul(const string& clientName) override; + virtual bool disconnectBackhaul(const string& clientName) override; +#endif + +private: + SystemStatus* mSystemStatus; + ObserverContext mContext; + const string mAddress; + ClientToDataItems mClientToDataItems; + DataItemToClients mDataItemToClients; + DataItemIdToCore mDataItemCache; + DataItemIdToInt mActiveRequestCount; + + // Cache the subscribe and requestData till subscription obj is obtained + void cacheObserverRequest(ObserverReqCache& reqCache, + const list& l, IDataItemObserver* client); +#ifdef USE_GLIB + // Cache the framework action request for connect/disconnect + ClientBackhaulReqCache mBackHaulConnReqCache; +#endif + + void subscribe(const list& l, IDataItemObserver* client, bool toRequestData); + + // Helpers + void sendCachedDataItems(const unordered_set& s, IDataItemObserver* to); + bool updateCache(IDataItemCore* d); + inline void logMe(const unordered_set& l) { + IF_LOC_LOGD { + for (auto id : l) { + LOC_LOGD("DataItem %d", id); + } + } + } +}; + +} // namespace loc_core + +#endif //__SYSTEM_STATUS__ + diff --git a/gps/core/configure.ac b/gps/core/configure.ac new file mode 100644 index 0000000..19db9cf --- /dev/null +++ b/gps/core/configure.ac @@ -0,0 +1,107 @@ +# configure.ac -- Autoconf script for gps loc-core +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps loc-hal package version 1.0.0 +AC_INIT([loc-core],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign subdir-objects]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([loc-core.pc.in]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Checks for libraries. +PKG_CHECK_MODULES([GPSUTILS], [gps-utils]) +AC_SUBST([GPSUTILS_CFLAGS]) +AC_SUBST([GPSUTILS_LIBS]) + +AC_ARG_WITH([core_includes], + AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], + [Specify the location of the core headers]), + [core_incdir=$withval], + with_core_includes=no) + +if test "x$with_core_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${core_incdir}" +fi + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x$with_locpla_includes" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_SUBST([CPPFLAGS]) + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_ARG_WITH([auto_feature], + AC_HELP_STRING([--with-auto_feature=@<:@dir@:>@], + [Using Automotive feature]), + [], + with_auto_feature=no) + +if test "x$with_auto_feature" != "xno"; then + CPPFLAGS="${CPPFLAGS} -DFEATURE_AUTOMOTIVE" +fi + +AM_CONDITIONAL(USE_FEATURE_AUTOMOTIVE, test "x${with_auto_feature}" = "xyes") + +# External AP +AC_ARG_WITH([external_ap], + AC_HELP_STRING([--with-external_ap=@<:@dir@:>@], + [Using External Application Processor]), + [], + with_external_ap=no) + +if test "x$with_external_ap" != "xno"; then + CPPFLAGS="${CPPFLAGS} -DFEATURE_EXTERNAL_AP" +fi + +AM_CONDITIONAL(USE_EXTERNAL_AP, test "x${with_external_ap}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + loc-core.pc \ + ]) + +AC_OUTPUT diff --git a/gps/core/data-items/DataItemConcreteTypesBase.h b/gps/core/data-items/DataItemConcreteTypesBase.h new file mode 100644 index 0000000..11a3cce --- /dev/null +++ b/gps/core/data-items/DataItemConcreteTypesBase.h @@ -0,0 +1,555 @@ +/* Copyright (c) 2015-2017, 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __DATAITEMCONCRETEBASETYPES__ +#define __DATAITEMCONCRETEBASETYPES__ + +#include +#include +#include +#include +#include +#include +#include + +#define MAC_ADDRESS_LENGTH 6 +// MAC address length in bytes +// QMI_LOC_SRN_MAC_ADDR_LENGTH_V02 +#define SRN_MAC_ADDRESS_LENGTH 6 +#define WIFI_SUPPLICANT_DEFAULT_STATE 0 + +static constexpr char sDelimit = ':'; + +namespace loc_core +{ +using namespace std; + +enum NetworkType { + TYPE_MOBILE = 0, + TYPE_WIFI, + TYPE_ETHERNET, + TYPE_BLUETOOTH, + TYPE_MMS, + TYPE_SUPL, + TYPE_DUN, + TYPE_HIPRI, + TYPE_WIMAX, + TYPE_PROXY, + TYPE_UNKNOWN, +}; + +typedef struct NetworkInfoType +{ + // Unique network handle ID + uint64_t networkHandle; + // Type of network for corresponding network handle + NetworkType networkType; + NetworkInfoType() : networkHandle(NETWORK_HANDLE_UNKNOWN), networkType(TYPE_UNKNOWN) {} + NetworkInfoType(string strObj) { + size_t posDelimit = strObj.find(sDelimit); + + if ( posDelimit != string::npos) { + int32_t type = TYPE_UNKNOWN; + string handleStr = strObj.substr(0, posDelimit); + string typeStr = strObj.substr(posDelimit + 1, strObj.length() - posDelimit - 1); + stringstream(handleStr) >> networkHandle; + stringstream(typeStr) >> type; + networkType = (NetworkType) type; + } else { + networkHandle = NETWORK_HANDLE_UNKNOWN; + networkType = TYPE_UNKNOWN; + } + } + bool operator== (const NetworkInfoType& other) { + return ((networkHandle == other.networkHandle) && (networkType == other.networkType)); + } + string toString() { + string valueStr; + valueStr.clear (); + char nethandle [32]; + memset (nethandle, 0, 32); + snprintf(nethandle, sizeof(nethandle), "%" PRIu64, networkHandle); + valueStr += string(nethandle); + valueStr += sDelimit; + char type [12]; + memset (type, 0, 12); + snprintf (type, 12, "%u", networkType); + valueStr += string (type); + return valueStr; + } +} NetworkInfoType; + + +class AirplaneModeDataItemBase : public IDataItemCore { +public: + AirplaneModeDataItemBase(bool mode): + mMode(mode), + mId(AIRPLANEMODE_DATA_ITEM_ID) {} + virtual ~AirplaneModeDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mMode; + +protected: + DataItemId mId; +}; + +class ENHDataItemBase : public IDataItemCore { +public: + ENHDataItemBase(bool enabled) : + mEnabled(enabled), + mId(ENH_DATA_ITEM_ID) {} + virtual ~ENHDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mEnabled; +protected: + DataItemId mId; +}; + +class GPSStateDataItemBase : public IDataItemCore { +public: + GPSStateDataItemBase(bool enabled) : + mEnabled(enabled), + mId(GPSSTATE_DATA_ITEM_ID) {} + virtual ~GPSStateDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mEnabled; +protected: + DataItemId mId; +}; + +class NLPStatusDataItemBase : public IDataItemCore { +public: + NLPStatusDataItemBase(bool enabled) : + mEnabled(enabled), + mId(NLPSTATUS_DATA_ITEM_ID) {} + virtual ~NLPStatusDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mEnabled; +protected: + DataItemId mId; +}; + +class WifiHardwareStateDataItemBase : public IDataItemCore { +public: + WifiHardwareStateDataItemBase(bool enabled) : + mEnabled(enabled), + mId(WIFIHARDWARESTATE_DATA_ITEM_ID) {} + virtual ~WifiHardwareStateDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mEnabled; +protected: + DataItemId mId; +}; + +class ScreenStateDataItemBase : public IDataItemCore { +public: + ScreenStateDataItemBase(bool state) : + mState(state), + mId(SCREEN_STATE_DATA_ITEM_ID) {} + virtual ~ScreenStateDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mState; +protected: + DataItemId mId; +}; + +class PowerConnectStateDataItemBase : public IDataItemCore { +public: + PowerConnectStateDataItemBase(bool state) : + mState(state), + mId(POWER_CONNECTED_STATE_DATA_ITEM_ID) {} + virtual ~PowerConnectStateDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mState; +protected: + DataItemId mId; +}; + +class TimeZoneChangeDataItemBase : public IDataItemCore { +public: + TimeZoneChangeDataItemBase(int64_t currTimeMillis, int32_t rawOffset, int32_t dstOffset) : + mCurrTimeMillis (currTimeMillis), + mRawOffsetTZ (rawOffset), + mDstOffsetTZ (dstOffset), + mId(TIMEZONE_CHANGE_DATA_ITEM_ID) {} + virtual ~TimeZoneChangeDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + int64_t mCurrTimeMillis; + int32_t mRawOffsetTZ; + int32_t mDstOffsetTZ; +protected: + DataItemId mId; +}; + +class TimeChangeDataItemBase : public IDataItemCore { +public: + TimeChangeDataItemBase(int64_t currTimeMillis, int32_t rawOffset, int32_t dstOffset) : + mCurrTimeMillis (currTimeMillis), + mRawOffsetTZ (rawOffset), + mDstOffsetTZ (dstOffset), + mId(TIME_CHANGE_DATA_ITEM_ID) {} + virtual ~TimeChangeDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + int64_t mCurrTimeMillis; + int32_t mRawOffsetTZ; + int32_t mDstOffsetTZ; +protected: + DataItemId mId; +}; + +class ShutdownStateDataItemBase : public IDataItemCore { +public: + ShutdownStateDataItemBase(bool state) : + mState (state), + mId(SHUTDOWN_STATE_DATA_ITEM_ID) {} + virtual ~ShutdownStateDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mState; +protected: + DataItemId mId; +}; + +class AssistedGpsDataItemBase : public IDataItemCore { +public: + AssistedGpsDataItemBase(bool enabled) : + mEnabled(enabled), + mId(ASSISTED_GPS_DATA_ITEM_ID) {} + virtual ~AssistedGpsDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} +// Data members + bool mEnabled; +protected: + DataItemId mId; +}; + +class NetworkInfoDataItemBase : public IDataItemCore { +public: + NetworkInfoDataItemBase( + NetworkType initialType, int32_t type, string typeName, string subTypeName, + bool available, bool connected, bool roaming, uint64_t networkHandle, string apn): + mAllTypes(typeToAllTypes(initialType)), + mType(type), + mTypeName(typeName), + mSubTypeName(subTypeName), + mAvailable(available), + mConnected(connected), + mRoaming(roaming), + mNetworkHandle(networkHandle), + mId(NETWORKINFO_DATA_ITEM_ID), mApn(apn) { + mAllNetworkHandles[0].networkHandle = networkHandle; + mAllNetworkHandles[0].networkType = initialType; + } + virtual ~NetworkInfoDataItemBase() {} + inline virtual DataItemId getId() { return mId; } + virtual void stringify(string& /*valueStr*/) {} + virtual int32_t copy(IDataItemCore* /*src*/, bool* /*dataItemCopied = NULL*/) {return 1;} + inline virtual NetworkType getType(void) const { + return (NetworkType)mType; + } + inline uint64_t getAllTypes() { return mAllTypes; } + inline NetworkInfoType* getNetworkHandle() { + return &mAllNetworkHandles[0]; + } + // Data members + uint64_t mAllTypes; + int32_t mType; + string mTypeName; + string mSubTypeName; + bool mAvailable; + bool mConnected; + bool mRoaming; + NetworkInfoType mAllNetworkHandles[MAX_NETWORK_HANDLES]; + uint64_t mNetworkHandle; + string mApn; +protected: + DataItemId mId; + inline uint64_t typeToAllTypes(NetworkType type) { + return (type >= TYPE_UNKNOWN || type < TYPE_MOBILE) ? 0 : (1< +#include +#include +#include +#include +#include +#include "loc_misc_utils.h" + +namespace loc_core +{ +void* DataItemsFactoryProxy::dataItemLibHandle = NULL; +get_concrete_data_item_fn* DataItemsFactoryProxy::getConcreteDIFunc = NULL; + +IDataItemCore* DataItemsFactoryProxy::createNewDataItem(DataItemId id) +{ + IDataItemCore *mydi = nullptr; + + if (NULL != getConcreteDIFunc) { + mydi = (*getConcreteDIFunc)(id); + } + else { + getConcreteDIFunc = (get_concrete_data_item_fn * ) + dlGetSymFromLib(dataItemLibHandle, DATA_ITEMS_LIB_NAME, DATA_ITEMS_GET_CONCRETE_DI); + + if (NULL != getConcreteDIFunc) { + LOC_LOGd("Loaded function %s : %p", DATA_ITEMS_GET_CONCRETE_DI, getConcreteDIFunc); + mydi = (*getConcreteDIFunc)(id); + } + else { + // dlysm failed. + const char * err = dlerror(); + if (NULL == err) + { + err = "Unknown"; + } + LOC_LOGe("failed to find symbol %s; error=%s", DATA_ITEMS_GET_CONCRETE_DI, err); + } + } + return mydi; +} + +void DataItemsFactoryProxy::closeDataItemLibraryHandle() +{ + if (NULL != dataItemLibHandle) { + dlclose(dataItemLibHandle); + dataItemLibHandle = NULL; + } +} + +} // namespace loc_core + + diff --git a/gps/core/data-items/DataItemsFactoryProxy.h b/gps/core/data-items/DataItemsFactoryProxy.h new file mode 100644 index 0000000..cfd447d --- /dev/null +++ b/gps/core/data-items/DataItemsFactoryProxy.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __DATAITEMFACTORYBASE__ +#define __DATAITEMFACTORYBASE__ + +#include +#include + +namespace loc_core +{ + +#define DATA_ITEMS_LIB_NAME "libdataitems.so" +#define DATA_ITEMS_GET_CONCRETE_DI "getConcreteDataItem" + +typedef IDataItemCore * (get_concrete_data_item_fn)(DataItemId); + +class DataItemsFactoryProxy { +public: + static IDataItemCore* createNewDataItem(DataItemId id); + static void closeDataItemLibraryHandle(); + static void *dataItemLibHandle; + static get_concrete_data_item_fn *getConcreteDIFunc; +}; + +} // namespace loc_core + +#endif //__DATAITEMFACTORYBASE__ + diff --git a/gps/core/data-items/IDataItemCore.h b/gps/core/data-items/IDataItemCore.h new file mode 100644 index 0000000..6084c92 --- /dev/null +++ b/gps/core/data-items/IDataItemCore.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IDATAITEMCORE_H__ +#define __IDATAITEMCORE_H__ + +#include +#include + +namespace loc_core { + +using namespace std; + +/** + * @brief IDataItemCore interface. + * @details IDataItemCore interface. + * + */ +class IDataItemCore { +public: + /** + * @brief Gets Data item id. + * @details Gets Data item id. + * @return Data item id. + */ + virtual DataItemId getId () = 0; + + /** + * @brief Stringify. + * @details Stringify. + * + * @param valueStr Reference to string. + */ + virtual void stringify (string & valueStr) = 0; + + /** + * @brief copy. + * @details copy. + * + * @param src Where to copy from. + * @param dataItemCopied Boolean flag indicated whether or not copied. + * + * @return Zero for success or non zero for failure. + */ + virtual int32_t copy (IDataItemCore * src, bool *dataItemCopied = nullptr) = 0; + + /** + * @brief Destructor. + * @details Destructor. + */ + virtual ~IDataItemCore () {} +}; + +} // namespace loc_core + +#endif // __IDATAITEMCORE_H__ diff --git a/gps/core/loc-core.pc.in b/gps/core/loc-core.pc.in new file mode 100644 index 0000000..76b514c --- /dev/null +++ b/gps/core/loc-core.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: loc-core +Description: QTI GPS Loc Core +Version: @VERSION@ +Libs: -L${libdir} -lloc_core +Cflags: -I${includedir}/loc-core diff --git a/gps/core/loc_core_log.cpp b/gps/core/loc_core_log.cpp new file mode 100644 index 0000000..904f94b --- /dev/null +++ b/gps/core/loc_core_log.cpp @@ -0,0 +1,215 @@ +/* Copyright (c) 2011-2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_core_log" + +#include +#include +#include +#include + +void LocPosMode::logv() const +{ + LOC_LOGV ("Position mode: %s\n Position recurrence: %s\n " + "min interval: %d\n preferred accuracy: %d\n " + "preferred time: %d\n credentials: %s provider: %s \n " + "power mode: %d\n tbm %d", + loc_get_position_mode_name(mode), + loc_get_position_recurrence_name(recurrence), + min_interval, + preferred_accuracy, + preferred_time, + credentials, + provider, + powerMode, + timeBetweenMeasurements); +} + +/* GPS status names */ +DECLARE_TBL(gps_status_name) = +{ + NAME_VAL( LOC_GPS_STATUS_NONE ), + NAME_VAL( LOC_GPS_STATUS_SESSION_BEGIN ), + NAME_VAL( LOC_GPS_STATUS_SESSION_END ), + NAME_VAL( LOC_GPS_STATUS_ENGINE_ON ), + NAME_VAL( LOC_GPS_STATUS_ENGINE_OFF ), +}; + +/* Find Android GPS status name */ +const char* loc_get_gps_status_name(LocGpsStatusValue gps_status) +{ + return loc_get_name_from_val(gps_status_name_tbl, (int64_t) gps_status); +} + + + +DECLARE_TBL(loc_eng_position_modes) = +{ + NAME_VAL( LOC_POSITION_MODE_STANDALONE ), + NAME_VAL( LOC_POSITION_MODE_MS_BASED ), + NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_5 ) +}; + +const char* loc_get_position_mode_name(LocGpsPositionMode mode) +{ + return loc_get_name_from_val(loc_eng_position_modes_tbl, (int64_t) mode); +} + + + +DECLARE_TBL(loc_eng_position_recurrences) = +{ + NAME_VAL( LOC_GPS_POSITION_RECURRENCE_PERIODIC ), + NAME_VAL( LOC_GPS_POSITION_RECURRENCE_SINGLE ) +}; + +const char* loc_get_position_recurrence_name(LocGpsPositionRecurrence recur) +{ + return loc_get_name_from_val(loc_eng_position_recurrences_tbl, (int64_t) recur); +} + +const char* loc_get_aiding_data_mask_names(LocGpsAidingData /*data*/) +{ + return NULL; +} + + +DECLARE_TBL(loc_eng_agps_types) = +{ + NAME_VAL( LOC_AGPS_TYPE_INVALID ), + NAME_VAL( LOC_AGPS_TYPE_ANY ), + NAME_VAL( LOC_AGPS_TYPE_SUPL ), + NAME_VAL( LOC_AGPS_TYPE_C2K ), + NAME_VAL( LOC_AGPS_TYPE_WWAN_ANY ) +}; + +const char* loc_get_agps_type_name(LocAGpsType type) +{ + return loc_get_name_from_val(loc_eng_agps_types_tbl, (int64_t) type); +} + + +DECLARE_TBL(loc_eng_ni_types) = +{ + NAME_VAL( LOC_GPS_NI_TYPE_VOICE ), + NAME_VAL( LOC_GPS_NI_TYPE_UMTS_SUPL ), + NAME_VAL( LOC_GPS_NI_TYPE_UMTS_CTRL_PLANE ), + NAME_VAL( LOC_GPS_NI_TYPE_EMERGENCY_SUPL ) +}; + +const char* loc_get_ni_type_name(LocGpsNiType type) +{ + return loc_get_name_from_val(loc_eng_ni_types_tbl, (int64_t) type); +} + + +DECLARE_TBL(loc_eng_ni_responses) = +{ + NAME_VAL( LOC_GPS_NI_RESPONSE_ACCEPT ), + NAME_VAL( LOC_GPS_NI_RESPONSE_DENY ), + NAME_VAL( LOC_GPS_NI_RESPONSE_DENY ) +}; + +const char* loc_get_ni_response_name(LocGpsUserResponseType response) +{ + return loc_get_name_from_val(loc_eng_ni_responses_tbl, (int64_t) response); +} + + +DECLARE_TBL(loc_eng_ni_encodings) = +{ + NAME_VAL( LOC_GPS_ENC_NONE ), + NAME_VAL( LOC_GPS_ENC_SUPL_GSM_DEFAULT ), + NAME_VAL( LOC_GPS_ENC_SUPL_UTF8 ), + NAME_VAL( LOC_GPS_ENC_SUPL_UCS2 ), + NAME_VAL( LOC_GPS_ENC_UNKNOWN ) +}; + +const char* loc_get_ni_encoding_name(LocGpsNiEncodingType encoding) +{ + return loc_get_name_from_val(loc_eng_ni_encodings_tbl, (int64_t) encoding); +} + +DECLARE_TBL(loc_eng_agps_bears) = +{ + NAME_VAL( AGPS_APN_BEARER_INVALID ), + NAME_VAL( AGPS_APN_BEARER_IPV4 ), + NAME_VAL( AGPS_APN_BEARER_IPV6 ), + NAME_VAL( AGPS_APN_BEARER_IPV4V6 ) +}; + +const char* loc_get_agps_bear_name(AGpsBearerType bearer) +{ + return loc_get_name_from_val(loc_eng_agps_bears_tbl, (int64_t) bearer); +} + +DECLARE_TBL(loc_eng_server_types) = +{ + NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ), + NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ), + NAME_VAL( LOC_AGPS_MPC_SERVER ), + NAME_VAL( LOC_AGPS_SUPL_SERVER ) +}; + +const char* loc_get_server_type_name(LocServerType type) +{ + return loc_get_name_from_val(loc_eng_server_types_tbl, (int64_t) type); +} + +DECLARE_TBL(loc_eng_position_sess_status_types) = +{ + NAME_VAL( LOC_SESS_SUCCESS ), + NAME_VAL( LOC_SESS_INTERMEDIATE ), + NAME_VAL( LOC_SESS_FAILURE ) +}; + +const char* loc_get_position_sess_status_name(enum loc_sess_status status) +{ + return loc_get_name_from_val(loc_eng_position_sess_status_types_tbl, (int64_t) status); +} + +DECLARE_TBL(loc_eng_agps_status_names) = +{ + NAME_VAL( LOC_GPS_REQUEST_AGPS_DATA_CONN ), + NAME_VAL( LOC_GPS_RELEASE_AGPS_DATA_CONN ), + NAME_VAL( LOC_GPS_AGPS_DATA_CONNECTED ), + NAME_VAL( LOC_GPS_AGPS_DATA_CONN_DONE ), + NAME_VAL( LOC_GPS_AGPS_DATA_CONN_FAILED ) +}; + +const char* loc_get_agps_status_name(LocAGpsStatusValue status) +{ + return loc_get_name_from_val(loc_eng_agps_status_names_tbl, (int64_t) status); +} diff --git a/gps/core/loc_core_log.h b/gps/core/loc_core_log.h new file mode 100644 index 0000000..2beb687 --- /dev/null +++ b/gps/core/loc_core_log.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2011-2013, 2016-2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_CORE_LOG_H +#define LOC_CORE_LOG_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +const char* loc_get_gps_status_name(LocGpsStatusValue gps_status); +const char* loc_get_position_mode_name(LocGpsPositionMode mode); +const char* loc_get_position_recurrence_name(LocGpsPositionRecurrence recur); +const char* loc_get_aiding_data_mask_names(LocGpsAidingData data); +const char* loc_get_agps_type_name(LocAGpsType type); +const char* loc_get_ni_type_name(LocGpsNiType type); +const char* loc_get_ni_response_name(LocGpsUserResponseType response); +const char* loc_get_ni_encoding_name(LocGpsNiEncodingType encoding); +const char* loc_get_agps_bear_name(AGpsBearerType bear); +const char* loc_get_server_type_name(LocServerType type); +const char* loc_get_position_sess_status_name(enum loc_sess_status status); +const char* loc_get_agps_status_name(LocAGpsStatusValue status); + +#ifdef __cplusplus +} +#endif + +#endif /* LOC_CORE_LOG_H */ diff --git a/gps/core/observer/IDataItemObserver.h b/gps/core/observer/IDataItemObserver.h new file mode 100644 index 0000000..7954d85 --- /dev/null +++ b/gps/core/observer/IDataItemObserver.h @@ -0,0 +1,76 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IDATAITEMOBSERVER_H__ +#define __IDATAITEMOBSERVER_H__ + +#include +#include + +using namespace std; + +namespace loc_core +{ +class IDataItemCore; + +/** + * @brief IDataItemObserver interface + * @details IDataItemObserver interface; + * In OS dependent code this type serves as a handle to an OS independent instance of this interface. + */ +class IDataItemObserver { + +public: + + /** + * @brief Gets name of Data Item Observer + * @details Gets name of Data Item Observer + * + * @param name reference to name of Data Item Observer + */ + virtual void getName (string & name) = 0; + + /** + * @brief Notify updated values of Data Items + * @details Notifys updated values of Data items + * + * @param dlist List of updated data items + */ + virtual void notify (const std :: list & dlist) = 0; + + /** + * @brief Destructor + * @details Destructor + */ + virtual ~IDataItemObserver () {} +}; + +} // namespace loc_core + +#endif // #ifndef __IDATAITEMOBSERVER_H__ diff --git a/gps/core/observer/IDataItemSubscription.h b/gps/core/observer/IDataItemSubscription.h new file mode 100644 index 0000000..7e8b8c8 --- /dev/null +++ b/gps/core/observer/IDataItemSubscription.h @@ -0,0 +1,129 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IDATAITEMSUBSCRIPTION_H__ +#define __IDATAITEMSUBSCRIPTION_H__ + +#include +#include + +namespace loc_core +{ +class IDataItemObserver; + +/** + * @brief IDataItemSubscription interface + * @details IDataItemSubscription interface; + * Defines an interface for operations such as subscribe, + * unsubscribe data items by their IDs. + * Must be implemented by OS dependent code. + */ +class IDataItemSubscription { + +public: + /** + * @brief Subscribe for data items by their IDs + * @details Subscribe for data items by their IDs; + * An IDataItemObserver implementer invokes this method to subscribe + * for a list of DataItems by passing in their Ids. + * A symbolic invocation of this method in the following order + * subscribe ( {1,2,3}, &obj), subscribe ( {2,3,4,5}, &obj) + * where the numbers enclosed in braces indicate a list of data item Ids + * will cause this class implementer to update its subscription list for + * &obj to only contain the following Data Item Ids 1,2,3,4,5. + * + * @param l List of DataItemId + * @param o Pointer to an instance of IDataItemObserver + */ + virtual void subscribe (const std :: list & l, IDataItemObserver * o = NULL) = 0; + + /** + * @brief Update subscription for Data items + * @details Update subscription for Data items; + * An IDataItemObserver implementer invokes this method to update their + * subscription for a list of DataItems by passing in their Ids + * A symbolic invocation of this method in the following order + * updateSubscription ( {1,2,3}, &obj),updateSubscription ( {2,3,4,5}, &obj) + * where the numbers enclosed in braces indicate a list of data item Ids + * will cause this class implementer to update its subscription list for + * &obj to only contain the following Data Item Ids 2,3,4,5. + * Note that this method may or may not be called. + * + * @param l List of DataItemId + * @param o Pointer to an instance of IDataItemObserver + */ + virtual void updateSubscription (const std :: list & l, IDataItemObserver * o = NULL) = 0; + + /** + * @brief Request Data + * @details Request Data + * + * @param l List of DataItemId + * @param o Pointer to an instance of IDataItemObserver + */ + virtual void requestData (const std :: list & l, IDataItemObserver * o = NULL) = 0; + + /** + * @brief Unsubscribe Data items + * @details Unsubscrbe Data items; + * An IDataItemObserver implementer invokes this method to unsubscribe their + * subscription for a list of DataItems by passing in their Ids + * Suppose this class implementor has a currently active subscription list + * containing 1,2,3,4,5,6,7 for &obj then a symbolic invocation of this + * method in the following order + * unsubscribe ( {1,2,3}, &obj), unsubscribe ( {1,2,3,4}, &obj), + * unsubscribe ( {7}, &obj) + * where the numbers enclosed in braces indicate a list of data item Ids + * will cause this class implementer to update its subscription list for + * &obj to only contain the following data item id 5,6. + * + * @param l List of DataItemId + * @param o Pointer to an instance of IDataItemObserver + */ + virtual void unsubscribe (const std :: list & l, IDataItemObserver * o = NULL) = 0; + + /** + * @brief Unsubscribe all data items + * @details Unsubscribe all data items + * + * @param o Pointer to an instance of IDataItemObserver + */ + virtual void unsubscribeAll (IDataItemObserver * o = NULL) = 0; + + /** + * @brief Destructor + * @details Destructor + */ + virtual ~IDataItemSubscription () {} +}; + +} // namespace loc_core + +#endif // #ifndef __IDATAITEMSUBSCRIPTION_H__ + diff --git a/gps/core/observer/IFrameworkActionReq.h b/gps/core/observer/IFrameworkActionReq.h new file mode 100644 index 0000000..138508c --- /dev/null +++ b/gps/core/observer/IFrameworkActionReq.h @@ -0,0 +1,104 @@ +/* Copyright (c) 2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IFRAMEWORKACTIONREQ_H__ +#define __IFRAMEWORKACTIONREQ_H__ + +#include +#include + +using namespace std; + +namespace loc_core +{ + +/** + * @brief IFrameworkActionReq interface + * @details IFrameworkActionReq interface; + * Defines an interface for operations such as turnOn, turnOff a + * framework module described by the data item. Framework module + * could be bluetooth, wifi etc. + * Must be implemented by OS dependent code. + * + */ +class IFrameworkActionReq { + +public: + /** + * @brief Turn on the framework module described by the data item. + * @details Turn on the framework module described by the data item; + * An IFrameworkActionReq implementer invokes this method to + * turn on the framework module described by the data item. + * Framework module could be bluetooth, wifi etc. + * + * @param dit DataItemId + * @param timeout Timeout after which to turn off the framework module. + */ + virtual void turnOn (DataItemId dit, int timeOut = 0) = 0; + + /** + * @brief Turn off the framework module described by the data item. + * @details Turn off the framework module described by the data item; + * An IFrameworkActionReq implementer invokes this method to + * turn off the framework module described by the data item. + * Framework module could be bluetooth, wifi etc. + * + * @param dit DataItemId + */ + virtual void turnOff (DataItemId dit) = 0; + +#ifdef USE_GLIB + /** + * @brief Setup WWAN backhaul + * @details Setup WWAN backhaul + * + * @param None + */ + virtual bool connectBackhaul(const string& clientName) = 0; + + /** + * @brief Disconnects the WWANbackhaul + * @details Disconnects the WWANbackhaul, only if it was setup by us + * + * @param None + */ + virtual bool disconnectBackhaul(const string& clientName) = 0; +#endif + + /** + * @brief Destructor + * @details Destructor + */ + virtual ~IFrameworkActionReq () {} +}; + +} // namespace loc_core + +#endif // #ifndef __IFRAMEWORKACTIONREQ_H__ + diff --git a/gps/core/observer/IOsObserver.h b/gps/core/observer/IOsObserver.h new file mode 100644 index 0000000..a25bb9f --- /dev/null +++ b/gps/core/observer/IOsObserver.h @@ -0,0 +1,107 @@ +/* Copyright (c) 2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IOSOBSERVER_H__ +#define __IOSOBSERVER_H__ + +#include +#include +#include +#include +#include + +using namespace std; + +namespace loc_core +{ + +/** + * @brief IOsObserver interface + * @details IOsObserver interface; + * In OS dependent code this type serves as a handle to + * an OS independent instance of this interface. + */ +class IOsObserver : + public IDataItemObserver, + public IDataItemSubscription, + public IFrameworkActionReq { + +public: + + // To set the subscription object + virtual void setSubscriptionObj(IDataItemSubscription *subscriptionObj) = 0; + + // To set the framework action request object + virtual void setFrameworkActionReqObj(IFrameworkActionReq *frameworkActionReqObj) = 0; + + // IDataItemObserver Overrides + inline virtual void getName (string & /*name*/) {} + inline virtual void notify (const std::list & /*dlist*/) {} + + // IDataItemSubscription Overrides + inline virtual void subscribe + ( + const std :: list & /*l*/, + IDataItemObserver * /*client*/ + ){} + inline virtual void updateSubscription + ( + const std :: list & /*l*/, + IDataItemObserver * /*client*/ + ){} + inline virtual void requestData + ( + const std :: list & /*l*/, + IDataItemObserver * /*client*/ + ){} + inline virtual void unsubscribe + ( + const std :: list & /*l*/, + IDataItemObserver * /*client*/ + ){} + inline virtual void unsubscribeAll (IDataItemObserver * /*client*/){} + + // IFrameworkActionReq Overrides + inline virtual void turnOn (DataItemId /*dit*/, int /*timeOut*/){} + inline virtual void turnOff (DataItemId /*dit*/) {} +#ifdef USE_GLIB + inline virtual bool connectBackhaul(const string& clientName) { return false; } + inline virtual bool disconnectBackhaul(const string& clientName) { return false; } +#endif + + /** + * @brief Destructor + * @details Destructor + */ + virtual ~IOsObserver () {} +}; + +} // namespace loc_core + +#endif // #ifndef __IOSOBSERVER_H__ diff --git a/gps/etc/Android.bp b/gps/etc/Android.bp new file mode 100644 index 0000000..95f2e80 --- /dev/null +++ b/gps/etc/Android.bp @@ -0,0 +1,55 @@ +prebuilt_etc { + name: "apdr.conf", + vendor: true, + src: "apdr.conf", +} + +prebuilt_etc { + name: "flp.conf", + vendor: true, + src: "flp.conf", +} + +prebuilt_etc { + name: "gnss_antenna_info.conf", + vendor: true, + src: "gnss_antenna_info.conf", +} + +prebuilt_etc { + name: "gps.conf", + vendor: true, + src: "gps.conf", +} + +prebuilt_etc { + name: "izat.conf", + vendor: true, + src: "izat.conf", +} + +prebuilt_etc { + name: "lowi.conf", + vendor: true, + src: "lowi.conf", +} + +prebuilt_etc { + name: "sap.conf", + vendor: true, + src: "sap.conf", +} + +prebuilt_etc { + name: "gnss@2.0-base.policy", + vendor: true, + sub_dir: "seccomp_policy", + src: "seccomp_policy/gnss@2.0-base.policy", +} + +prebuilt_etc { + name: "gnss@2.0-xtra-daemon.policy", + vendor: true, + sub_dir: "seccomp_policy", + src: "seccomp_policy/gnss@2.0-xtra-daemon.policy", +} diff --git a/gps/etc/apdr.conf b/gps/etc/apdr.conf new file mode 100644 index 0000000..ea2ec52 --- /dev/null +++ b/gps/etc/apdr.conf @@ -0,0 +1,183 @@ +# AP DR SENSOR Configuration file +# +# SENSOR_SERVICE options are one of below +# accel,gyro,vehicle_accel,vehicle_gyro,pedometer,vehicle_odometry,accel_temp, +# gyro_temp,baro,mag_calib,mag_uncalib,amd,rmd. +# +# SENSOR_PROVIDER options is one of -- default,native,ssc,samlite. +# +# SENSOR_RATE = 1~100 (Hz) +# +# SENSOR_SAMPLES = 1~N +# +# SENSOR_STATISTIC_ENABLED +# bit 0: Diag Print Enabled +# bit 1: Adb Print Enabled +# SENSOR_STATISTIC_PRINT_COUNT +# Skip Number of Print +# +# QDR_DYNAMIC_LOADING = 1~3 +# Configure QDR library to be loaded +# 1: QDR3 +# 2: QDR2-GYRO +# 3: QDR2-DWT +# +# + +###################################### +# # +# QDR3 Configuration # +# # +# For QDR3, # +# comment default configuration above# +# and # +# uncomment below configuration # +# settings. # +# # +###################################### +# +SENSOR_SERVICE = accel +SENSOR_PROVIDER = native +SENSOR_RATE = 10 +SENSOR_SAMPLES = 10 +# +SENSOR_SERVICE = vehicle_speed +SENSOR_PROVIDER = native +SENSOR_RATE = 100 +SENSOR_SAMPLES = 1 +# +SENSOR_SERVICE = gyro +SENSOR_PROVIDER = native +SENSOR_RATE = 10 +SENSOR_SAMPLES = 10 +# +SENSOR_SERVICE = vehicle_gear +SENSOR_PROVIDER = native +SENSOR_RATE = 100 +SENSOR_SAMPLES = 1 +# +SENSOR_SERVICE = accel_temp +SENSOR_PROVIDER = native +SENSOR_RATE = 1 +SENSOR_SAMPLES = 1 +# +# +##Configure QDR library to be loaded 1: QDR3 2: QDR2-GYRO 3: QDR2-DWS +QDR_DYNAMIC_LOADING = 1 +##Specify CAN sensor type: Valid Options: 14(ODO), 2(ODO_DWT), 3(ODO_DWS) +QDR_CAN_TYPE = 14 +##Reporting offset before PPS boundary +QDR_REPORTING_OFFSET = 20 +# + +##Vehicle Sensor Configuration (CAN data availability) +##QDR_VEH_SENSOR_CONFIG: +## 0: VEHICLE_SENSOR_PRESENT - Vehicle Sensor is available (DEFAULT) +## 1: VEHICLE_SENSOR_OPTIONAL - Vehicle Sensor may or may not be present. +#QDR_VEH_SENSOR_CONFIG = 0 + +##Select Wheel set (E.g.: Front two wheels, Rear two wheels OR All four wheels) +##To be used for differential wheel tick OR speed service. +##This configuration is applicable when QDR_CAN_TYPE configured as +##ODO_DWS(3) or ODO_DWT(2). +##Value "0": Use Front two wheels +##Value "1": Use Rear two wheels +##Value "2": Use All four wheels +#QG_DRIVE_WHEEL_FW_RW_AW = 2 +##Max Wheel tick value above which wheel tick rolls over +##This configuration is applicable when QDR_CAN_TYPE configured as ODO_DWT(2) +#QG_DWT_MAX_WHEEL_TICK_COUNT = 255.0 +##Configure Wheel constant for DWT based below equation +##(2 * pi * WHEEL_RADIUS / Pulses Per revolution) +##This configuration is applicable when QDR_CAN_TYPE configured as ODO_DWT(2) +#QG_DWT_WHEEL_CONSTANT = 0.044 +# + +###################################### +# # +# QDR2-DWT Configuration # +# # +# For QDR2-DWT, # +# comment default configuration above# +# and # +# uncomment below configuration # +# settings. # +# # +###################################### +# +#SENSOR_SERVICE = vehicle_speed +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +#SENSOR_STATISTIC_ENABLED = 3 +#SENSOR_STATISTIC_PRINT_COUNT = 50 +# +#SENSOR_SERVICE = vehicle_dws +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +#SENSOR_STATISTIC_ENABLED = 3 +#SENSOR_STATISTIC_PRINT_COUNT = 50 +# +#SENSOR_SERVICE = vehicle_gear +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +#SENSOR_STATISTIC_ENABLED = 3 +#SENSOR_STATISTIC_PRINT_COUNT = 50 +# +#GNSS_POS_STATISTIC_ENABLED = 3 +#GNSS_POS_STATISTIC_PRNTCNT = 10 +#GNSS_MSR_STATISTIC_ENABLED = 3 +#GNSS_MSR_STATISTIC_PRNTCNT = 10 +# +##Configure QDR library to be loaded 1: QDR3 2: QDR2-GYRO 3: QDR2-DWS +#QDR_DYNAMIC_LOADING = 3 +##Enable/disable sensor data flashback feature +#QDR_FLASHBACK_ENABLED = 0 +##Enable/disable sensor data batching feature +#QDR_BATCHING_ENABLED = 0 +##Reporting offset before PPS boundary +#QDR_REPORTING_OFFSET = 20 +##Sensor dispatch threshold declaration +#QDR_SENSDISPATCH_MS = 30 + + +###################################### +# # +# QDR2-GYRO Configuration # +# # +# For QDR2-GYRO, # +# comment default configuration above# +# and # +# uncomment below configuration # +# settings. # +# # +###################################### +# +#SENSOR_SERVICE = vehicle_speed +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +# +#SENSOR_SERVICE = vehicle_gyro +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +# +#SENSOR_SERVICE = vehicle_gear +#SENSOR_PROVIDER = native +#SENSOR_RATE = 100 +#SENSOR_SAMPLES = 1 +# +##Configure QDR library to be loaded 1: QDR3 2: QDR2-GYRO 3: QDR2-DWS +#QDR_DYNAMIC_LOADING = 2 +##Enable/disable sensor data flashback feature +#QDR_FLASHBACK_ENABLED = 0 +##Enable/disable sensor data batching feature +#QDR_BATCHING_ENABLED = 0 +##Reporting offset before PPS boundary +#QDR_REPORTING_OFFSET = 20 +##Sensor dispatch threshold declaration +#QDR_SENSDISPATCH_MS = 30 +# diff --git a/gps/etc/flp.conf b/gps/etc/flp.conf new file mode 100644 index 0000000..65d54d3 --- /dev/null +++ b/gps/etc/flp.conf @@ -0,0 +1,60 @@ +################################### +##### FLP settings ##### +################################### + +################################### +# FLP BATCH SIZE +################################### +# The number of batched locations +# requested to modem. The desired number +# defined below may not be satisfied, as +# the modem can only return the number +# of batched locations that can be allocated, +# which is limited by memory. The default +# batch size defined as 20 as below. +BATCH_SIZE=20 + +################################### +# FLP OUTDOOR TRIP BATCH SIZE +################################### +# The number of batched locations +# requested to modem for outdoor +# trip batching. The desired number +# defined below may not be satisfied, as +# the modem can only return the number +# of batched locations that can be allocated, +# which is limited by memory. The default +# trip batch size defined as 600 as below. +OUTDOOR_TRIP_BATCH_SIZE=600 + +################################### +# FLP BATCHING SESSION TIMEOUT +################################### +# Duration with which batch session timeout +# happens in milliseconds. If not specified +# or set to zero, batching session timeout +# defaults to 20 seconds by the modem. +# BATCH_SESSION_TIMEOUT=20000 + +################################### +# FLP BATCHING ACCURACY +################################### +# Set to one of the defined values below +# to define the accuracy of batching. +# If not specified, accuracy defaults +# to LOW. +# FLP BATCHING ACCURACY values: +# Low accuracy = 0 +# Medium accuracy = 1 +# High accuracy = 2 +ACCURACY=1 + +#################################### +# By default if network fixes are not sensor assisted +# these fixes must be dropped. This parameter adds an exception +# for targets where there is no PDR and we still want to +# report out network fixes +# 0: MUST NOT ALLOW NETWORK FIXES +# 1: ALLOW NETWORK FIXES +#################################### +ALLOW_NETWORK_FIXES = 0 diff --git a/gps/etc/gnss_antenna_info.conf b/gps/etc/gnss_antenna_info.conf new file mode 100644 index 0000000..79a2aef --- /dev/null +++ b/gps/etc/gnss_antenna_info.conf @@ -0,0 +1,134 @@ +################################### +##### ANTENNA INFORMATION ##### +################################### + +################################### +# ANTENNA INFO VECTOR SIZE +################################### +# The number of antenna info +# structures in the vector. Each +# entry in this vector is a structure +# with the following elements: +# +# - CARRIER_FREQUENCY +# - PC_OFFSET +# - PC_VARIATION_CORRECTION +# - PC_VARIATION_CORRECTION_UNC +# - SIGNAL_GAIN_CORRECTION +# - SIGNAL_GAIN_CORRECTION_UNC +# +# Notes: +# CARRIER_FREQUENCY +# The carrier frequency in MHz. +# +# PC = PHASE CENTER +# PC_OFFSET is a structure with six +# elements: x, y, z and their associated uncertainties +# Phase center offset (PCO) is defined with +# respect to the origin of the Android sensor coordinate system, e.g., +# center of primary screen for mobiles +# +# PC_VARIATION_CORRECTION +# 2D vectors representing the phase center variation (PCV) corrections, +# in millimeters, at regularly spaced azimuthal angle (theta) and zenith angle +# (phi). The PCV correction is added to the phase measurement to obtain the +# corrected value. +# The azimuthal angle, theta, is defined with respect to the X axis of the +# Android sensor coordinate system, increasing toward the Y axis. The zenith +# angle, phi, is defined with respect to the Z axis of the Android Sensor +# coordinate system, increasing toward the X-Y plane. +# Each row vector (outer vectors) represents a fixed theta. The first row +# corresponds to a theta angle of 0 degrees. The last row corresponds to a +# theta angle of (360 - deltaTheta) degrees, where deltaTheta is the regular +# spacing between azimuthal angles, i.e., deltaTheta = 360 / (number of rows). +# The columns (inner vectors) represent fixed zenith angles, beginning at 0 +# degrees and ending at 180 degrees. They are separated by deltaPhi, the regular +# spacing between zenith angles, i.e., deltaPhi = 180 / (number of columns - 1). +# +# PC_VARIATION_CORRECTION_UNC +# 2D vectors of 1-sigma uncertainty in millimeters associated with the PCV +# correction values. +# +# SIGNAL_GAIN_CORRECTION +# 2D vectors representing the signal gain corrections at regularly spaced +# azimuthal angle (theta) and zenith angle (phi). The values are calculated or +# measured at the antenna feed point without considering the radio and receiver +# noise figure and path loss contribution, in dBi, i.e., decibel over isotropic +# antenna with the same total power. The signal gain correction is added the +# signal gain measurement to obtain the corrected value. +# The azimuthal angle, theta, is defined with respect to the X axis of the +# Android sensor coordinate system, increasing toward the Y axis. The zenith +# angle, phi, is defined with respect to the Z axis of the Android Sensor +# coordinate system, increasing toward the X-Y plane. +# Each row vector (outer vectors) represents a fixed theta. The first row +# corresponds to a theta angle of 0 degrees. The last row corresponds to a +# theta angle of (360 - deltaTheta) degrees, where deltaTheta is the regular +# spacing between azimuthal angles, i.e., deltaTheta = 360 / (number of rows). +# The columns (inner vectors) represent fixed zenith angles, beginning at 0 +# degrees and ending at 180 degrees. They are separated by deltaPhi, the regular +# spacing between zenith angles, i.e., deltaPhi = 180 / (number of columns - 1). +# +# SIGNAL_GAIN_CORRECTION_UNC +# 2D vectors of 1-sigma uncertainty in dBi associated with the signal +# gain correction values. +# +# The number of rows and columns could be the same for PC variation correction +# and signal gain corrections, or could be different +# If the former then NUMBER_OF_ROWS_ and NUMBER_OF_COLUMNS_ are specified once +# only, if the latter then NUMBER_OF_ROWS_ and NUMBER_OF_COLUMNS_ represent +# the number of rows/columns for PC variation correction and +# NUMBER_OF_ROWS_SGC_ and NUMBER_OF_COLUMNS_SGC_ represent the number of +# rows/columns for signal gain corrections + +ANTENNA_INFO_VECTOR_SIZE = 2 + +CARRIER_FREQUENCY_0 = 1575.42 + +PC_OFFSET_0 = 1.2 0.1 3.4 0.2 5.6 0.3 + +NUMBER_OF_ROWS_0 = 3 +NUMBER_OF_COLUMNS_0 = 4 + +PC_VARIATION_CORRECTION_0_ROW_0 = 11.22 33.44 55.66 77.88 +PC_VARIATION_CORRECTION_0_ROW_1 = 10.2 30.4 50.6 70.8 +PC_VARIATION_CORRECTION_0_ROW_2 = 12.2 34.4 56.6 78.8 + +PC_VARIATION_CORRECTION_UNC_0_ROW_0 = 0.1 0.2 0.3 0.4 +PC_VARIATION_CORRECTION_UNC_0_ROW_1 = 1.1 1.2 1.3 1.4 +PC_VARIATION_CORRECTION_UNC_0_ROW_2 = 2.1 2.2 2.3 2.4 + +SIGNAL_GAIN_CORRECTION_0_ROW_0 = 9.8 8.7 7.6 6.5 +SIGNAL_GAIN_CORRECTION_0_ROW_1 = 5.4 4.3 3.2 2.1 +SIGNAL_GAIN_CORRECTION_0_ROW_2 = 1.3 2.4 3.5 4.6 + +SIGNAL_GAIN_CORRECTION_UNC_0_ROW_0 = 0.11 0.22 0.33 0.44 +SIGNAL_GAIN_CORRECTION_UNC_0_ROW_1 = 0.55 0.66 0.77 0.88 +SIGNAL_GAIN_CORRECTION_UNC_0_ROW_2 = 0.91 0.92 0.93 0.94 + + +CARRIER_FREQUENCY_1 = 1227.6 + +PC_OFFSET_1 = 3.4 0.2 5.6 0.3 1.2 0.1 + +NUMBER_OF_ROWS_1 = 4 +NUMBER_OF_COLUMNS_1 = 2 +NUMBER_OF_ROWS_SGC_1 = 3 +NUMBER_OF_COLUMNS_SGC_1 = 4 + +PC_VARIATION_CORRECTION_1_ROW_0 = 55.66 77.88 +PC_VARIATION_CORRECTION_1_ROW_1 = 11.22 33.44 +PC_VARIATION_CORRECTION_1_ROW_2 = 56.6 78.8 +PC_VARIATION_CORRECTION_1_ROW_3 = 12.2 34.4 + +PC_VARIATION_CORRECTION_UNC_1_ROW_0 = 0.3 0.4 +PC_VARIATION_CORRECTION_UNC_1_ROW_1 = 1.1 1.2 +PC_VARIATION_CORRECTION_UNC_1_ROW_2 = 2.1 2.2 +PC_VARIATION_CORRECTION_UNC_1_ROW_3 = 0.1 0.2 + +SIGNAL_GAIN_CORRECTION_1_ROW_0 = 7.6 6.5 5.4 4.3 +SIGNAL_GAIN_CORRECTION_1_ROW_1 = 1.3 2.4 9.8 8.7 +SIGNAL_GAIN_CORRECTION_1_ROW_2 = 1.4 2.5 3.6 4.7 + +SIGNAL_GAIN_CORRECTION_UNC_1_ROW_0 = 0.91 0.92 0.55 0.66 +SIGNAL_GAIN_CORRECTION_UNC_1_ROW_1 = 0.11 0.22 0.93 0.94 +SIGNAL_GAIN_CORRECTION_UNC_1_ROW_2 = 0.95 0.96 0.33 0.44 diff --git a/gps/etc/gps.conf b/gps/etc/gps.conf new file mode 100644 index 0000000..1bab008 --- /dev/null +++ b/gps/etc/gps.conf @@ -0,0 +1,391 @@ +# Error Estimate +# _SET = 1 +# _CLEAR = 0 +ERR_ESTIMATE=0 + +#NTP server +NTP_SERVER=time.xtracloud.net + +#XTRA CA path +XTRA_CA_PATH=/usr/lib/ssl-1.1/certs + +# DEBUG LEVELS: 0 - none, 1 - Error, 2 - Warning, 3 - Info +# 4 - Debug, 5 - Verbose +# If DEBUG_LEVEL is commented, Android's logging levels will be used +DEBUG_LEVEL = 2 + +# Intermediate position report, 1=enable, 0=disable +INTERMEDIATE_POS=0 + +# supl version 1.0 +SUPL_VER=0x10000 + +# Emergency SUPL, 1=enable, 0=disable +#SUPL_ES=1 + +#Choose PDN for Emergency SUPL +#1 - Use emergency PDN +#0 - Use regular SUPL PDN for Emergency SUPL +#USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL=0 + +#SUPL_MODE is a bit mask set in config.xml per carrier by default. +#If it is uncommented here, this value will overwrite the value from +#config.xml. +#MSA=0X2 +#MSB=0X1 +#SUPL_MODE= + +# GPS Capabilities bit mask +# SCHEDULING = 0x01 +# MSB = 0x02 +# MSA = 0x04 +# ON_DEMAND_TIME = 0x10 +# default = ON_DEMAND_TIME | MSA | MSB | SCHEDULING +CAPABILITIES=0x17 + +# Accuracy threshold for intermediate positions +# less accurate positions are ignored, 0 for passing all positions +# ACCURACY_THRES=5000 + +################################ +##### AGPS server settings ##### +################################ + +# FOR SUPL SUPPORT, set the following +# SUPL_HOST=supl.host.com or IP +# SUPL_PORT=1234 + +# FOR MO SUPL SUPPORT, set the following +# MO_SUPL_HOST=supl.host.com or IP +# MO_SUPL_PORT=1234 + +# FOR C2K PDE SUPPORT, set the following +# C2K_HOST=c2k.pde.com or IP +# C2K_PORT=1234 + +# Bitmask of slots that are available +# for write/install to, where 1s indicate writable, +# and the default value is 0 where no slots +# are writable. For example, AGPS_CERT_WRITABLE_MASK +# of b1000001010 makes 3 slots available +# and the remaining 7 slots unwritable. +#AGPS_CERT_WRITABLE_MASK=0 + +#################################### +# LTE Positioning Profile Settings +#################################### +# LPP_PROFILE is a bit mask +# 0: Enable RRLP on LTE(Default) +# 0x1: LPP User Plane +# 0x2: LPP Control Plane +# 0x4: LPP User Plane for NR5G +# 0x8: LPP Control Plane for NR5G +LPP_PROFILE = 2 + +#################################### +#Datum Type +#################################### +# 0: WGS-84 +# 1: PZ-90 +DATUM_TYPE = 0 + +################################ +# EXTRA SETTINGS +################################ +# NMEA provider (1=Modem Processor, 0=Application Processor) +NMEA_PROVIDER=0 + +################################ +# NMEA TAG BLOCK GROUPING +################################ +# NMEA tag block grouping is only applicable to GSA +# Default is disabled +# 0 - disabled +# 1 - enabled +NMEA_TAG_BLOCK_GROUPING_ENABLED = 0 + +# Customized NMEA GGA fix quality that can be used to tell +# whether SENSOR contributed to the fix. +# +# When this configuration item is not enabled (set to any value that is not 1), +# GGA fix quality conforms to NMEA standard spec as below: +# PPP/DGNSS/SBAS correction fix w/ or w/o sensor: 2 +# RTK fixed fix w/ or w/o sensor: 4 +# RTK float fix w/ or w/o sensor: 5 +# SPE fix w/ or w/o sensor: 1 +# Sensor dead reckoning fix: 6 +# +# When this configuration is enabled (set to 1), GGA fix quality +# will be output as below: +# PPP fix w/o sensor: 59, w/ sensor: 69 +# DGNSS/SBAS correction fix w/o sensor: 2, w/ sensor: 62 +# RTK fixed fix w/o sensor: 4, w/ sensor: 64 +# RTK float fix w/o sensor: 5, w/ sensor: 65, +# SPE fix w/o sensor: 1, and w/ sensor: 61 +# Sensor dead reckoning fix: 6 +# +# any value that is not 1 - disabled +# 1 - enabled +CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED = 0 + +################################ +# NMEA Reporting Rate Config, valid only when NMEA_PROVIDER is set to "0" +################################ +# NMEA Reporting Rate +# Set it to "1HZ" for 1Hz NMEA Reporting +# Set it to "NHZ" for NHz NMEA Reporting +#Default : NHZ (overridden by position update rate if set to lower rates) +NMEA_REPORT_RATE=NHZ + +# Mark if it is a SGLTE target (1=SGLTE, 0=nonSGLTE) +SGLTE_TARGET=0 + +################################################## +# Select Positioning Protocol on A-GLONASS system +################################################## +# 0x1: RRC CPlane +# 0x2: RRLP UPlane +# 0x4: LLP Uplane +A_GLONASS_POS_PROTOCOL_SELECT = 0 + +################################################## +# Select technology for LPPe Control Plane +################################################## +# 0x1: DBH for LPPe CP +# 0x2: WLAN AP Measurements for LPPe CP +# 0x4: SRN AP measurement for CP +# 0x8: Sensor Barometer Measurement LPPe CP +#LPPE_CP_TECHNOLOGY = 0 + +################################################## +# Select technology for LPPe User Plane +################################################## +# 0x1: DBH for LPPe UP +# 0x2: WLAN AP Measurements for LPPe UP +# 0x4: SRN AP measurement for UP +# 0x8: Sensor Barometer Measurement LPPe UP +#LPPE_UP_TECHNOLOGY = 0 + +################################################## +# AGPS_CONFIG_INJECT +################################################## +# enable/disable injection of AGPS configurations: +# SUPL_VER +# SUPL_HOST +# SUPL_PORT +# MO_SUPL_HOST +# MO_SUPL_PORT +# C2K_HOST +# C2K_PORT +# LPP_PROFILE +# A_GLONASS_POS_PROTOCOL_SELECT +# 0: disable +# 1: enable +AGPS_CONFIG_INJECT = 1 + +################################################## +# GNSS settings for automotive use cases +# Configurations in following section are +# specific to automotive use cases, others +# please do not change, keep the default values +################################################## + +# AP Coarse Timestamp Uncertainty +################################################## +# default : 10 +# AP time stamp uncertainty, until GNSS receiver +# is able to acquire better timing information +AP_TIMESTAMP_UNCERTAINTY = 10 + +##################################### +# DR_SYNC Pulse Availability +##################################### +# 0 : DR_SYNC pulse not available (default) +# 1 : DR_SYNC pulse available +# This configuration enables the driver to make use +# of PPS events generated by DR_SYNC pulse +# Standard Linux PPS driver needs to be enabled +DR_SYNC_ENABLED = 0 + +##################################### +# PPS Device name +##################################### +PPS_DEVICENAME = /dev/pps0 + +##################################### +# Ignore PPS at Startup and after long outage +##################################### +IGNORE_PPS_PULSE_COUNT = 1 + +##################################### +# Long GNSS RF outage in seconds +##################################### +GNSS_OUTAGE_DURATION = 10 + +##################################### +# AP Clock Accuracy +##################################### +# Quality of APPS processor clock (in PPM). +# Value specified is used for calculation of +# APPS time stamp uncertainty +AP_CLOCK_PPM = 100 + +##################################### +# MAX ms difference to detect missing pulse +##################################### +# Specifies time threshold in ms to validate any missing PPS pulses +MISSING_PULSE_TIME_DELTA = 900 + +##################################### +# Propagation time uncertainty +##################################### +# This settings enables time uncertainty propagation +# logic incase of missing PPS pulse +PROPAGATION_TIME_UNCERTAINTY = 1 + +####################################### +# APN / IP Type Configuration +# APN and IP Type to use for setting +# up WWAN call. +# Use below values for IP Type: +# v4 = 4 +# v6 = 6 +# v4v6 = 10 +####################################### +# INTERNET_APN = abc.xyz +# INTERNET_IP_TYPE = 4 +# SUPL_APN = abc.xyz +# SUPL_IP_TYPE = 4 + +##################################### +# Modem type +##################################### +# This setting configures modem type +# (external=0 or internal=1) +# comment out the next line to vote +# for the first modem in the list +MODEM_TYPE = 1 + +################################################## +# CONSTRAINED TIME UNCERTAINTY MODE +################################################## +# 0 : disabled (default) +# 1 : enabled +# This setting enables GPS engine to keep its time +# uncertainty below the specified constraint +#CONSTRAINED_TIME_UNCERTAINTY_ENABLED = 0 + +# If constrained time uncertainty mode is enabled, +# this setting specifies the time uncertainty +# threshold that gps engine need to maintain. +# In unit of milli-seconds. +# Default is 0.0 meaning that modem default value +# of time uncertainty threshold will be used. +#CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD = 0.0 + +# If constrained time uncertainty mode is enabled, +# this setting specifies the power budget that +# gps engine is allowed to spend to maintain the time +# uncertainty. +# Default is 0 meaning that GPS engine is not constained +# by power budget and can spend as much power as needed. +# In unit of 0.1 milli watt second. +#CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET = 0 + +################################################## +# POSITION ASSISTED CLOCK ESTIMATOR +################################################## +# 0 : disabled (default) +# 1 : enabled +# This setting enables GPS engine to estimate clock +# bias and drift when the signal from at least 1 +# SV is available and the UE's position is known by +# other position engines. +#POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED = 0 + +##################################### +# proxyAppPackageName +##################################### +# This is a string that is sent to the framework +# in nfwNotifyCb callback +PROXY_APP_PACKAGE_NAME = com.google.android.carrierlocation + +##################################### +# CP_MTLR_ES +##################################### +# CP MTLR ES, 1=enable, 0=disable +CP_MTLR_ES=0 + +################################################## +# GNSS_DEPLOYMENT +################################################## +# 0 : Enable QTI GNSS (default) +# 1 : Enable QCSR SS5 +# 2 : Enable PDS API +# This setting use to select between QTI GNSS, +# QCSR SS5 hardware receiver, and PDS API. +# By default QTI GNSS receiver is enabled. +# GNSS_DEPLOYMENT = 0 + +################################################## +## LOG BUFFER CONFIGURATION +################################################## +#LOG_BUFFER_ENABLED, 1=enable, 0=disable +#*_LEVEL_TIME_DEPTH, maximum time depth of level * +#in log buffer, unit is second +#*_LEVEL_MAX_CAPACITY, maximum numbers of level * +#log print sentences in log buffer +LOG_BUFFER_ENABLED = 0 +E_LEVEL_TIME_DEPTH = 600 +E_LEVEL_MAX_CAPACITY = 50 +W_LEVEL_TIME_DEPTH = 500 +W_LEVEL_MAX_CAPACITY = 100 +I_LEVEL_TIME_DEPTH = 400 +I_LEVEL_MAX_CAPACITY = 200 +D_LEVEL_TIME_DEPTH = 30 +D_LEVEL_MAX_CAPACITY = 300 +V_LEVEL_TIME_DEPTH = 200 +V_LEVEL_MAX_CAPACITY = 400 + +################################################## +# Allow buffer diag log packets when diag memory allocation +# fails during boot up time. +################################################## +BUFFER_DIAG_LOGGING = 1 + +####################################### +# NTRIP CLIENT LIBRARY NAME +####################################### +# NTRIP_CLIENT_LIB_NAME = + +################################################## +# Correction Data Framework settings +# Default values: +# CDFW_SOURCE_PRIORITY_1 = INTERNAL_1 RTCM +# CDFW_INJECT_DATA_INTERVAL = 600000 //10 mins +# CDFW_RTCM_MESSAGE_INTERVAL = 1000 //1 second +# +# If multiple sources coexist on a PL, +# the prorioty sequence can be set by the integer number. +# PRIORITY_1 is higher than PRIORITY_2, for example, +# CDFW_SOURCE_PRIORITY_1 = INTERNAL_1 RTCM +# CDFW_SOURCE_PRIORITY_2 = CV2X RTCM +################################################## + +################################################## +# RF LOSS +# The loss in 0.1 dbHz from the C/N0 at the antenna port +# These values must be configured by OEM if not +# supported in QMI LOC message +# There is one entry for each signal type +################################################## +RF_LOSS_GPS = 0 +RF_LOSS_GPS_L5 = 0 +RF_LOSS_GLO_LEFT = 0 +RF_LOSS_GLO_CENTER = 0 +RF_LOSS_GLO_RIGHT = 0 +RF_LOSS_BDS = 0 +RF_LOSS_BDS_B2A = 0 +RF_LOSS_GAL = 0 +RF_LOSS_GAL_E5 = 0 +RF_LOSS_NAVIC = 0 diff --git a/gps/etc/izat.conf b/gps/etc/izat.conf new file mode 100644 index 0000000..e891154 --- /dev/null +++ b/gps/etc/izat.conf @@ -0,0 +1,277 @@ +######################################### +# Log verbosity control for izat modules +######################################### +# OFF = 0, ERROR = 1, WARNING = 2, INFO = 3, DEBUG = 4, VERBOSE = 5 +IZAT_DEBUG_LEVEL = 2 + +################################################## +# Select WIFI Wait Timeout value in seconds for SUPL +################################################## +WIFI_WAIT_TIMEOUT_SELECT = 0 + +################################################## +# Time interval of injecting SRN scan data to modem +# time in seconds. +# Note: recommended value is between 1-5 sec +################################################## +LPPE_SRN_DATA_SCAN_INJECT_TIME=2 + +################################ +# NLP Settings +################################ +# NLP_MODE 1: OSNLP Only, 2: QNP Only, 3: Combo, 4: QNP preferred +# For Automotive products, please use NLP_MODE = 4 only. +# NLP_TOLERANCE_TIME_FIRST: Time in ms used in Combo mode +# to determine how much Tolerance for first position +# NLP_TOLERANCE_TIME_AFTER: Time in ms used in Combo mode +# to determine how much Tolerance for positions after first +# NLP_THRESHOLD: Sets how many failures needed before +# switching preferred NLP in Combo mode +# NLP_ACCURACY_MULTIPLE: Determines how far off the accuracy +# must be, in multiples, between two NLP location reports to +# be considered much worse accuracy. Used in switching logic +# NLP COMBO MODE USES QNP WITH NO EULA CONSENT: Determines +# whether or not to still send network location requests to +# QNP when the EULA is not consented to by the user. QNP can +# still return ZPP locations or injected locations even +# without EULA consent, but the uncertainty can be high. +# QNP preferred mode prefers QNP when there is EULA consent, +# otherwise OSNLP is used. +NLP_MODE = 1 +NLP_MODE_EMERGENCY = 2 +NLP_TOLERANCE_TIME_FIRST = 5000 +NLP_TOLERANCE_TIME_AFTER = 20000 +NLP_THRESHOLD = 3 +NLP_ACCURACY_MULTIPLE = 2 +NLP_COMBO_MODE_USES_QNP_WITH_NO_EULA_CONSENT = 1 + +######################################### +# NLP PACKAGE SETTINGS +######################################### +# OSNLP_PACKAGE: name of default NLP package +OSNLP_PACKAGE = com.google.android.gms +# REGION_OSNLP_PACKAGE: +# This value will be used as alternative +# for particular region where default NLP is not functional. +#REGION_OSNLP_PACKAGE = + +################################### +# GEOFENCE SERVICES +################################### +# If set to one of the defined values below, it will override +# the responsiveness for geofence services, which implements +# the Proximity Alert API. If not set to a value defined below, +# which is default, it will not override the responsivness. +# The geofence HAL API is unaffected by this value. +# GEOFENCE_SERVICES_RESPONSIVENESS_OVERRIDE Values: +# 1: LOW responsiveness +# 2: MEDIUM responsiveness +# 3: HIGH responsiveness +GEOFENCE_SERVICES_RESPONSIVENESS_OVERRIDE = 0 + +##################################### +#GTP Opt-In app +##################################### + +#GTP privacy policy version url +#https support is required +GTP_PRIVACY_VERSION_URL = https://info.izatcloud.net/privacy/version.html + +#GTP privacy policy version download retry interval +#unit is second. default is 86400 +GTP_PRIVACY_RETRY_INTERVAL = 86400 + +##################################### +# IZAT PREMIUM FEATURE SETTINGS +##################################### +#Possible states of a feature: +#DISABLED +#BASIC +#PREMIUM + +#GTP_MODE valid modes: +# DISABLED +# LEGACY_WWAN +# SDK (WWAN not available for Modems before LocTech 10.0) +# SDK_WIFI (WWAN provided by legacy Modem) +GTP_MODE=DISABLED + +#GTP_WAA valid modes: +# DISABLED +# BASIC +GTP_WAA=DISABLED + +#SAP valid modes: +# DISABLED +# BASIC +# PREMIUM +# PREMIUM_ENV_AIDING +# MODEM_DEFAULT +SAP=PREMIUM + +#FREE_WIFI_SCAN_INJECT valid modes: +#DISABLED +#BASIC +FREE_WIFI_SCAN_INJECT=BASIC + +#SUPL_WIFI valid modes: +#DISABLED +#BASIC +SUPL_WIFI=BASIC + +#WIFI_SUPPLICANT_INFO valid modes: +#DISABLED +#BASIC +WIFI_SUPPLICANT_INFO=BASIC + +##################################### +# Location process launcher settings +##################################### + +# DO NOT MODIFY +# Modifying below attributes without +# caution can have serious implications. + +#Values for PROCESS_STATE: +# ENABLED +# DISABLED + +#Values for LOW_RAM_TARGETS: +# ENABLED +# DISABLED +# Property to enable/disable processes for low ram targets. Uses ro.config.low_ram property +# to identify low ram targets. + +#PROCESS_NAME +# Name of the executable file. + +#FEATURE MASKS: +# GTP-WIFI 0X03 +# GTP-MP-CELL 0xc00 +# GTP-WAA 0x100 +# SAP 0Xc0 +# ODCPI 0x1000 +# FREE_WIFI_SCAN_INJECT 0x2000 +# SUPL_WIFI 0x4000 +# WIFI_SUPPLICANT_INFO 0x8000 + +#Values for PLATFORMS can be: +#1. Any valid values obtained from ro.board.platform separated by single space. For example: msm8960 msm8226 +#2. 'all' or 'all exclude' -> for All platforms +#3. 'all exclude XXXX' -> All platforms exclude XXXX. For example: all exclude msm8937 + +#Values for SOC_IDS can be: +#1. Any valid values obtained from soc_id node separated by single space. For example: 339 386 436 +## soc_id value can be obtained from any one of below node: +## - /sys/devices/soc0/soc_id +## - /sys/devices/system/soc/soc0/id +#2. 'all' or 'all exclude' -> for All soc id's +#3. 'all exclude XXXX' -> All soc id's exclude XXXX. For example: all exclude 339 386 + +#Values for BASEBAND can be: +#1. Any valid values obtained from ro.baseband separated by single space. For example: sglte sglte2 +#2. 'all' or 'all exclude' -> for all basebands +#3. 'all exclude XXXX' -> All basebands exclude XXXX. For example: all exclude sglte +PROCESS_NAME=lowi-server +PROCESS_ARGUMENT= +PROCESS_STATE=DISABLED +PROCESS_GROUPS=gps wifi inet oem_2901 +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0xf303 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=ENABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=0 + +PROCESS_NAME=xtwifi-inet-agent +PROCESS_ARGUMENT= +PROCESS_STATE=DISABLED +PROCESS_GROUPS=inet gps +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0xc03 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=ENABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=1 + +PROCESS_NAME=xtwifi-client +PROCESS_ARGUMENT= +PROCESS_STATE=DISABLED +PROCESS_GROUPS=wifi inet gps system oem_2904 +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0xd03 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=ENABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=1 + +PROCESS_NAME=slim_daemon +PROCESS_ARGUMENT= +PROCESS_STATE=ENABLED +PROCESS_GROUPS=gps oem_2901 can plugdev diag sensors +PREMIUM_FEATURE=1 +IZAT_FEATURE_MASK=0xf0 +PLATFORMS=all +SOC_IDS=all exclude 386 436 +BASEBAND=all +LOW_RAM_TARGETS=DISABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=1 + +PROCESS_NAME=xtra-daemon +PROCESS_ARGUMENT= +PROCESS_STATE=ENABLED +PROCESS_GROUPS=inet gps system +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=ENABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=0 + +######################################## +# Engine Service which host DRE module # +# To enable DRE engine service, change # +# PROCESS_STATE=ENABLED # +######################################## +PROCESS_NAME=engine-service +PROCESS_ARGUMENT=DRE-INT libloc_epDr.so +PROCESS_STATE=DISABLED +PROCESS_GROUPS=gps diag inet qwes oem_2901 system +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=DISABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=1 + +######################################## +# Engine Service which host PPE module # +# To enable PPE engine service, change # +# PROCESS_STATE=ENABLED # +# and update process arugements # +# with PPE library name # +#PROCESS_ARGUMENT=PPE libepsimulator.so# +######################################## +PROCESS_NAME=engine-service +PROCESS_ARGUMENT=PPE libepsimulator.so +PROCESS_STATE=DISABLED +PROCESS_GROUPS=gps diag inet qwes oem_2901 system +PREMIUM_FEATURE=0 +IZAT_FEATURE_MASK=0 +PLATFORMS=all +SOC_IDS=all +BASEBAND=all +LOW_RAM_TARGETS=DISABLED +HARDWARE_TYPE=all +VENDOR_ENHANCED_PROCESS=1 diff --git a/gps/etc/lowi.conf b/gps/etc/lowi.conf new file mode 100644 index 0000000..ff7611d --- /dev/null +++ b/gps/etc/lowi.conf @@ -0,0 +1,26 @@ +#*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====* +# +# LOWI Config file - default +# +# GENERAL DESCRIPTION +# This file contains the config params for LOWI +# +# Copyright (c) 2019 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +# +# 2012-2013 Qualcomm Atheros, Inc. +# All Rights Reserved. +# Qualcomm Atheros Confidential and Proprietary. +# +# Export of this technology or software is regulated by the U.S. Government. +# Diversion contrary to U.S. law prohibited. +#=============================================================================*/ + +# X86 ONLY - UBUNTU: +# Copy this file in the same directory where the executable is + +# Log level +# EL_LOG_OFF = 0, EL_ERROR = 1, EL_WARNING = 2, EL_INFO = 3, EL_DEBUG = 4, EL_VERBOSE = 5, EL_LOG_ALL = 100 +LOWI_LOG_LEVEL = 4 +LOWI_USE_LOWI_LP = 0 diff --git a/gps/etc/sap.conf b/gps/etc/sap.conf new file mode 100644 index 0000000..ce1d088 --- /dev/null +++ b/gps/etc/sap.conf @@ -0,0 +1,181 @@ +################################ +# Sensor Settings +################################ +#The following parameters are optional. +#Internal defaults support MEMS sensors +#native to most handset devices. +#Device specific sensor characterization +#for improved performance is possible as +#described in SAP application notes. +#GYRO_BIAS_RANDOM_WALK= +#ACCEL_RANDOM_WALK_SPECTRAL_DENSITY= +#ANGLE_RANDOM_WALK_SPECTRAL_DENSITY= +#RATE_RANDOM_WALK_SPECTRAL_DENSITY= +#VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY= + +# DEBUG LEVELS: 0 - none, 1 - Error, 2 - Warning, 3 - Info +# 4 - Debug, 5 - Verbose +# If DEBUG_LEVEL is commented, Android's logging levels will be used +DEBUG_LEVEL = 0 +# Sensor Sampling Rate Parameters for Low-Data Rate Filter (should be greater than 0) +# used in loc_eng_reinit +SENSOR_ACCEL_BATCHES_PER_SEC=2 +SENSOR_ACCEL_SAMPLES_PER_BATCH=5 +SENSOR_GYRO_BATCHES_PER_SEC=2 +SENSOR_GYRO_SAMPLES_PER_BATCH=5 +# Sensor Sampling Rate Parameters for High-Data Rate Filter (should be greater than 0) +SENSOR_ACCEL_BATCHES_PER_SEC_HIGH=4 +SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH=25 +SENSOR_GYRO_BATCHES_PER_SEC_HIGH=4 +SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH=25 + +# Sensor Control Mode (0=AUTO, 1=FORCE_ON, 2=MODEM_DEFAULT) +# used in loc_eng_reinit +SENSOR_CONTROL_MODE=1 +SENSOR_USAGE= 0 +SENSOR_PROVIDER= 1 + +# Bit mask used to define which sensor algorithms are used. +# Setting each bit has the following definition: +# 0x1 - DISABLE_INS_POSITIONING_FILTER +# 0x0 - ENABLE_INS_POSITIONING_FILTER +SENSOR_ALGORITHM_CONFIG_MASK=0x0 + +#Vehicle Network Provider configuration + +#Service configuration strings +#The number before colon in VN_X items defines version of the format of the rest of the string +#VN_ACCEL_CFG=0:5 +#VN_GYRO_CFG=0:5.5 +#VN_ODOMETRY_CFG=0:2,4.5 + +################################################ +# QDR3 configurations # +################################################ +#VN_SPEED_CFG=1:131,5,8,1,2,3,1,1,9,2,14,2 +#VN_GEAR_CFG=1:422,20,4,0,4,1,9,0,1,2,3,4,5,6,7,8 +VN_SPEED_CFG=1:777,0,0,1,3,1,0.002778,0,40,8,32,8 +VN_GEAR_CFG=1:422,20,4,0,4,1,9,0,1,2,3,4,5,6,7,8 + +################################################ +# QDR2-Gyro configurations # +################################################ +#VN_GYRO_CFG=1:555,0,1,0,0,0,0,-6.5,6.6066,-6.5,-1.00,2,6.607,6.6068,0,0,16,0.0002,0,16,0.0002,0,16,0.0002 +#VN_SPEED_CFG=1:555,0,0,1,2,1,0.01,0,56,8,48,8 +#VN_GEAR_CFG=1:555,16,4,0,1,1,9,0,1,2,3,4,5,6,7,8 + +################################################ +# QDR2-DWT configurations # +################################################ +#VN_SPEED_CFG=1:555,22,1,2,1,1,1,0,8,8,23,1,2,0,1,0,8,8,23,1 +#VN_GEAR_CFG=1:555,12,4,16,14,16,8,1,2,3,4,5,6,7,8 +#VN_DWS_CFG=1:555,0,0,1,3,1,1,0,0,8,0,0,8,8,0,0,16,8,0,0,24,8,0,0 +#VN_GYRO_CFG=1:555,40,16,1.0,40,16,1.0,40,16,1.0 + +##################################################################################### +# VNW service batching configuration strings # +# VNW provider will initialize default type as Time based batching # +# Each service batch value is configured to be 100 # +# VN_ACCEL_CFG_BATCH_VALUE will be treated as time in Ms if VN_CFG_BATCH_TYPE # +# is set to time based batching # +# VN_ACCEL_CFG_BATCH_VALUE will be treated as sample count if VN_CFG_BATCH_TYPE # +# is set to count based batching # +# Uncomment and update batch time /sample count as per selected batching type # +##################################################################################### +# Batching type +# 1 - Time based (default) +# 2 - Count based +VN_CFG_BATCH_TYPE=1 + +#Vehicle Accel batching value, it can either accept time in milli seconds or sample count +#VN_ACCEL_CFG_BATCH_VALUE=100 + +#Vehicle Gyro batching value, it can either accept time in milli seconds or sample count +VN_GYRO_CFG_BATCH_VALUE=50 + +#Vehicle Odo batching value, it can either accept time in milli seconds or sample count +#VN_ODOMETRY_CFG_BATCH_VALUE=100 + +#Vehicle Speed batching value, it can either accept time in milli seconds or sample count +VN_SPEED_CFG_BATCH_VALUE=50 + +#Vehicle Gear batching value, it can either accept time in milli seconds or sample count +VN_GEAR_CFG_BATCH_VALUE=50 + +#Vehicle DWS batching value, it can either accept time in milli seconds or sample count +#VN_DWS_CFG_BATCH_VALUE=100 +#################################################################################### + +#Procesors clock ratio: AP and CAN bus microcontroller +################################################ +# QDR3 configurations # +################################################ +VN_PROC_CLOCK_RATIO=1.0 + +################################################ +# QDR2-DWT OR QDR2-Gyro configurations # +################################################ +#VN_PROC_CLOCK_RATIO = 1.0 + +# Time source used by Sensor HAL +# Setting this value controls accuracy of location sensor services. +# 0 - Unknown +# 1 - CLOCK_BOOTTIME +# 2 - CLOCK_MONOTONIC +# 3 - CLOCK_REALTIME +# 4 - CLOCK_BOOTTIME using Alarm timer interface +NDK_PROVIDER_TIME_SOURCE=1 + +# Sensor Batching Configuration +# 0 - Time based +# 1 - Fixed count based +# 2 - Variable count based +COUNT_BASED_BATCHING=1 +SYNC_ONCE=0 + +# Vehicle Network Data optimization +# Default value: 0 +# Value 0x40000 - Speed(bit 18 eSLIM_SERVICE_VEHICLE_SPEED) +# Value 0x80000 - Speed(bit 19 eSLIM_SERVICE_VEHICLE_DWS) +# Value 0x100000 - Speed(bit 20 eSLIM_SERVICE_VEHICLE_GEAR) +VN_ENABLE_DATA_OPTIMIZATION=0x100000 + +# Vehicle Network Data Routing time interval +# This is applicable only if VN_ENABLE_DATA_OPTIMIZATION value is set +# Default value: 5000 msec +VN_DATA_ROUTING_TIME_INTERVAL_MSEC=3000 + +#Sensor HAL Provider Configuration HAL Library name including path +################################################ +# # +# Configuration for BMI 160 Sensor # +# # +################################################ +#SENSOR_TYPE=2 +#SENSOR_HAL_LIB_PATH=/usr/lib/libbmi160sensors.so.1 + +################################################ +# # +# Configuration for ASM330 Sensor # +# # +################################################ +SENSOR_TYPE=1 +SENSOR_HAL_LIB_PATH=/usr/lib/libasm330sensors.so.1 + + +################################################ +# # +# Configuration for IAM20680 Sensor # +# # +################################################ +#SENSOR_TYPE=3 +#SENSOR_HAL_LIB_PATH=/usr/lib/libiam20680sensors.so.1 + + +################################################ +# # +# Configuration for SMI130 Sensor # +# # +################################################ +#SENSOR_TYPE=4 +#SENSOR_HAL_LIB_PATH=/usr/lib/libsmi130sensors.so.1 diff --git a/gps/etc/seccomp_policy/gnss@2.0-base.policy b/gps/etc/seccomp_policy/gnss@2.0-base.policy new file mode 100644 index 0000000..7b93037 --- /dev/null +++ b/gps/etc/seccomp_policy/gnss@2.0-base.policy @@ -0,0 +1,95 @@ +#******************************************************************************* +# Copyright (c) 2020 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation, nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#****************************************************************************** + +clone: 1 +close: 1 +connect: 1 +execve: 1 +exit_group: 1 +exit: 1 +faccessat: 1 +fcntl: 1 +fstat: 1 +fstatfs: 1 +futex: 1 +getpid: 1 +getuid: 1 +getgid: 1 +getegid: 1 +getgroups: 1 +geteuid: 1 +umask: 1 +getrandom: 1 +mmap: arg2 in ~PROT_EXEC || arg2 in ~PROT_WRITE +mprotect: arg2 in ~PROT_EXEC || arg2 in ~PROT_WRITE +mremap: 1 +munmap: 1 +newfstatat: 1 +openat: 1 +#prctl: arg0 == PR_SET_VMA || arg0 == PR_SET_NO_NEW_PRIVS || arg0 == PR_GET_DUMPABLE || arg0 == PR_SET_SECCOMP || arg0 == 0x37 /* PR_??? */ +prctl: 1 +pread64: 1 +read: 1 +pwrite64: 1 +write: 1 +writev: 1 +readlinkat: 1 +restart_syscall: 1 +rt_sigaction: 1 +rt_sigprocmask: 1 +rt_sigreturn: 1 +sched_getscheduler: 1 +set_tid_address: 1 +sigaltstack: 1 +unlinkat: 1 +lseek: 1 +##ioctl: arg1 == _IOC(_IOC_NONE || arg1 == _IOC(_IOC_READ || arg1 == VSOC_MAYBE_SEND_INTERRUPT_TO_HOST +ioctl: 1 +clock_gettime: 1 + + +socket: arg0 == AF_INET6 || arg0 == AF_UNIX || arg0 == AF_QIPCRTR +connect: 1 +setsockopt: 1 +getsockname: 1 +socketpair: 1 +ppoll: 1 +pselect6: 1 +accept4: 1 +listen: 1 +bind: 1 +pipe2: 1 + +recvmsg: 1 +sendmsg: 1 + +sendto: 1 +recvfrom: 1 + diff --git a/gps/etc/seccomp_policy/gnss@2.0-xtra-daemon.policy b/gps/etc/seccomp_policy/gnss@2.0-xtra-daemon.policy new file mode 100644 index 0000000..19b67bb --- /dev/null +++ b/gps/etc/seccomp_policy/gnss@2.0-xtra-daemon.policy @@ -0,0 +1,48 @@ +#******************************************************************************* +# Copyright (c) 2020 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation, nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#****************************************************************************** +bind: 1 +getrlimit: 1 + +pipe2: 1 + +sched_getaffinity: 1 +timerfd_create: 1 +unlinkat: 1 +setpriority: 1 + +epoll_create1: 1 +epoll_ctl: 1 +epoll_pwait: 1 +timerfd_settime: 1 + +fdatasync: 1 +madvise: 1 +ftruncate: 1 + diff --git a/gps/geofence/Android.bp b/gps/geofence/Android.bp new file mode 100644 index 0000000..4801eb8 --- /dev/null +++ b/gps/geofence/Android.bp @@ -0,0 +1,31 @@ + + +cc_library_shared { + + name: "libgeofencing", + vendor: true, + + sanitize: GNSS_SANITIZE, + + srcs: [ + "GeofenceAdapter.cpp", + "location_geofence.cpp", + ], + + shared_libs: [ + "libutils", + "libcutils", + "libgps.utils", + "liblog", + "libloc_core", + ], + + header_libs: [ + "libgps.utils_headers", + "libloc_core_headers", + "libloc_pla_headers", + "liblocation_api_headers", + ], + + cflags: GNSS_CFLAGS, +} diff --git a/gps/geofence/GeofenceAdapter.cpp b/gps/geofence/GeofenceAdapter.cpp new file mode 100644 index 0000000..f024e3f --- /dev/null +++ b/gps/geofence/GeofenceAdapter.cpp @@ -0,0 +1,866 @@ +/* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "LocSvc_GeofenceAdapter" + +#include +#include "loc_log.h" +#include +#include + +using namespace loc_core; + +GeofenceAdapter::GeofenceAdapter() : + LocAdapterBase(0, + LocContext::getLocContext(LocContext::mLocationHalName), + true /*isMaster*/) +{ + LOC_LOGD("%s]: Constructor", __func__); +} + +void +GeofenceAdapter::stopClientSessions(LocationAPI* client) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + + for (auto it = mGeofenceIds.begin(); it != mGeofenceIds.end();) { + uint32_t hwId = it->second; + GeofenceKey key(it->first); + if (client == key.client) { + it = mGeofenceIds.erase(it); + mLocApi->removeGeofence(hwId, key.id, + new LocApiResponse(*getContext(), + [this, hwId] (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + auto it2 = mGeofences.find(hwId); + if (it2 != mGeofences.end()) { + mGeofences.erase(it2); + } else { + LOC_LOGE("%s]:geofence item to erase not found. hwId %u", __func__, hwId); + } + } + })); + continue; + } + ++it; // increment only when not erasing an iterator + } + +} + +void +GeofenceAdapter::updateClientsEventMask() +{ + LOC_API_ADAPTER_EVENT_MASK_T mask = 0; + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (it->second.geofenceBreachCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_BATCHED_GENFENCE_BREACH_REPORT; + mask |= LOC_API_ADAPTER_BIT_REPORT_GENFENCE_DWELL; + } + if (it->second.geofenceStatusCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT; + } + } + updateEvtMask(mask, LOC_REGISTRATION_MASK_SET); +} + +LocationError +GeofenceAdapter::getHwIdFromClient(LocationAPI* client, uint32_t clientId, uint32_t& hwId) +{ + GeofenceKey key(client, clientId); + auto it = mGeofenceIds.find(key); + if (it != mGeofenceIds.end()) { + hwId = it->second; + return LOCATION_ERROR_SUCCESS; + } + return LOCATION_ERROR_ID_UNKNOWN; +} + +LocationError +GeofenceAdapter::getGeofenceKeyFromHwId(uint32_t hwId, GeofenceKey& key) +{ + auto it = mGeofences.find(hwId); + if (it != mGeofences.end()) { + key = it->second.key; + return LOCATION_ERROR_SUCCESS; + } + return LOCATION_ERROR_ID_UNKNOWN; +} + +void +GeofenceAdapter::handleEngineUpEvent() +{ + struct MsgSSREvent : public LocMsg { + GeofenceAdapter& mAdapter; + inline MsgSSREvent(GeofenceAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + virtual void proc() const { + mAdapter.setEngineCapabilitiesKnown(true); + mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); + mAdapter.restartGeofences(); + for (auto msg: mAdapter.mPendingMsgs) { + mAdapter.sendMsg(msg); + } + mAdapter.mPendingMsgs.clear(); + } + }; + + sendMsg(new MsgSSREvent(*this)); +} + +void +GeofenceAdapter::restartGeofences() +{ + if (mGeofences.empty()) { + return; + } + + GeofencesMap oldGeofences(mGeofences); + mGeofences.clear(); + mGeofenceIds.clear(); + + for (auto it = oldGeofences.begin(); it != oldGeofences.end(); it++) { + GeofenceObject object = it->second; + GeofenceOption options = {sizeof(GeofenceOption), + object.breachMask, + object.responsiveness, + object.dwellTime}; + GeofenceInfo info = {sizeof(GeofenceInfo), + object.latitude, + object.longitude, + object.radius}; + mLocApi->addGeofence(object.key.id, + options, + info, + new LocApiResponseData(*getContext(), + [this, object, options, info] (LocationError err, LocApiGeofenceData data) { + if (LOCATION_ERROR_SUCCESS == err) { + if (true == object.paused) { + mLocApi->pauseGeofence(data.hwId, object.key.id, + new LocApiResponse(*getContext(), [] (LocationError err ) {})); + } + saveGeofenceItem(object.key.client, object.key.id, data.hwId, options, info); + } + })); + } +} + +void +GeofenceAdapter::reportResponse(LocationAPI* client, size_t count, LocationError* errs, + uint32_t* ids) +{ + IF_LOC_LOGD { + std::string idsString = "["; + std::string errsString = "["; + if (NULL != ids && NULL != errs) { + for (size_t i=0; i < count; ++i) { + idsString += std::to_string(ids[i]) + " "; + errsString += std::to_string(errs[i]) + " "; + } + } + idsString += "]"; + errsString += "]"; + + LOC_LOGD("%s]: client %p ids %s errs %s", + __func__, client, idsString.c_str(), errsString.c_str()); + } + + auto it = mClientData.find(client); + if (it != mClientData.end() && it->second.collectiveResponseCb != nullptr) { + it->second.collectiveResponseCb(count, errs, ids); + } else { + LOC_LOGE("%s]: client %p response not found in info", __func__, client); + } +} + +uint32_t* +GeofenceAdapter::addGeofencesCommand(LocationAPI* client, size_t count, GeofenceOption* options, + GeofenceInfo* infos) +{ + LOC_LOGD("%s]: client %p count %zu", __func__, client, count); + + struct MsgAddGeofences : public LocMsg { + GeofenceAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + size_t mCount; + uint32_t* mIds; + GeofenceOption* mOptions; + GeofenceInfo* mInfos; + inline MsgAddGeofences(GeofenceAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + size_t count, + uint32_t* ids, + GeofenceOption* options, + GeofenceInfo* infos) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mCount(count), + mIds(ids), + mOptions(options), + mInfos(infos) {} + inline virtual void proc() const { + LocationError* errs = new LocationError[mCount]; + if (nullptr == errs) { + LOC_LOGE("%s]: new failed to allocate errs", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + if (NULL == mIds || NULL == mOptions || NULL == mInfos) { + errs[i] = LOCATION_ERROR_INVALID_PARAMETER; + } else { + mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, + mOptions = mOptions, mInfos = mInfos, mIds = mIds, &mApi = mApi, + errs, i] (LocationError err ) { + mApi.addGeofence(mIds[i], mOptions[i], mInfos[i], + new LocApiResponseData(*mAdapter.getContext(), + [&mAdapter = mAdapter, mOptions = mOptions, mClient = mClient, + mCount = mCount, mIds = mIds, mInfos = mInfos, errs, i] + (LocationError err, LocApiGeofenceData data) { + if (LOCATION_ERROR_SUCCESS == err) { + mAdapter.saveGeofenceItem(mClient, + mIds[i], + data.hwId, + mOptions[i], + mInfos[i]); + } + errs[i] = err; + + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + delete[] mOptions; + delete[] mInfos; + } + })); + })); + } + } + } + }; + + if (0 == count) { + return NULL; + } + uint32_t* ids = new uint32_t[count]; + if (nullptr == ids) { + LOC_LOGE("%s]: new failed to allocate ids", __func__); + return NULL; + } + if (NULL != ids) { + for (size_t i=0; i < count; ++i) { + ids[i] = generateSessionId(); + } + } + GeofenceOption* optionsCopy; + if (options == NULL) { + optionsCopy = NULL; + } else { + optionsCopy = new GeofenceOption[count]; + if (nullptr == optionsCopy) { + LOC_LOGE("%s]: new failed to allocate optionsCopy", __func__); + return NULL; + } + COPY_IF_NOT_NULL(optionsCopy, options, count); + } + GeofenceInfo* infosCopy; + if (infos == NULL) { + infosCopy = NULL; + } else { + infosCopy = new GeofenceInfo[count]; + if (nullptr == infosCopy) { + LOC_LOGE("%s]: new failed to allocate infosCopy", __func__); + return NULL; + } + COPY_IF_NOT_NULL(infosCopy, infos, count); + } + + sendMsg(new MsgAddGeofences(*this, *mLocApi, client, count, ids, optionsCopy, infosCopy)); + return ids; +} + +void +GeofenceAdapter::removeGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids) +{ + LOC_LOGD("%s]: client %p count %zu", __func__, client, count); + + struct MsgRemoveGeofences : public LocMsg { + GeofenceAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + size_t mCount; + uint32_t* mIds; + inline MsgRemoveGeofences(GeofenceAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + size_t count, + uint32_t* ids) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mCount(count), + mIds(ids) {} + inline virtual void proc() const { + LocationError* errs = new LocationError[mCount]; + if (nullptr == errs) { + LOC_LOGE("%s]: new failed to allocate errs", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + &mApi = mApi, errs, i] (LocationError err ) { + uint32_t hwId = 0; + errs[i] = mAdapter.getHwIdFromClient(mClient, mIds[i], hwId); + if (LOCATION_ERROR_SUCCESS == errs[i]) { + mApi.removeGeofence(hwId, mIds[i], + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + hwId, errs, i] (LocationError err ) { + if (LOCATION_ERROR_SUCCESS == err) { + mAdapter.removeGeofenceItem(hwId); + } + errs[i] = err; + + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + })); + } else { + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + } + })); + } + } + }; + + if (0 == count) { + return; + } + uint32_t* idsCopy = new uint32_t[count]; + if (nullptr == idsCopy) { + LOC_LOGE("%s]: new failed to allocate idsCopy", __func__); + return; + } + COPY_IF_NOT_NULL(idsCopy, ids, count); + sendMsg(new MsgRemoveGeofences(*this, *mLocApi, client, count, idsCopy)); +} + +void +GeofenceAdapter::pauseGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids) +{ + LOC_LOGD("%s]: client %p count %zu", __func__, client, count); + + struct MsgPauseGeofences : public LocMsg { + GeofenceAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + size_t mCount; + uint32_t* mIds; + inline MsgPauseGeofences(GeofenceAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + size_t count, + uint32_t* ids) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mCount(count), + mIds(ids) {} + inline virtual void proc() const { + LocationError* errs = new LocationError[mCount]; + if (nullptr == errs) { + LOC_LOGE("%s]: new failed to allocate errs", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + &mApi = mApi, errs, i] (LocationError err ) { + uint32_t hwId = 0; + errs[i] = mAdapter.getHwIdFromClient(mClient, mIds[i], hwId); + if (LOCATION_ERROR_SUCCESS == errs[i]) { + mApi.pauseGeofence(hwId, mIds[i], new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + hwId, errs, i] (LocationError err ) { + if (LOCATION_ERROR_SUCCESS == err) { + mAdapter.pauseGeofenceItem(hwId); + } + errs[i] = err; + + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + })); + } else { + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + } + })); + } + } + }; + + if (0 == count) { + return; + } + uint32_t* idsCopy = new uint32_t[count]; + if (nullptr == idsCopy) { + LOC_LOGE("%s]: new failed to allocate idsCopy", __func__); + return; + } + COPY_IF_NOT_NULL(idsCopy, ids, count); + sendMsg(new MsgPauseGeofences(*this, *mLocApi, client, count, idsCopy)); +} + +void +GeofenceAdapter::resumeGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids) +{ + LOC_LOGD("%s]: client %p count %zu", __func__, client, count); + + struct MsgResumeGeofences : public LocMsg { + GeofenceAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + size_t mCount; + uint32_t* mIds; + inline MsgResumeGeofences(GeofenceAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + size_t count, + uint32_t* ids) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mCount(count), + mIds(ids) {} + inline virtual void proc() const { + LocationError* errs = new LocationError[mCount]; + if (nullptr == errs) { + LOC_LOGE("%s]: new failed to allocate errs", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + &mApi = mApi, errs, i] (LocationError err ) { + uint32_t hwId = 0; + errs[i] = mAdapter.getHwIdFromClient(mClient, mIds[i], hwId); + if (LOCATION_ERROR_SUCCESS == errs[i]) { + mApi.resumeGeofence(hwId, mIds[i], + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, hwId, + errs, mIds = mIds, i] (LocationError err ) { + if (LOCATION_ERROR_SUCCESS == err) { + errs[i] = err; + + mAdapter.resumeGeofenceItem(hwId); + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + } + })); + } else { + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + } + } + })); + } + } + }; + + if (0 == count) { + return; + } + uint32_t* idsCopy = new uint32_t[count]; + if (nullptr == idsCopy) { + LOC_LOGE("%s]: new failed to allocate idsCopy", __func__); + return; + } + COPY_IF_NOT_NULL(idsCopy, ids, count); + sendMsg(new MsgResumeGeofences(*this, *mLocApi, client, count, idsCopy)); +} + +void +GeofenceAdapter::modifyGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids, + GeofenceOption* options) +{ + LOC_LOGD("%s]: client %p count %zu", __func__, client, count); + + struct MsgModifyGeofences : public LocMsg { + GeofenceAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + size_t mCount; + uint32_t* mIds; + GeofenceOption* mOptions; + inline MsgModifyGeofences(GeofenceAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + size_t count, + uint32_t* ids, + GeofenceOption* options) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mCount(count), + mIds(ids), + mOptions(options) {} + inline virtual void proc() const { + LocationError* errs = new LocationError[mCount]; + if (nullptr == errs) { + LOC_LOGE("%s]: new failed to allocate errs", __func__); + return; + } + for (size_t i=0; i < mCount; ++i) { + if (NULL == mIds || NULL == mOptions) { + errs[i] = LOCATION_ERROR_INVALID_PARAMETER; + } else { + mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, mIds = mIds, + &mApi = mApi, mOptions = mOptions, errs, i] (LocationError err ) { + uint32_t hwId = 0; + errs[i] = mAdapter.getHwIdFromClient(mClient, mIds[i], hwId); + if (LOCATION_ERROR_SUCCESS == errs[i]) { + mApi.modifyGeofence(hwId, mIds[i], mOptions[i], + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mCount = mCount, mClient = mClient, + mIds = mIds, mOptions = mOptions, hwId, errs, i] + (LocationError err ) { + if (LOCATION_ERROR_SUCCESS == err) { + errs[i] = err; + + mAdapter.modifyGeofenceItem(hwId, mOptions[i]); + } + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + delete[] mOptions; + } + })); + } else { + // Send aggregated response on last item and cleanup + if (i == mCount-1) { + mAdapter.reportResponse(mClient, mCount, errs, mIds); + delete[] errs; + delete[] mIds; + delete[] mOptions; + } + } + })); + } + } + } + }; + + if (0 == count) { + return; + } + uint32_t* idsCopy = new uint32_t[count]; + if (nullptr == idsCopy) { + LOC_LOGE("%s]: new failed to allocate idsCopy", __func__); + return; + } + COPY_IF_NOT_NULL(idsCopy, ids, count); + GeofenceOption* optionsCopy; + if (options == NULL) { + optionsCopy = NULL; + } else { + optionsCopy = new GeofenceOption[count]; + if (nullptr == optionsCopy) { + LOC_LOGE("%s]: new failed to allocate optionsCopy", __func__); + return; + } + COPY_IF_NOT_NULL(optionsCopy, options, count); + } + + sendMsg(new MsgModifyGeofences(*this, *mLocApi, client, count, idsCopy, optionsCopy)); +} + +void +GeofenceAdapter::saveGeofenceItem(LocationAPI* client, uint32_t clientId, uint32_t hwId, + const GeofenceOption& options, const GeofenceInfo& info) +{ + LOC_LOGD("%s]: hwId %u client %p clientId %u", __func__, hwId, client, clientId); + GeofenceKey key(client, clientId); + GeofenceObject object = {key, + options.breachTypeMask, + options.responsiveness, + options.dwellTime, + info.latitude, + info.longitude, + info.radius, + false}; + mGeofences[hwId] = object; + mGeofenceIds[key] = hwId; + dump(); +} + +void +GeofenceAdapter::removeGeofenceItem(uint32_t hwId) +{ + GeofenceKey key; + LocationError err = getGeofenceKeyFromHwId(hwId, key); + if (LOCATION_ERROR_SUCCESS != err) { + LOC_LOGE("%s]: can not find the key for hwId %u", __func__, hwId); + } else { + auto it1 = mGeofenceIds.find(key); + if (it1 != mGeofenceIds.end()) { + mGeofenceIds.erase(it1); + + auto it2 = mGeofences.find(hwId); + if (it2 != mGeofences.end()) { + mGeofences.erase(it2); + dump(); + } else { + LOC_LOGE("%s]:geofence item to erase not found. hwId %u", __func__, hwId); + } + } else { + LOC_LOGE("%s]: geofence item to erase not found. hwId %u", __func__, hwId); + } + } +} + +void +GeofenceAdapter::pauseGeofenceItem(uint32_t hwId) +{ + auto it = mGeofences.find(hwId); + if (it != mGeofences.end()) { + it->second.paused = true; + dump(); + } else { + LOC_LOGE("%s]: geofence item to pause not found. hwId %u", __func__, hwId); + } +} + +void +GeofenceAdapter::resumeGeofenceItem(uint32_t hwId) +{ + auto it = mGeofences.find(hwId); + if (it != mGeofences.end()) { + it->second.paused = false; + dump(); + } else { + LOC_LOGE("%s]: geofence item to resume not found. hwId %u", __func__, hwId); + } +} + +void +GeofenceAdapter::modifyGeofenceItem(uint32_t hwId, const GeofenceOption& options) +{ + auto it = mGeofences.find(hwId); + if (it != mGeofences.end()) { + it->second.breachMask = options.breachTypeMask; + it->second.responsiveness = options.responsiveness; + it->second.dwellTime = options.dwellTime; + dump(); + } else { + LOC_LOGE("%s]: geofence item to modify not found. hwId %u", __func__, hwId); + } +} + + +void +GeofenceAdapter::geofenceBreachEvent(size_t count, uint32_t* hwIds, Location& location, + GeofenceBreachType breachType, uint64_t timestamp) +{ + + IF_LOC_LOGD { + std::string idsString = "["; + if (NULL != hwIds) { + for (size_t i=0; i < count; ++i) { + idsString += std::to_string(hwIds[i]) + " "; + } + } + idsString += "]"; + LOC_LOGD("%s]: breachType %u count %zu ids %s", + __func__, breachType, count, idsString.c_str()); + } + + if (0 == count || NULL == hwIds) + return; + + struct MsgGeofenceBreach : public LocMsg { + GeofenceAdapter& mAdapter; + size_t mCount; + uint32_t* mHwIds; + Location mLocation; + GeofenceBreachType mBreachType; + uint64_t mTimestamp; + inline MsgGeofenceBreach(GeofenceAdapter& adapter, + size_t count, + uint32_t* hwIds, + Location& location, + GeofenceBreachType breachType, + uint64_t timestamp) : + LocMsg(), + mAdapter(adapter), + mCount(count), + mHwIds(new uint32_t[count]), + mLocation(location), + mBreachType(breachType), + mTimestamp(timestamp) + { + if (nullptr == mHwIds) { + LOC_LOGE("%s]: new failed to allocate mHwIds", __func__); + return; + } + COPY_IF_NOT_NULL(mHwIds, hwIds, mCount); + } + inline virtual ~MsgGeofenceBreach() { + delete[] mHwIds; + } + inline virtual void proc() const { + mAdapter.geofenceBreach(mCount, mHwIds, mLocation, mBreachType, mTimestamp); + } + }; + + sendMsg(new MsgGeofenceBreach(*this, count, hwIds, location, breachType, timestamp)); + +} + +void +GeofenceAdapter::geofenceBreach(size_t count, uint32_t* hwIds, const Location& location, + GeofenceBreachType breachType, uint64_t timestamp) +{ + + for (auto it = mClientData.begin(); it != mClientData.end(); ++it) { + uint32_t* clientIds = new uint32_t[count]; + if (nullptr == clientIds) { + return; + } + uint32_t index = 0; + for (size_t i=0; i < count; ++i) { + GeofenceKey key; + LocationError err = getGeofenceKeyFromHwId(hwIds[i], key); + if (LOCATION_ERROR_SUCCESS == err) { + if (key.client == it->first) { + clientIds[index++] = key.id; + } + } + } + if (index > 0 && it->second.geofenceBreachCb != nullptr) { + GeofenceBreachNotification notify = {sizeof(GeofenceBreachNotification), + index, + clientIds, + location, + breachType, + timestamp}; + + it->second.geofenceBreachCb(notify); + } + delete[] clientIds; + } +} + +void +GeofenceAdapter::geofenceStatusEvent(GeofenceStatusAvailable available) +{ + LOC_LOGD("%s]: available %u ", __func__, available); + + struct MsgGeofenceStatus : public LocMsg { + GeofenceAdapter& mAdapter; + GeofenceStatusAvailable mAvailable; + inline MsgGeofenceStatus(GeofenceAdapter& adapter, + GeofenceStatusAvailable available) : + LocMsg(), + mAdapter(adapter), + mAvailable(available) {} + inline virtual void proc() const { + mAdapter.geofenceStatus(mAvailable); + } + }; + + sendMsg(new MsgGeofenceStatus(*this, available)); +} + +void +GeofenceAdapter::geofenceStatus(GeofenceStatusAvailable available) +{ + for (auto it = mClientData.begin(); it != mClientData.end(); ++it) { + if (it->second.geofenceStatusCb != nullptr) { + GeofenceStatusNotification notify = {sizeof(GeofenceStatusNotification), + available, + LOCATION_TECHNOLOGY_TYPE_GNSS}; + it->second.geofenceStatusCb(notify); + } + } +} + +void +GeofenceAdapter::dump() +{ + IF_LOC_LOGV { + LOC_LOGV( + "HAL | hwId | mask | respon | latitude | longitude | radius | paused | Id | client"); + for (auto it = mGeofences.begin(); it != mGeofences.end(); ++it) { + uint32_t hwId = it->first; + GeofenceObject object = it->second; + LOC_LOGV(" | %5u | %4u | %6u | %8.2f | %9.2f | %6.2f | %6u | %04x | %p ", + hwId, object.breachMask, object.responsiveness, + object.latitude, object.longitude, object.radius, + object.paused, object.key.id, object.key.client); + } + } +} + diff --git a/gps/geofence/GeofenceAdapter.h b/gps/geofence/GeofenceAdapter.h new file mode 100644 index 0000000..38f4823 --- /dev/null +++ b/gps/geofence/GeofenceAdapter.h @@ -0,0 +1,136 @@ +/* Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef GEOFENCE_ADAPTER_H +#define GEOFENCE_ADAPTER_H + +#include +#include +#include +#include + +using namespace loc_core; + +#define COPY_IF_NOT_NULL(dest, src, len) do { \ + if (NULL!=dest && NULL!=src) { \ + for (size_t i=0; i GeofencesMap; //map of hwId to GeofenceObject +typedef std::map GeofenceIdMap; //map of GeofenceKey to hwId + +class GeofenceAdapter : public LocAdapterBase { + + /* ==== GEOFENCES ====================================================================== */ + GeofencesMap mGeofences; //map hwId to GeofenceObject + GeofenceIdMap mGeofenceIds; //map of GeofenceKey to hwId + +protected: + + /* ==== CLIENT ========================================================================= */ + virtual void updateClientsEventMask(); + virtual void stopClientSessions(LocationAPI* client); + +public: + + GeofenceAdapter(); + virtual ~GeofenceAdapter() {} + + /* ==== SSR ============================================================================ */ + /* ======== EVENTS ====(Called from QMI Thread)========================================= */ + virtual void handleEngineUpEvent(); + /* ======== UTILITIES ================================================================== */ + void restartGeofences(); + + /* ==== GEOFENCES ====================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + uint32_t* addGeofencesCommand(LocationAPI* client, size_t count, + GeofenceOption* options, GeofenceInfo* info); + void removeGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids); + void pauseGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids); + void resumeGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids); + void modifyGeofencesCommand(LocationAPI* client, size_t count, uint32_t* ids, + GeofenceOption* options); + /* ======== RESPONSES ================================================================== */ + void reportResponse(LocationAPI* client, size_t count, LocationError* errs, uint32_t* ids); + /* ======== UTILITIES ================================================================== */ + void saveGeofenceItem(LocationAPI* client, + uint32_t clientId, + uint32_t hwId, + const GeofenceOption& options, + const GeofenceInfo& info); + void removeGeofenceItem(uint32_t hwId); + void pauseGeofenceItem(uint32_t hwId); + void resumeGeofenceItem(uint32_t hwId); + void modifyGeofenceItem(uint32_t hwId, const GeofenceOption& options); + LocationError getHwIdFromClient(LocationAPI* client, uint32_t clientId, uint32_t& hwId); + LocationError getGeofenceKeyFromHwId(uint32_t hwId, GeofenceKey& key); + void dump(); + + /* ==== REPORTS ======================================================================== */ + /* ======== EVENTS ====(Called from QMI Thread)========================================= */ + void geofenceBreachEvent(size_t count, uint32_t* hwIds, Location& location, + GeofenceBreachType breachType, uint64_t timestamp); + void geofenceStatusEvent(GeofenceStatusAvailable available); + /* ======== UTILITIES ================================================================== */ + void geofenceBreach(size_t count, uint32_t* hwIds, const Location& location, + GeofenceBreachType breachType, uint64_t timestamp); + void geofenceStatus(GeofenceStatusAvailable available); +}; + +#endif /* GEOFENCE_ADAPTER_H */ diff --git a/gps/geofence/Makefile.am b/gps/geofence/Makefile.am new file mode 100644 index 0000000..61883ff --- /dev/null +++ b/gps/geofence/Makefile.am @@ -0,0 +1,50 @@ +AM_CFLAGS = -Wundef \ + -Wno-trigraphs \ + -g -O0 \ + -fno-inline \ + -fno-short-enums \ + -fpic \ + ${GPSUTILS_CFLAGS} \ + ${LOCCORE_CFLAGS} \ + $(LOCPLA_CFLAGS) \ + -D__func__=__PRETTY_FUNCTION__ \ + -std=c++1y + +AM_CPPFLAGS = $(AM_CFLAGS) + +ACLOCAL_AMFLAGS = -I m4 + +requiredlibs = \ + ${LOCCORE_LIBS} \ + $(GPSUTILS_LIBS) \ + -llog + +h_sources = \ + GeofenceAdapter.h + +c_sources = \ + GeofenceAdapter.cpp \ + location_geofence.cpp + +libgeofencing_la_SOURCES = $(c_sources) +if USE_GLIB +libgeofencing_la_CFLAGS = -DUSE_GLIB @GLIB_CFLAGS@ $(AM_CFLAGS) +libgeofencing_la_CPPFLAGS = -DUSE_GLIB @GLIB_CFLAGS@ $(AM_CFLAGS) $(AM_CPPFLAGS) +libgeofencing_la_LDFLAGS = -lstdc++ -Wl,-z,defs @GLIB_LIBS@ $(requiredlibs) -shared -version-info 1:0:0 +libgeofencing_la_LIBDADD = $(requiredlibs) -lstdc++ @GLIB_LIBS@ +else +libgeofencing_la_CFLAGS = $(AM_CFLAGS) +libgeofencing_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +libgeofencing_la_LDFLAGS = -lstdc++ -Wl,-z,defs $(requiredlibs) -shared -version-info 1:0:0 +libgeofencing_la_LIBDADD = $(requiredlibs) -lstdc++ +endif + +library_include_HEADERS = $(h_sources) + +library_includedir = $(pkgincludedir) + +lib_LTLIBRARIES = libgeofencing.la + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = location-geofence.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/geofence/configure.ac b/gps/geofence/configure.ac new file mode 100644 index 0000000..74eae7a --- /dev/null +++ b/gps/geofence/configure.ac @@ -0,0 +1,72 @@ +AC_PREREQ(2.61) +AC_INIT([location-geofence], 1.0.0) +AM_INIT_AUTOMAKE([foreign subdir-objects]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Check for programs +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Check for libraries +PKG_CHECK_MODULES([GPSUTILS], [gps-utils]) +AC_SUBST([GPSUTILS_CFLAGS]) +AC_SUBST([GPSUTILS_LIBS]) + +PKG_CHECK_MODULES([LOCCORE], [loc-core]) +AC_SUBST([LOCCORE_CFLAGS]) +AC_SUBST([LOCCORE_LIBS]) + +AS_CASE([$host], + [arm*], [ARM=yes], + [ARM=no] +) + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x$with_locpla_includes" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_SUBST([CFLAGS]) +AC_SUBST([CPPFLAGS]) +AC_SUBST([LIBS]) + +AC_CONFIG_FILES([ \ + Makefile \ + location-geofence.pc + ]) + +AC_OUTPUT diff --git a/gps/geofence/location-geofence.pc.in b/gps/geofence/location-geofence.pc.in new file mode 100644 index 0000000..6a0781f --- /dev/null +++ b/gps/geofence/location-geofence.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: location-geofence +Description: QTI GPS Geofence +Version: @VERSION +Libs: -L${libdir} -lgeofencing +Cflags: -I${includedir}/location-geofence diff --git a/gps/geofence/location_geofence.cpp b/gps/geofence/location_geofence.cpp new file mode 100644 index 0000000..66729f4 --- /dev/null +++ b/gps/geofence/location_geofence.cpp @@ -0,0 +1,145 @@ +/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "GeofenceAdapter.h" +#include "location_interface.h" + +static GeofenceAdapter* gGeofenceAdapter = NULL; + +static void initialize(); +static void deinitialize(); + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks); +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb); +static void requestCapabilities(LocationAPI* client); + +static uint32_t* addGeofences(LocationAPI* client, size_t count, GeofenceOption*, GeofenceInfo*); +static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids); +static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids, + GeofenceOption* options); +static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids); +static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids); + +static const GeofenceInterface gGeofenceInterface = { + sizeof(GeofenceInterface), + initialize, + deinitialize, + addClient, + removeClient, + requestCapabilities, + addGeofences, + removeGeofences, + modifyGeofences, + pauseGeofences, + resumeGeofences +}; + +#ifndef DEBUG_X86 +extern "C" const GeofenceInterface* getGeofenceInterface() +#else +const GeofenceInterface* getGeofenceInterface() +#endif // DEBUG_X86 +{ + return &gGeofenceInterface; +} + +static void initialize() +{ + if (NULL == gGeofenceAdapter) { + gGeofenceAdapter = new GeofenceAdapter(); + } +} + +static void deinitialize() +{ + if (NULL != gGeofenceAdapter) { + delete gGeofenceAdapter; + gGeofenceAdapter = NULL; + } +} + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks) +{ + if (NULL != gGeofenceAdapter) { + gGeofenceAdapter->addClientCommand(client, callbacks); + } +} + +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb) +{ + if (NULL != gGeofenceAdapter) { + gGeofenceAdapter->removeClientCommand(client, rmClientCb); + } +} + +static void requestCapabilities(LocationAPI* client) +{ + if (NULL != gGeofenceAdapter) { + gGeofenceAdapter->requestCapabilitiesCommand(client); + } +} + +static uint32_t* addGeofences(LocationAPI* client, size_t count, + GeofenceOption* options, GeofenceInfo* info) +{ + if (NULL != gGeofenceAdapter) { + return gGeofenceAdapter->addGeofencesCommand(client, count, options, info); + } else { + return NULL; + } +} + +static void removeGeofences(LocationAPI* client, size_t count, uint32_t* ids) +{ + if (NULL != gGeofenceAdapter) { + return gGeofenceAdapter->removeGeofencesCommand(client, count, ids); + } +} + +static void modifyGeofences(LocationAPI* client, size_t count, uint32_t* ids, + GeofenceOption* options) +{ + if (NULL != gGeofenceAdapter) { + return gGeofenceAdapter->modifyGeofencesCommand(client, count, ids, options); + } +} + +static void pauseGeofences(LocationAPI* client, size_t count, uint32_t* ids) +{ + if (NULL != gGeofenceAdapter) { + return gGeofenceAdapter->pauseGeofencesCommand(client, count, ids); + } +} + +static void resumeGeofences(LocationAPI* client, size_t count, uint32_t* ids) +{ + if (NULL != gGeofenceAdapter) { + return gGeofenceAdapter->resumeGeofencesCommand(client, count, ids); + } +} + diff --git a/gps/gnss/Agps.cpp b/gps/gnss/Agps.cpp new file mode 100644 index 0000000..9255f88 --- /dev/null +++ b/gps/gnss/Agps.cpp @@ -0,0 +1,675 @@ +/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_Agps" + +#include +#include +#include +#include +#include + +/* -------------------------------------------------------------------- + * AGPS State Machine Methods + * -------------------------------------------------------------------*/ +void AgpsStateMachine::processAgpsEvent(AgpsEvent event){ + + LOC_LOGD("processAgpsEvent(): SM %p, Event %d, State %d", + this, event, mState); + + switch (event) { + + case AGPS_EVENT_SUBSCRIBE: + processAgpsEventSubscribe(); + break; + + case AGPS_EVENT_UNSUBSCRIBE: + processAgpsEventUnsubscribe(); + break; + + case AGPS_EVENT_GRANTED: + processAgpsEventGranted(); + break; + + case AGPS_EVENT_RELEASED: + processAgpsEventReleased(); + break; + + case AGPS_EVENT_DENIED: + processAgpsEventDenied(); + break; + + default: + LOC_LOGE("Invalid Loc Agps Event"); + } +} + +void AgpsStateMachine::processAgpsEventSubscribe(){ + + switch (mState) { + + case AGPS_STATE_RELEASED: + /* Add subscriber to list + * No notifications until we get RSRC_GRANTED */ + addSubscriber(mCurrentSubscriber); + requestOrReleaseDataConn(true); + transitionState(AGPS_STATE_PENDING); + break; + + case AGPS_STATE_PENDING: + /* Already requested for data connection, + * do nothing until we get RSRC_GRANTED event; + * Just add this subscriber to the list, for notifications */ + addSubscriber(mCurrentSubscriber); + break; + + case AGPS_STATE_ACQUIRED: + /* We already have the data connection setup, + * Notify current subscriber with GRANTED event, + * And add it to the subscriber list for further notifications. */ + notifyEventToSubscriber(AGPS_EVENT_GRANTED, mCurrentSubscriber, false); + addSubscriber(mCurrentSubscriber); + break; + + case AGPS_STATE_RELEASING: + addSubscriber(mCurrentSubscriber); + break; + + default: + LOC_LOGE("Invalid state: %d", mState); + } +} + +void AgpsStateMachine::processAgpsEventUnsubscribe(){ + + switch (mState) { + + case AGPS_STATE_RELEASED: + notifyEventToSubscriber( + AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, false); + break; + + case AGPS_STATE_PENDING: + case AGPS_STATE_ACQUIRED: + /* If the subscriber wishes to wait for connection close, + * before being removed from list, move to inactive state + * and notify */ + if (mCurrentSubscriber->mWaitForCloseComplete) { + mCurrentSubscriber->mIsInactive = true; + } + else { + /* Notify only current subscriber and then delete it from + * subscriberList */ + notifyEventToSubscriber( + AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true); + } + + /* If no subscribers in list, release data connection */ + if (mSubscriberList.empty()) { + transitionState(AGPS_STATE_RELEASED); + requestOrReleaseDataConn(false); + } + /* Some subscribers in list, but all inactive; + * Release data connection */ + else if(!anyActiveSubscribers()) { + transitionState(AGPS_STATE_RELEASING); + requestOrReleaseDataConn(false); + } + break; + + case AGPS_STATE_RELEASING: + /* If the subscriber wishes to wait for connection close, + * before being removed from list, move to inactive state + * and notify */ + if (mCurrentSubscriber->mWaitForCloseComplete) { + mCurrentSubscriber->mIsInactive = true; + } + else { + /* Notify only current subscriber and then delete it from + * subscriberList */ + notifyEventToSubscriber( + AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true); + } + + /* If no subscribers in list, just move the state. + * Request for releasing data connection should already have been + * sent */ + if (mSubscriberList.empty()) { + transitionState(AGPS_STATE_RELEASED); + } + break; + + default: + LOC_LOGE("Invalid state: %d", mState); + } +} + +void AgpsStateMachine::processAgpsEventGranted(){ + + switch (mState) { + + case AGPS_STATE_RELEASED: + case AGPS_STATE_ACQUIRED: + case AGPS_STATE_RELEASING: + LOC_LOGE("Unexpected event GRANTED in state %d", mState); + break; + + case AGPS_STATE_PENDING: + // Move to acquired state + transitionState(AGPS_STATE_ACQUIRED); + notifyAllSubscribers( + AGPS_EVENT_GRANTED, false, + AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS); + break; + + default: + LOC_LOGE("Invalid state: %d", mState); + } +} + +void AgpsStateMachine::processAgpsEventReleased(){ + + switch (mState) { + + case AGPS_STATE_RELEASED: + /* Subscriber list should be empty if we are in released state */ + if (!mSubscriberList.empty()) { + LOC_LOGE("Unexpected event RELEASED in RELEASED state"); + } + break; + + case AGPS_STATE_ACQUIRED: + /* Force release received */ + LOC_LOGW("Force RELEASED event in ACQUIRED state"); + transitionState(AGPS_STATE_RELEASED); + notifyAllSubscribers( + AGPS_EVENT_RELEASED, true, + AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS); + break; + + case AGPS_STATE_RELEASING: + /* Notify all inactive subscribers about the event */ + notifyAllSubscribers( + AGPS_EVENT_RELEASED, true, + AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS); + + /* If we have active subscribers now, they must be waiting for + * data conn setup */ + if (anyActiveSubscribers()) { + transitionState(AGPS_STATE_PENDING); + requestOrReleaseDataConn(true); + } + /* No active subscribers, move to released state */ + else { + transitionState(AGPS_STATE_RELEASED); + } + break; + + case AGPS_STATE_PENDING: + /* NOOP */ + break; + + default: + LOC_LOGE("Invalid state: %d", mState); + } +} + +void AgpsStateMachine::processAgpsEventDenied(){ + + switch (mState) { + + case AGPS_STATE_RELEASED: + LOC_LOGE("Unexpected event DENIED in state %d", mState); + break; + + case AGPS_STATE_ACQUIRED: + /* NOOP */ + break; + + case AGPS_STATE_RELEASING: + /* Notify all inactive subscribers about the event */ + notifyAllSubscribers( + AGPS_EVENT_RELEASED, true, + AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS); + + /* If we have active subscribers now, they must be waiting for + * data conn setup */ + if (anyActiveSubscribers()) { + transitionState(AGPS_STATE_PENDING); + requestOrReleaseDataConn(true); + } + /* No active subscribers, move to released state */ + else { + transitionState(AGPS_STATE_RELEASED); + } + break; + + case AGPS_STATE_PENDING: + transitionState(AGPS_STATE_RELEASED); + notifyAllSubscribers( + AGPS_EVENT_DENIED, true, + AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS); + break; + + default: + LOC_LOGE("Invalid state: %d", mState); + } +} + +/* Request or Release data connection + * bool request : + * true = Request data connection + * false = Release data connection */ +void AgpsStateMachine::requestOrReleaseDataConn(bool request){ + + AGnssExtStatusIpV4 nifRequest; + memset(&nifRequest, 0, sizeof(nifRequest)); + + nifRequest.type = mAgpsType; + nifRequest.apnTypeMask = mApnTypeMask; + if (request) { + LOC_LOGD("AGPS Data Conn Request mAgpsType=%d mApnTypeMask=0x%X", + mAgpsType, mApnTypeMask); + nifRequest.status = LOC_GPS_REQUEST_AGPS_DATA_CONN; + } + else{ + LOC_LOGD("AGPS Data Conn Release mAgpsType=%d mApnTypeMask=0x%X", + mAgpsType, mApnTypeMask); + nifRequest.status = LOC_GPS_RELEASE_AGPS_DATA_CONN; + } + + mFrameworkStatusV4Cb(nifRequest); +} + +void AgpsStateMachine::notifyAllSubscribers( + AgpsEvent event, bool deleteSubscriberPostNotify, + AgpsNotificationType notificationType){ + + LOC_LOGD("notifyAllSubscribers(): " + "SM %p, Event %d Delete %d Notification Type %d", + this, event, deleteSubscriberPostNotify, notificationType); + + std::list::const_iterator it = mSubscriberList.begin(); + while ( it != mSubscriberList.end() ) { + + AgpsSubscriber* subscriber = *it; + + if (notificationType == AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS || + (notificationType == AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS && + subscriber->mIsInactive) || + (notificationType == AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS && + !subscriber->mIsInactive)) { + + /* Deleting via this call would require another traversal + * through subscriber list, inefficient; hence pass in false*/ + notifyEventToSubscriber(event, subscriber, false); + + if (deleteSubscriberPostNotify) { + it = mSubscriberList.erase(it); + delete subscriber; + } else { + it++; + } + } else { + it++; + } + } +} + +void AgpsStateMachine::notifyEventToSubscriber( + AgpsEvent event, AgpsSubscriber* subscriberToNotify, + bool deleteSubscriberPostNotify) { + + LOC_LOGD("notifyEventToSubscriber(): " + "SM %p, Event %d Subscriber %p Delete %d", + this, event, subscriberToNotify, deleteSubscriberPostNotify); + + switch (event) { + + case AGPS_EVENT_GRANTED: + mAgpsManager->mAtlOpenStatusCb( + subscriberToNotify->mConnHandle, 1, getAPN(), getAPNLen(), + getBearer(), mAgpsType, mApnTypeMask); + break; + + case AGPS_EVENT_DENIED: + mAgpsManager->mAtlOpenStatusCb( + subscriberToNotify->mConnHandle, 0, getAPN(), getAPNLen(), + getBearer(), mAgpsType, mApnTypeMask); + break; + + case AGPS_EVENT_UNSUBSCRIBE: + case AGPS_EVENT_RELEASED: + mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1); + break; + + default: + LOC_LOGE("Invalid event %d", event); + } + + /* Search this subscriber in list and delete */ + if (deleteSubscriberPostNotify) { + deleteSubscriber(subscriberToNotify); + } +} + +void AgpsStateMachine::transitionState(AgpsState newState){ + + LOC_LOGD("transitionState(): SM %p, old %d, new %d", + this, mState, newState); + + mState = newState; + + // notify state transitions to all subscribers ? +} + +void AgpsStateMachine::addSubscriber(AgpsSubscriber* subscriberToAdd){ + + LOC_LOGD("addSubscriber(): SM %p, Subscriber %p", + this, subscriberToAdd); + + // Check if subscriber is already present in the current list + // If not, then add + std::list::const_iterator it = mSubscriberList.begin(); + for (; it != mSubscriberList.end(); it++) { + AgpsSubscriber* subscriber = *it; + if (subscriber->equals(subscriberToAdd)) { + LOC_LOGE("Subscriber already in list"); + return; + } + } + + AgpsSubscriber* cloned = subscriberToAdd->clone(); + LOC_LOGD("addSubscriber(): cloned subscriber: %p", cloned); + mSubscriberList.push_back(cloned); +} + +void AgpsStateMachine::deleteSubscriber(AgpsSubscriber* subscriberToDelete){ + + LOC_LOGD("deleteSubscriber(): SM %p, Subscriber %p", + this, subscriberToDelete); + + std::list::const_iterator it = mSubscriberList.begin(); + while ( it != mSubscriberList.end() ) { + + AgpsSubscriber* subscriber = *it; + if (subscriber && subscriber->equals(subscriberToDelete)) { + + it = mSubscriberList.erase(it); + delete subscriber; + } else { + it++; + } + } +} + +bool AgpsStateMachine::anyActiveSubscribers(){ + + std::list::const_iterator it = mSubscriberList.begin(); + for (; it != mSubscriberList.end(); it++) { + AgpsSubscriber* subscriber = *it; + if (!subscriber->mIsInactive) { + return true; + } + } + return false; +} + +void AgpsStateMachine::setAPN(char* apn, unsigned int len){ + + if (NULL != mAPN) { + delete mAPN; + mAPN = NULL; + } + + if (NULL == apn || len <= 0 || len > MAX_APN_LEN || strlen(apn) != len) { + LOC_LOGD("Invalid apn len (%d) or null apn", len); + mAPN = NULL; + mAPNLen = 0; + } else { + mAPN = new char[len+1]; + if (NULL != mAPN) { + memcpy(mAPN, apn, len); + mAPN[len] = '\0'; + mAPNLen = len; + } + } +} + +AgpsSubscriber* AgpsStateMachine::getSubscriber(int connHandle){ + + /* Go over the subscriber list */ + std::list::const_iterator it = mSubscriberList.begin(); + for (; it != mSubscriberList.end(); it++) { + AgpsSubscriber* subscriber = *it; + if (subscriber->mConnHandle == connHandle) { + return subscriber; + } + } + + /* Not found, return NULL */ + return NULL; +} + +AgpsSubscriber* AgpsStateMachine::getFirstSubscriber(bool isInactive){ + + /* Go over the subscriber list */ + std::list::const_iterator it = mSubscriberList.begin(); + for (; it != mSubscriberList.end(); it++) { + AgpsSubscriber* subscriber = *it; + if(subscriber->mIsInactive == isInactive) { + return subscriber; + } + } + + /* Not found, return NULL */ + return NULL; +} + +void AgpsStateMachine::dropAllSubscribers(){ + + LOC_LOGD("dropAllSubscribers(): SM %p", this); + + /* Go over the subscriber list */ + std::list::const_iterator it = mSubscriberList.begin(); + while ( it != mSubscriberList.end() ) { + AgpsSubscriber* subscriber = *it; + it = mSubscriberList.erase(it); + delete subscriber; + } +} + +/* -------------------------------------------------------------------- + * Loc AGPS Manager Methods + * -------------------------------------------------------------------*/ + +/* CREATE AGPS STATE MACHINES + * Must be invoked in Msg Handler context */ +void AgpsManager::createAgpsStateMachines(const AgpsCbInfo& cbInfo) { + + LOC_LOGD("AgpsManager::createAgpsStateMachines"); + + bool agpsCapable = + ((loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSA) || + (loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSB)); + + if (NULL == mInternetNif && (cbInfo.atlType & AGPS_ATL_TYPE_WWAN)) { + mInternetNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_WWAN_ANY); + mInternetNif->registerFrameworkStatusCallback((AgnssStatusIpV4Cb)cbInfo.statusV4Cb); + LOC_LOGD("Internet NIF: %p", mInternetNif); + } + if (agpsCapable) { + if (NULL == mAgnssNif && (cbInfo.atlType & AGPS_ATL_TYPE_SUPL) && + (cbInfo.atlType & AGPS_ATL_TYPE_SUPL_ES)) { + mAgnssNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_SUPL); + mAgnssNif->registerFrameworkStatusCallback((AgnssStatusIpV4Cb)cbInfo.statusV4Cb); + LOC_LOGD("AGNSS NIF: %p", mAgnssNif); + } + } +} + +AgpsStateMachine* AgpsManager::getAgpsStateMachine(AGpsExtType agpsType) { + + LOC_LOGD("AgpsManager::getAgpsStateMachine(): agpsType %d", agpsType); + + switch (agpsType) { + + case LOC_AGPS_TYPE_INVALID: + case LOC_AGPS_TYPE_SUPL: + case LOC_AGPS_TYPE_SUPL_ES: + if (mAgnssNif == NULL) { + LOC_LOGE("NULL AGNSS NIF !"); + } + return mAgnssNif; + case LOC_AGPS_TYPE_WWAN_ANY: + if (mInternetNif == NULL) { + LOC_LOGE("NULL Internet NIF !"); + } + return mInternetNif; + default: + return mInternetNif; + } + + LOC_LOGE("No SM found !"); + return NULL; +} + +void AgpsManager::requestATL(int connHandle, AGpsExtType agpsType, + LocApnTypeMask apnTypeMask){ + + LOC_LOGD("AgpsManager::requestATL(): connHandle %d, agpsType 0x%X apnTypeMask: 0x%X", + connHandle, agpsType, apnTypeMask); + + if (0 == loc_core::ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL && + LOC_AGPS_TYPE_SUPL_ES == agpsType) { + agpsType = LOC_AGPS_TYPE_SUPL; + apnTypeMask &= ~LOC_APN_TYPE_MASK_EMERGENCY; + apnTypeMask |= LOC_APN_TYPE_MASK_SUPL; + LOC_LOGD("Changed agpsType to non-emergency when USE_EMERGENCY... is 0" + "and removed LOC_APN_TYPE_MASK_EMERGENCY from apnTypeMask" + "agpsType 0x%X apnTypeMask : 0x%X", + agpsType, apnTypeMask); + } + AgpsStateMachine* sm = getAgpsStateMachine(agpsType); + + if (sm == NULL) { + + LOC_LOGE("No AGPS State Machine for agpsType: %d apnTypeMask: 0x%X", + agpsType, apnTypeMask); + mAtlOpenStatusCb( + connHandle, 0, NULL, 0, AGPS_APN_BEARER_INVALID, agpsType, apnTypeMask); + return; + } + sm->setType(agpsType); + sm->setApnTypeMask(apnTypeMask); + + /* Invoke AGPS SM processing */ + AgpsSubscriber subscriber(connHandle, false, false, apnTypeMask); + sm->setCurrentSubscriber(&subscriber); + /* Send subscriber event */ + sm->processAgpsEvent(AGPS_EVENT_SUBSCRIBE); +} + +void AgpsManager::releaseATL(int connHandle){ + + LOC_LOGD("AgpsManager::releaseATL(): connHandle %d", connHandle); + + /* First find the subscriber with specified handle. + * We need to search in all state machines. */ + AgpsStateMachine* sm = NULL; + AgpsSubscriber* subscriber = NULL; + + if (mAgnssNif && + (subscriber = mAgnssNif->getSubscriber(connHandle)) != NULL) { + sm = mAgnssNif; + } + else if (mInternetNif && + (subscriber = mInternetNif->getSubscriber(connHandle)) != NULL) { + sm = mInternetNif; + } + if (sm == NULL) { + LOC_LOGE("Subscriber with connHandle %d not found in any SM", + connHandle); + return; + } + + /* Now send unsubscribe event */ + sm->setCurrentSubscriber(subscriber); + sm->processAgpsEvent(AGPS_EVENT_UNSUBSCRIBE); +} + +void AgpsManager::reportAtlOpenSuccess( + AGpsExtType agpsType, char* apnName, int apnLen, + AGpsBearerType bearerType){ + + LOC_LOGD("AgpsManager::reportAtlOpenSuccess(): " + "AgpsType %d, APN [%s], Len %d, BearerType %d", + agpsType, apnName, apnLen, bearerType); + + /* Find the state machine instance */ + AgpsStateMachine* sm = getAgpsStateMachine(agpsType); + + /* Set bearer and apn info in state machine instance */ + sm->setBearer(bearerType); + sm->setAPN(apnName, apnLen); + + /* Send GRANTED event to state machine */ + sm->processAgpsEvent(AGPS_EVENT_GRANTED); +} + +void AgpsManager::reportAtlOpenFailed(AGpsExtType agpsType){ + + LOC_LOGD("AgpsManager::reportAtlOpenFailed(): AgpsType %d", agpsType); + + /* Fetch SM and send DENIED event */ + AgpsStateMachine* sm = getAgpsStateMachine(agpsType); + sm->processAgpsEvent(AGPS_EVENT_DENIED); +} + +void AgpsManager::reportAtlClosed(AGpsExtType agpsType){ + + LOC_LOGD("AgpsManager::reportAtlClosed(): AgpsType %d", agpsType); + + /* Fetch SM and send RELEASED event */ + AgpsStateMachine* sm = getAgpsStateMachine(agpsType); + sm->processAgpsEvent(AGPS_EVENT_RELEASED); +} + +void AgpsManager::handleModemSSR(){ + + LOC_LOGD("AgpsManager::handleModemSSR"); + + /* Drop subscribers from all state machines */ + if (mAgnssNif) { + mAgnssNif->dropAllSubscribers(); + } + if (mInternetNif) { + mInternetNif->dropAllSubscribers(); + } +} diff --git a/gps/gnss/Agps.h b/gps/gnss/Agps.h new file mode 100644 index 0000000..6b43bf5 --- /dev/null +++ b/gps/gnss/Agps.h @@ -0,0 +1,318 @@ +/* Copyright (c) 2012-2018, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef AGPS_H +#define AGPS_H + +#include +#include +#include +#include +#include +#include + +using namespace loc_util; + +/* ATL callback function pointers + * Passed in by Adapter to AgpsManager */ +typedef std::function AgpsAtlOpenStatusCb; + +typedef std::function AgpsAtlCloseStatusCb; + +/* Post message to adapter's message queue */ +typedef std::function SendMsgToAdapterMsgQueueFn; + +/* AGPS States */ +typedef enum { + AGPS_STATE_INVALID = 0, + AGPS_STATE_RELEASED, + AGPS_STATE_PENDING, + AGPS_STATE_ACQUIRED, + AGPS_STATE_RELEASING +} AgpsState; + +typedef enum { + AGPS_EVENT_INVALID = 0, + AGPS_EVENT_SUBSCRIBE, + AGPS_EVENT_UNSUBSCRIBE, + AGPS_EVENT_GRANTED, + AGPS_EVENT_RELEASED, + AGPS_EVENT_DENIED +} AgpsEvent; + +/* Notification Types sent to subscribers */ +typedef enum { + AGPS_NOTIFICATION_TYPE_INVALID = 0, + + /* Meant for all subscribers, either active or inactive */ + AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS, + + /* Meant for only inactive subscribers */ + AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS, + + /* Meant for only active subscribers */ + AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS +} AgpsNotificationType; + +/* Classes in this header */ +class AgpsSubscriber; +class AgpsManager; +class AgpsStateMachine; + +/* SUBSCRIBER + * Each Subscriber instance corresponds to one AGPS request, + * received by the AGPS state machine */ +class AgpsSubscriber { + +public: + int mConnHandle; + + /* Does this subscriber wait for data call close complete, + * before being notified ATL close ? + * While waiting for data call close, subscriber will be in + * inactive state. */ + bool mWaitForCloseComplete; + bool mIsInactive; + LocApnTypeMask mApnTypeMask; + + inline AgpsSubscriber( + int connHandle, bool waitForCloseComplete, bool isInactive, + LocApnTypeMask apnTypeMask) : + mConnHandle(connHandle), + mWaitForCloseComplete(waitForCloseComplete), + mIsInactive(isInactive), + mApnTypeMask(apnTypeMask) {} + inline virtual ~AgpsSubscriber() {} + + inline virtual bool equals(const AgpsSubscriber *s) const + { return (mConnHandle == s->mConnHandle); } + + inline virtual AgpsSubscriber* clone() + { return new AgpsSubscriber( + mConnHandle, mWaitForCloseComplete, mIsInactive, mApnTypeMask); } +}; + +/* AGPS STATE MACHINE */ +class AgpsStateMachine { +protected: + /* AGPS Manager instance, from where this state machine is created */ + AgpsManager* mAgpsManager; + + /* List of all subscribers for this State Machine. + * Once a subscriber is notified for ATL open/close status, + * it is deleted */ + std::list mSubscriberList; + + /* Current subscriber, whose request this State Machine is + * currently processing */ + AgpsSubscriber* mCurrentSubscriber; + + /* Current state for this state machine */ + AgpsState mState; + + AgnssStatusIpV4Cb mFrameworkStatusV4Cb; +private: + /* AGPS Type for this state machine + LOC_AGPS_TYPE_ANY 0 + LOC_AGPS_TYPE_SUPL 1 + LOC_AGPS_TYPE_WWAN_ANY 3 + LOC_AGPS_TYPE_SUPL_ES 5 */ + AGpsExtType mAgpsType; + LocApnTypeMask mApnTypeMask; + + /* APN and IP Type info for AGPS Call */ + char* mAPN; + unsigned int mAPNLen; + AGpsBearerType mBearer; + +public: + /* CONSTRUCTOR */ + AgpsStateMachine(AgpsManager* agpsManager, AGpsExtType agpsType): + mFrameworkStatusV4Cb(NULL), + mAgpsManager(agpsManager), mSubscriberList(), + mCurrentSubscriber(NULL), mState(AGPS_STATE_RELEASED), + mAgpsType(agpsType), mAPN(NULL), mAPNLen(0), + mBearer(AGPS_APN_BEARER_INVALID) {}; + + virtual ~AgpsStateMachine() { if(NULL != mAPN) delete[] mAPN; }; + + /* Getter/Setter methods */ + void setAPN(char* apn, unsigned int len); + inline char* getAPN() const { return (char*)mAPN; } + inline uint32_t getAPNLen() const { return mAPNLen; } + inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; } + inline LocApnTypeMask getApnTypeMask() const { return mApnTypeMask; } + inline void setApnTypeMask(LocApnTypeMask apnTypeMask) + { mApnTypeMask = apnTypeMask; } + inline AGpsBearerType getBearer() const { return mBearer; } + inline void setType(AGpsExtType type) { mAgpsType = type; } + inline AGpsExtType getType() const { return mAgpsType; } + inline void setCurrentSubscriber(AgpsSubscriber* subscriber) + { mCurrentSubscriber = subscriber; } + + inline void registerFrameworkStatusCallback(AgnssStatusIpV4Cb frameworkStatusV4Cb) { + mFrameworkStatusV4Cb = frameworkStatusV4Cb; + } + + /* Fetch subscriber with specified handle */ + AgpsSubscriber* getSubscriber(int connHandle); + + /* Fetch first active or inactive subscriber in list + * isInactive = true : fetch first inactive subscriber + * isInactive = false : fetch first active subscriber */ + AgpsSubscriber* getFirstSubscriber(bool isInactive); + + /* Process LOC AGPS Event being passed in + * onRsrcEvent */ + virtual void processAgpsEvent(AgpsEvent event); + + /* Drop all subscribers, in case of Modem SSR */ + void dropAllSubscribers(); + +protected: + /* Remove the specified subscriber from list if present. + * Also delete the subscriber instance. */ + void deleteSubscriber(AgpsSubscriber* subscriber); + +private: + /* Send call setup request to framework + * sendRsrcRequest(LOC_GPS_REQUEST_AGPS_DATA_CONN) + * sendRsrcRequest(LOC_GPS_RELEASE_AGPS_DATA_CONN) */ + void requestOrReleaseDataConn(bool request); + + /* Individual event processing methods */ + void processAgpsEventSubscribe(); + void processAgpsEventUnsubscribe(); + void processAgpsEventGranted(); + void processAgpsEventReleased(); + void processAgpsEventDenied(); + + /* Clone the passed in subscriber and add to the subscriber list + * if not already present */ + void addSubscriber(AgpsSubscriber* subscriber); + + /* Notify subscribers about AGPS events */ + void notifyAllSubscribers( + AgpsEvent event, bool deleteSubscriberPostNotify, + AgpsNotificationType notificationType); + virtual void notifyEventToSubscriber( + AgpsEvent event, AgpsSubscriber* subscriber, + bool deleteSubscriberPostNotify); + + /* Do we have any subscribers in active state */ + bool anyActiveSubscribers(); + + /* Transition state */ + void transitionState(AgpsState newState); +}; + +/* LOC AGPS MANAGER */ +class AgpsManager { + + friend class AgpsStateMachine; +public: + /* CONSTRUCTOR */ + AgpsManager(): + mAtlOpenStatusCb(), mAtlCloseStatusCb(), + mAgnssNif(NULL), mInternetNif(NULL)/*, mDsNif(NULL)*/ {} + + /* Register callbacks */ + inline void registerATLCallbacks(AgpsAtlOpenStatusCb atlOpenStatusCb, + AgpsAtlCloseStatusCb atlCloseStatusCb) { + + mAtlOpenStatusCb = atlOpenStatusCb; + mAtlCloseStatusCb = atlCloseStatusCb; + } + + /* Check if AGPS client is registered */ + inline bool isRegistered() { return nullptr != mAgnssNif || nullptr != mInternetNif; } + + /* Create all AGPS state machines */ + void createAgpsStateMachines(const AgpsCbInfo& cbInfo); + + /* Process incoming ATL requests */ + void requestATL(int connHandle, AGpsExtType agpsType, LocApnTypeMask apnTypeMask); + void releaseATL(int connHandle); + /* Process incoming framework data call events */ + void reportAtlOpenSuccess(AGpsExtType agpsType, char* apnName, int apnLen, + AGpsBearerType bearerType); + void reportAtlOpenFailed(AGpsExtType agpsType); + void reportAtlClosed(AGpsExtType agpsType); + + /* Handle Modem SSR */ + void handleModemSSR(); + +protected: + + AgpsAtlOpenStatusCb mAtlOpenStatusCb; + AgpsAtlCloseStatusCb mAtlCloseStatusCb; + AgpsStateMachine* mAgnssNif; + AgpsStateMachine* mInternetNif; +private: + /* Fetch state machine for handling request ATL call */ + AgpsStateMachine* getAgpsStateMachine(AGpsExtType agpsType); +}; + +/* Request SUPL/INTERNET/SUPL_ES ATL + * This LocMsg is defined in this header since it has to be used from more + * than one place, other Agps LocMsg are restricted to GnssAdapter and + * declared inline */ +struct AgpsMsgRequestATL: public LocMsg { + + AgpsManager* mAgpsManager; + int mConnHandle; + AGpsExtType mAgpsType; + LocApnTypeMask mApnTypeMask; + + inline AgpsMsgRequestATL(AgpsManager* agpsManager, int connHandle, + AGpsExtType agpsType, LocApnTypeMask apnTypeMask) : + LocMsg(), mAgpsManager(agpsManager), mConnHandle(connHandle), + mAgpsType(agpsType), mApnTypeMask(apnTypeMask){ + + LOC_LOGV("AgpsMsgRequestATL"); + } + + inline virtual void proc() const { + + LOC_LOGV("AgpsMsgRequestATL::proc()"); + mAgpsManager->requestATL(mConnHandle, mAgpsType, mApnTypeMask); + } +}; + +namespace AgpsUtils { + +AGpsBearerType ipTypeToBearerType(LocApnIpType ipType); +LocApnIpType bearerTypeToIpType(AGpsBearerType bearerType); + +} + +#endif /* AGPS_H */ diff --git a/gps/gnss/Android.bp b/gps/gnss/Android.bp new file mode 100644 index 0000000..a3e8de9 --- /dev/null +++ b/gps/gnss/Android.bp @@ -0,0 +1,35 @@ + + +cc_library_shared { + + name: "libgnss", + vendor: true, + + sanitize: GNSS_SANITIZE, + + shared_libs: [ + "libutils", + "libcutils", + "libdl", + "liblog", + "libloc_core", + "libgps.utils", + ], + + srcs: [ + "location_gnss.cpp", + "GnssAdapter.cpp", + "Agps.cpp", + "XtraSystemStatusObserver.cpp", + "NativeAgpsHandler.cpp", + ], + + cflags: ["-fno-short-enums"] + GNSS_CFLAGS, + header_libs: [ + "libgps.utils_headers", + "libloc_core_headers", + "libloc_pla_headers", + "liblocation_api_headers", + ], + +} diff --git a/gps/gnss/GnssAdapter.cpp b/gps/gnss/GnssAdapter.cpp new file mode 100644 index 0000000..cff0298 --- /dev/null +++ b/gps/gnss/GnssAdapter.cpp @@ -0,0 +1,6916 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_GnssAdapter" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RAD2DEG (180.0 / M_PI) +#define DEG2RAD (M_PI / 180.0) +#define PROCESS_NAME_ENGINE_SERVICE "engine-service" +#define MIN_TRACKING_INTERVAL (100) // 100 msec + +#define BILLION_NSEC (1000000000ULL) +#define NMEA_MIN_THRESHOLD_MSEC (99) +#define NMEA_MAX_THRESHOLD_MSEC (975) + +#define DGNSS_RANGE_UPDATE_TIME_10MIN_IN_MILLI 600000 + +using namespace loc_core; + +static int loadEngHubForExternalEngine = 0; +static loc_param_s_type izatConfParamTable[] = { + {"LOAD_ENGHUB_FOR_EXTERNAL_ENGINE", &loadEngHubForExternalEngine, nullptr,'n'} +}; + +/* Method to fetch status cb from loc_net_iface library */ +typedef AgpsCbInfo& (*LocAgpsGetAgpsCbInfo)(LocAgpsOpenResultCb openResultCb, + LocAgpsCloseResultCb closeResultCb, void* userDataPtr); + +static void agpsOpenResultCb (bool isSuccess, AGpsExtType agpsType, const char* apn, + AGpsBearerType bearerType, void* userDataPtr); +static void agpsCloseResultCb (bool isSuccess, AGpsExtType agpsType, void* userDataPtr); + +typedef const CdfwInterface* (*getCdfwInterface)(); + +inline bool GnssReportLoggerUtil::isLogEnabled() { + return (mLogLatency != nullptr); +} + +inline void GnssReportLoggerUtil::log(const GnssLatencyInfo& gnssLatencyMeasInfo) { + if (mLogLatency != nullptr) { + mLogLatency(gnssLatencyMeasInfo); + } +} + +GnssAdapter::GnssAdapter() : + LocAdapterBase(0, + LocContext::getLocContext(LocContext::mLocationHalName), + true, nullptr, true), + mEngHubProxy(new EngineHubProxyBase()), + mQDgnssListenerHDL(nullptr), + mCdfwInterface(nullptr), + mDGnssNeedReport(false), + mDGnssDataUsage(false), + mLocPositionMode(), + mNHzNeeded(false), + mSPEAlreadyRunningAtHighestInterval(false), + mGnssSvIdUsedInPosition(), + mGnssSvIdUsedInPosAvail(false), + mControlCallbacks(), + mAfwControlId(0), + mNmeaMask(0), + mGnssSvIdConfig(), + mGnssSeconaryBandConfig(), + mGnssSvTypeConfig(), + mGnssSvTypeConfigCb(nullptr), + mLocConfigInfo{}, + mNiData(), + mAgpsManager(), + mOdcpiRequestCb(nullptr), + mOdcpiRequestActive(false), + mOdcpiTimer(this), + mOdcpiRequest(), + mCallbackPriority(OdcpiPrioritytype::ODCPI_HANDLER_PRIORITY_LOW), + mSystemStatus(SystemStatus::getInstance(mMsgTask)), + mServerUrl(":"), + mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask), + mBlockCPIInfo{}, + mDreIntEnabled(false), + mLocSystemInfo{}, + mNfwCb(NULL), + mPowerOn(false), + mAllowFlpNetworkFixes(0), + mGnssEnergyConsumedCb(nullptr), + mPowerStateCb(nullptr), + mIsE911Session(NULL), + mGnssMbSvIdUsedInPosition{}, + mGnssMbSvIdUsedInPosAvail(false), + mSupportNfwControl(true), + mSystemPowerState(POWER_STATE_UNKNOWN), + mIsMeasCorrInterfaceOpen(false), + mIsAntennaInfoInterfaceOpened(false), + mLastDeleteAidingDataTime(0), + mDgnssState(0), + mSendNmeaConsent(false), + mDgnssLastNmeaBootTimeMilli(0), + mNativeAgpsHandler(mSystemStatus->getOsObserver(), *this) +{ + LOC_LOGD("%s]: Constructor %p", __func__, this); + mLocPositionMode.mode = LOC_POSITION_MODE_INVALID; + + pthread_condattr_t condAttr; + pthread_condattr_init(&condAttr); + pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC); + pthread_cond_init(&mNiData.session.tCond, &condAttr); + pthread_cond_init(&mNiData.sessionEs.tCond, &condAttr); + pthread_condattr_destroy(&condAttr); + + /* Set ATL open/close callbacks */ + AgpsAtlOpenStatusCb atlOpenStatusCb = + [this](int handle, int isSuccess, char* apn, uint32_t apnLen, + AGpsBearerType bearerType, AGpsExtType agpsType, LocApnTypeMask mask) { + + mLocApi->atlOpenStatus( + handle, isSuccess, apn, apnLen, bearerType, agpsType, mask); + }; + AgpsAtlCloseStatusCb atlCloseStatusCb = + [this](int handle, int isSuccess) { + + mLocApi->atlCloseStatus(handle, isSuccess); + }; + mAgpsManager.registerATLCallbacks(atlOpenStatusCb, atlCloseStatusCb); + + readConfigCommand(); + initDefaultAgpsCommand(); + initEngHubProxyCommand(); + + // at last step, let us inform adapater base that we are done + // with initialization, e.g.: ready to process handleEngineUpEvent + doneInit(); +} + +void +GnssAdapter::setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks) +{ + struct MsgSetControlCallbacks : public LocMsg { + GnssAdapter& mAdapter; + const LocationControlCallbacks mControlCallbacks; + inline MsgSetControlCallbacks(GnssAdapter& adapter, + LocationControlCallbacks& controlCallbacks) : + LocMsg(), + mAdapter(adapter), + mControlCallbacks(controlCallbacks) {} + inline virtual void proc() const { + mAdapter.setControlCallbacks(mControlCallbacks); + } + }; + + sendMsg(new MsgSetControlCallbacks(*this, controlCallbacks)); +} + +void +GnssAdapter::convertOptions(LocPosMode& out, const TrackingOptions& trackingOptions) +{ + switch (trackingOptions.mode) { + case GNSS_SUPL_MODE_MSB: + out.mode = LOC_POSITION_MODE_MS_BASED; + break; + case GNSS_SUPL_MODE_MSA: + out.mode = LOC_POSITION_MODE_MS_ASSISTED; + break; + default: + out.mode = LOC_POSITION_MODE_STANDALONE; + break; + } + out.share_position = true; + out.min_interval = trackingOptions.minInterval; + out.powerMode = trackingOptions.powerMode; + out.timeBetweenMeasurements = trackingOptions.tbm; +} + +bool +GnssAdapter::checkAndSetSPEToRunforNHz(TrackingOptions & out) { + + // first check if NHz meas is needed at all, if not, just return false + // if a NHz capable engine is subscribed for NHz measurement or NHz positions, + // always run the SPE only session at 100ms TBF. + // If SPE session is already set to highest interval, no need to start it again. + + bool isSPERunningAtHighestInterval = false; + + if (!mNHzNeeded) { + LOC_LOGd("No nHz session needed."); + } else if (mSPEAlreadyRunningAtHighestInterval) { + LOC_LOGd("SPE is already running at highest interval."); + isSPERunningAtHighestInterval = true; + } else if (out.minInterval > MIN_TRACKING_INTERVAL) { + out.minInterval = MIN_TRACKING_INTERVAL; + LOC_LOGd("nHz session is needed, starting SPE only session at 100ms TBF."); + mSPEAlreadyRunningAtHighestInterval = true; + } + + return isSPERunningAtHighestInterval; +} + + +void +GnssAdapter::convertLocation(Location& out, const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended) +{ + memset(&out, 0, sizeof(Location)); + out.size = sizeof(Location); + if (LOC_GPS_LOCATION_HAS_LAT_LONG & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_LAT_LONG_BIT; + out.latitude = ulpLocation.gpsLocation.latitude; + out.longitude = ulpLocation.gpsLocation.longitude; + } + if (LOC_GPS_LOCATION_HAS_ALTITUDE & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_ALTITUDE_BIT; + out.altitude = ulpLocation.gpsLocation.altitude; + } + if (LOC_GPS_LOCATION_HAS_SPEED & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_SPEED_BIT; + out.speed = ulpLocation.gpsLocation.speed; + } + if (LOC_GPS_LOCATION_HAS_BEARING & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_BEARING_BIT; + out.bearing = ulpLocation.gpsLocation.bearing; + } + if (LOC_GPS_LOCATION_HAS_ACCURACY & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_ACCURACY_BIT; + out.accuracy = ulpLocation.gpsLocation.accuracy; + } + if (GPS_LOCATION_EXTENDED_HAS_VERT_UNC & locationExtended.flags) { + out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT; + out.verticalAccuracy = locationExtended.vert_unc; + } + if (GPS_LOCATION_EXTENDED_HAS_SPEED_UNC & locationExtended.flags) { + out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT; + out.speedAccuracy = locationExtended.speed_unc; + } + if (GPS_LOCATION_EXTENDED_HAS_BEARING_UNC & locationExtended.flags) { + out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT; + out.bearingAccuracy = locationExtended.bearing_unc; + } + if (GPS_LOCATION_EXTENDED_HAS_CONFORMITY_INDEX & locationExtended.flags) { + out.flags |= LOCATION_HAS_CONFORMITY_INDEX_BIT; + out.conformityIndex = locationExtended.conformityIndex; + } + out.timestamp = ulpLocation.gpsLocation.timestamp; + if (LOC_POS_TECH_MASK_SATELLITE & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_GNSS_BIT; + } + if (LOC_POS_TECH_MASK_CELLID & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_CELL_BIT; + } + if (LOC_POS_TECH_MASK_WIFI & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_WIFI_BIT; + } + if (LOC_POS_TECH_MASK_SENSORS & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_SENSORS_BIT; + } + if (LOC_POS_TECH_MASK_REFERENCE_LOCATION & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_REFERENCE_LOCATION_BIT; + } + if (LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_INJECTED_COARSE_POSITION_BIT; + } + if (LOC_POS_TECH_MASK_AFLT & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_AFLT_BIT; + } + if (LOC_POS_TECH_MASK_HYBRID & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_HYBRID_BIT; + } + if (LOC_POS_TECH_MASK_PPE & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_PPE_BIT; + } + if (LOC_POS_TECH_MASK_VEH & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_VEH_BIT; + } + if (LOC_POS_TECH_MASK_VIS & locationExtended.tech_mask) { + out.techMask |= LOCATION_TECHNOLOGY_VIS_BIT; + } + if (LOC_NAV_MASK_DGNSS_CORRECTION & locationExtended.navSolutionMask) { + out.techMask |= LOCATION_TECHNOLOGY_DGNSS_BIT; + } + + if (LOC_GPS_LOCATION_HAS_SPOOF_MASK & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_SPOOF_MASK; + out.spoofMask = ulpLocation.gpsLocation.spoof_mask; + } + if (LOC_GPS_LOCATION_HAS_ELAPSED_REAL_TIME & ulpLocation.gpsLocation.flags) { + out.flags |= LOCATION_HAS_ELAPSED_REAL_TIME; + out.elapsedRealTime = ulpLocation.gpsLocation.elapsedRealTime; + out.elapsedRealTimeUnc = ulpLocation.gpsLocation.elapsedRealTimeUnc; + } +} + +/* This is utility routine that computes number of SV used + in the fix from the svUsedIdsMask. + */ +#define MAX_SV_CNT_SUPPORTED_IN_ONE_CONSTELLATION 64 +uint16_t GnssAdapter::getNumSvUsed(uint64_t svUsedIdsMask, + int totalSvCntInThisConstellation) +{ + if (totalSvCntInThisConstellation > MAX_SV_CNT_SUPPORTED_IN_ONE_CONSTELLATION) { + LOC_LOGe ("error: total SV count in this constellation %d exceeded limit of %d", + totalSvCntInThisConstellation, MAX_SV_CNT_SUPPORTED_IN_ONE_CONSTELLATION); + return 0; + } + + uint16_t numSvUsed = 0; + uint64_t mask = 0x1; + for (int i = 0; i < totalSvCntInThisConstellation; i++) { + if (svUsedIdsMask & mask) { + numSvUsed++; + } + mask <<= 1; + } + + return numSvUsed; +} + +void +GnssAdapter::convertLocationInfo(GnssLocationInfoNotification& out, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status) +{ + out.size = sizeof(GnssLocationInfoNotification); + if (GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_ALTITUDE_MEAN_SEA_LEVEL_BIT; + out.altitudeMeanSeaLevel = locationExtended.altitudeMeanSeaLevel; + } + if (GPS_LOCATION_EXTENDED_HAS_EXT_DOP & locationExtended.flags) { + out.flags |= (GNSS_LOCATION_INFO_DOP_BIT|GNSS_LOCATION_INFO_EXT_DOP_BIT); + out.pdop = locationExtended.extDOP.PDOP; + out.hdop = locationExtended.extDOP.HDOP; + out.vdop = locationExtended.extDOP.VDOP; + out.gdop = locationExtended.extDOP.GDOP; + out.tdop = locationExtended.extDOP.TDOP; + } else if (GPS_LOCATION_EXTENDED_HAS_DOP & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_DOP_BIT; + out.pdop = locationExtended.pdop; + out.hdop = locationExtended.hdop; + out.vdop = locationExtended.vdop; + } + if (GPS_LOCATION_EXTENDED_HAS_MAG_DEV & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_MAGNETIC_DEVIATION_BIT; + out.magneticDeviation = locationExtended.magneticDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_HOR_RELIABILITY & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_HOR_RELIABILITY_BIT; + switch (locationExtended.horizontal_reliability) { + case LOC_RELIABILITY_VERY_LOW: + out.horReliability = LOCATION_RELIABILITY_VERY_LOW; + break; + case LOC_RELIABILITY_LOW: + out.horReliability = LOCATION_RELIABILITY_LOW; + break; + case LOC_RELIABILITY_MEDIUM: + out.horReliability = LOCATION_RELIABILITY_MEDIUM; + break; + case LOC_RELIABILITY_HIGH: + out.horReliability = LOCATION_RELIABILITY_HIGH; + break; + default: + out.horReliability = LOCATION_RELIABILITY_NOT_SET; + break; + } + } + if (GPS_LOCATION_EXTENDED_HAS_VERT_RELIABILITY & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_VER_RELIABILITY_BIT; + switch (locationExtended.vertical_reliability) { + case LOC_RELIABILITY_VERY_LOW: + out.verReliability = LOCATION_RELIABILITY_VERY_LOW; + break; + case LOC_RELIABILITY_LOW: + out.verReliability = LOCATION_RELIABILITY_LOW; + break; + case LOC_RELIABILITY_MEDIUM: + out.verReliability = LOCATION_RELIABILITY_MEDIUM; + break; + case LOC_RELIABILITY_HIGH: + out.verReliability = LOCATION_RELIABILITY_HIGH; + break; + default: + out.verReliability = LOCATION_RELIABILITY_NOT_SET; + break; + } + } + if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MAJOR & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MAJOR_BIT; + out.horUncEllipseSemiMajor = locationExtended.horUncEllipseSemiMajor; + } + if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MINOR & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MINOR_BIT; + out.horUncEllipseSemiMinor = locationExtended.horUncEllipseSemiMinor; + } + if (GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_AZIMUTH & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_AZIMUTH_BIT; + out.horUncEllipseOrientAzimuth = locationExtended.horUncEllipseOrientAzimuth; + } + if (GPS_LOCATION_EXTENDED_HAS_NORTH_STD_DEV & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_NORTH_STD_DEV_BIT; + out.northStdDeviation = locationExtended.northStdDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_EAST_STD_DEV & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_EAST_STD_DEV_BIT; + out.eastStdDeviation = locationExtended.eastStdDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_NORTH_VEL & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_NORTH_VEL_BIT; + out.northVelocity = locationExtended.northVelocity; + } + if (GPS_LOCATION_EXTENDED_HAS_NORTH_VEL_UNC & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_NORTH_VEL_UNC_BIT; + out.northVelocityStdDeviation = locationExtended.northVelocityStdDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_EAST_VEL & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_EAST_VEL_BIT; + out.eastVelocity = locationExtended.eastVelocity; + } + if (GPS_LOCATION_EXTENDED_HAS_EAST_VEL_UNC & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_EAST_VEL_UNC_BIT; + out.eastVelocityStdDeviation = locationExtended.eastVelocityStdDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_UP_VEL & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_UP_VEL_BIT; + out.upVelocity = locationExtended.upVelocity; + } + if (GPS_LOCATION_EXTENDED_HAS_UP_VEL_UNC & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_UP_VEL_UNC_BIT; + out.upVelocityStdDeviation = locationExtended.upVelocityStdDeviation; + } + if (GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_GNSS_SV_USED_DATA_BIT; + out.svUsedInPosition.gpsSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask; + out.svUsedInPosition.gloSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask; + out.svUsedInPosition.galSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask; + out.svUsedInPosition.bdsSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask; + out.svUsedInPosition.qzssSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask; + out.svUsedInPosition.navicSvUsedIdsMask = + locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask; + + out.flags |= GNSS_LOCATION_INFO_NUM_SV_USED_IN_POSITION_BIT; + out.numSvUsedInPosition = getNumSvUsed(out.svUsedInPosition.gpsSvUsedIdsMask, + GPS_SV_PRN_MAX - GPS_SV_PRN_MIN + 1); + out.numSvUsedInPosition += getNumSvUsed(out.svUsedInPosition.gloSvUsedIdsMask, + GLO_SV_PRN_MAX - GLO_SV_PRN_MIN + 1); + out.numSvUsedInPosition += getNumSvUsed(out.svUsedInPosition.qzssSvUsedIdsMask, + QZSS_SV_PRN_MAX - QZSS_SV_PRN_MIN + 1); + out.numSvUsedInPosition += getNumSvUsed(out.svUsedInPosition.bdsSvUsedIdsMask, + BDS_SV_PRN_MAX - BDS_SV_PRN_MIN + 1); + out.numSvUsedInPosition += getNumSvUsed(out.svUsedInPosition.galSvUsedIdsMask, + GAL_SV_PRN_MAX - GAL_SV_PRN_MIN + 1); + out.numSvUsedInPosition += getNumSvUsed(out.svUsedInPosition.navicSvUsedIdsMask, + NAVIC_SV_PRN_MAX - NAVIC_SV_PRN_MIN + 1); + + out.numOfMeasReceived = locationExtended.numOfMeasReceived; + for (int idx =0; idx < locationExtended.numOfMeasReceived; idx++) { + out.measUsageInfo[idx].gnssSignalType = + locationExtended.measUsageInfo[idx].gnssSignalType; + out.measUsageInfo[idx].gnssSvId = + locationExtended.measUsageInfo[idx].gnssSvId; + out.measUsageInfo[idx].gnssConstellation = + locationExtended.measUsageInfo[idx].gnssConstellation; + } + } + if (GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_NAV_SOLUTION_MASK_BIT; + out.navSolutionMask = locationExtended.navSolutionMask; + } + if (GPS_LOCATION_EXTENDED_HAS_POS_DYNAMICS_DATA & locationExtended.flags) { + out.flags |= GPS_LOCATION_EXTENDED_HAS_POS_DYNAMICS_DATA; + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_LONG_ACCEL_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_LONG_ACCEL_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_LAT_ACCEL_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_LAT_ACCEL_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_VERT_ACCEL_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_VERT_ACCEL_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_YAW_RATE_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_YAW_RATE_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_PITCH_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_PITCH_BIT; + } + + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_LONG_ACCEL_UNC_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_LONG_ACCEL_UNC_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_LAT_ACCEL_UNC_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_LAT_ACCEL_UNC_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_VERT_ACCEL_UNC_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_VERT_ACCEL_UNC_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_YAW_RATE_UNC_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_YAW_RATE_UNC_BIT; + } + if (locationExtended.bodyFrameData.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_PITCH_UNC_BIT) { + out.bodyFrameData.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_PITCH_UNC_BIT; + } + + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_PITCH_RATE_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_PITCH_RATE_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_PITCH_RATE_UNC_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_PITCH_RATE_UNC_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_ROLL_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_ROLL_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_ROLL_UNC_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_ROLL_UNC_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_ROLL_RATE_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_ROLL_RATE_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_ROLL_RATE_UNC_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_ROLL_RATE_UNC_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_YAW_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_YAW_BIT; + } + if (locationExtended.bodyFrameDataExt.bodyFrameDataMask & + LOCATION_NAV_DATA_HAS_YAW_UNC_BIT) { + out.bodyFrameDataExt.bodyFrameDataMask |= LOCATION_NAV_DATA_HAS_YAW_UNC_BIT; + } + + out.bodyFrameData.longAccel = locationExtended.bodyFrameData.longAccel; + out.bodyFrameData.latAccel = locationExtended.bodyFrameData.latAccel; + out.bodyFrameData.vertAccel = locationExtended.bodyFrameData.vertAccel; + out.bodyFrameData.yawRate = locationExtended.bodyFrameData.yawRate; + out.bodyFrameData.pitch = locationExtended.bodyFrameData.pitch; + out.bodyFrameData.longAccelUnc = locationExtended.bodyFrameData.longAccelUnc; + out.bodyFrameData.latAccelUnc = locationExtended.bodyFrameData.latAccelUnc; + out.bodyFrameData.vertAccelUnc = locationExtended.bodyFrameData.vertAccelUnc; + out.bodyFrameData.yawRateUnc = locationExtended.bodyFrameData.yawRateUnc; + out.bodyFrameData.pitchUnc = locationExtended.bodyFrameData.pitchUnc; + + out.bodyFrameDataExt.pitchRate = locationExtended.bodyFrameDataExt.pitchRate; + out.bodyFrameDataExt.pitchRateUnc = locationExtended.bodyFrameDataExt.pitchRateUnc; + out.bodyFrameDataExt.roll = locationExtended.bodyFrameDataExt.roll; + out.bodyFrameDataExt.rollUnc = locationExtended.bodyFrameDataExt.rollUnc; + out.bodyFrameDataExt.rollRate = locationExtended.bodyFrameDataExt.rollRate; + out.bodyFrameDataExt.rollRateUnc = locationExtended.bodyFrameDataExt.rollRateUnc; + out.bodyFrameDataExt.yaw = locationExtended.bodyFrameDataExt.yaw; + out.bodyFrameDataExt.yawUnc = locationExtended.bodyFrameDataExt.yawUnc; + } + + // Validity of this structure is established from the timeSrc of the GnssSystemTime structure. + out.gnssSystemTime = locationExtended.gnssSystemTime; + + if (GPS_LOCATION_EXTENDED_HAS_LEAP_SECONDS & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_LEAP_SECONDS_BIT; + out.leapSeconds = locationExtended.leapSeconds; + } + + if (GPS_LOCATION_EXTENDED_HAS_TIME_UNC & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_TIME_UNC_BIT; + out.timeUncMs = locationExtended.timeUncMs; + } + + if (GPS_LOCATION_EXTENDED_HAS_CALIBRATION_CONFIDENCE & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_CALIBRATION_CONFIDENCE_BIT; + out.calibrationConfidence = locationExtended.calibrationConfidence; + } + + if (GPS_LOCATION_EXTENDED_HAS_CALIBRATION_STATUS & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_CALIBRATION_STATUS_BIT; + out.calibrationStatus = locationExtended.calibrationStatus; + } + + if (GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_OUTPUT_ENG_TYPE_BIT; + out.locOutputEngType = locationExtended.locOutputEngType; + } + + if (GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_MASK & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_OUTPUT_ENG_MASK_BIT; + out.locOutputEngMask = locationExtended.locOutputEngMask; + } + + if (GPS_LOCATION_EXTENDED_HAS_CONFORMITY_INDEX & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_CONFORMITY_INDEX_BIT; + out.conformityIndex = locationExtended.conformityIndex; + } + + if (GPS_LOCATION_EXTENDED_HAS_LLA_VRP_BASED & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_LLA_VRP_BASED_BIT; + out.llaVRPBased = locationExtended.llaVRPBased; + } + + if (GPS_LOCATION_EXTENDED_HAS_ENU_VELOCITY_LLA_VRP_BASED & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_ENU_VELOCITY_VRP_BASED_BIT; + // copy over east, north and up vrp based velocity + out.enuVelocityVRPBased[0] = locationExtended.enuVelocityVRPBased[0]; + out.enuVelocityVRPBased[1] = locationExtended.enuVelocityVRPBased[1]; + out.enuVelocityVRPBased[2] = locationExtended.enuVelocityVRPBased[2]; + } + + if (GPS_LOCATION_EXTENDED_HAS_DR_SOLUTION_STATUS_MASK & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_DR_SOLUTION_STATUS_MASK_BIT; + out.drSolutionStatusMask = locationExtended.drSolutionStatusMask; + } + + if (GPS_LOCATION_EXTENDED_HAS_ALTITUDE_ASSUMED & locationExtended.flags) { + out.flags |= GNSS_LOCATION_INFO_ALTITUDE_ASSUMED_BIT; + out.altitudeAssumed = locationExtended.altitudeAssumed; + } + + out.flags |= GNSS_LOCATION_INFO_SESSION_STATUS_BIT; + out.sessionStatus = status; +} + +inline uint32_t +GnssAdapter::convertSuplVersion(const GnssConfigSuplVersion suplVersion) +{ + switch (suplVersion) { + case GNSS_CONFIG_SUPL_VERSION_2_0_4: + return 0x00020004; + case GNSS_CONFIG_SUPL_VERSION_2_0_0: + return 0x00020000; + case GNSS_CONFIG_SUPL_VERSION_2_0_2: + return 0x00020002; + case GNSS_CONFIG_SUPL_VERSION_1_0_0: + default: + return 0x00010000; + } +} + +uint32_t +GnssAdapter::convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask) +{ + uint32_t mask = 0; + if (GNSS_CONFIG_LPPE_CONTROL_PLANE_DBH_BIT & lppeControlPlaneMask) { + mask |= (1<<0); + } + if (GNSS_CONFIG_LPPE_CONTROL_PLANE_WLAN_AP_MEASUREMENTS_BIT & lppeControlPlaneMask) { + mask |= (1<<1); + } + if (GNSS_CONFIG_LPPE_CONTROL_PLANE_SRN_AP_MEASUREMENTS_BIT & lppeControlPlaneMask) { + mask |= (1<<2); + } + if (GNSS_CONFIG_LPPE_CONTROL_PLANE_SENSOR_BARO_MEASUREMENTS_BIT & lppeControlPlaneMask) { + mask |= (1<<3); + } + return mask; +} + +uint32_t +GnssAdapter::convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask) +{ + uint32_t mask = 0; + if (GNSS_CONFIG_LPPE_USER_PLANE_DBH_BIT & lppeUserPlaneMask) { + mask |= (1<<0); + } + if (GNSS_CONFIG_LPPE_USER_PLANE_WLAN_AP_MEASUREMENTS_BIT & lppeUserPlaneMask) { + mask |= (1<<1); + } + if (GNSS_CONFIG_LPPE_USER_PLANE_SRN_AP_MEASUREMENTS_BIT & lppeUserPlaneMask) { + mask |= (1<<2); + } + if (GNSS_CONFIG_LPPE_USER_PLANE_SENSOR_BARO_MEASUREMENTS_BIT & lppeUserPlaneMask) { + mask |= (1<<3); + } + return mask; +} + +uint32_t +GnssAdapter::convertAGloProt(const GnssConfigAGlonassPositionProtocolMask aGloPositionProtocolMask) +{ + uint32_t mask = 0; + if (GNSS_CONFIG_RRC_CONTROL_PLANE_BIT & aGloPositionProtocolMask) { + mask |= (1<<0); + } + if (GNSS_CONFIG_RRLP_USER_PLANE_BIT & aGloPositionProtocolMask) { + mask |= (1<<1); + } + if (GNSS_CONFIG_LLP_USER_PLANE_BIT & aGloPositionProtocolMask) { + mask |= (1<<2); + } + if (GNSS_CONFIG_LLP_CONTROL_PLANE_BIT & aGloPositionProtocolMask) { + mask |= (1<<3); + } + return mask; +} + +uint32_t +GnssAdapter::convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl emergencyPdnForEmergencySupl) +{ + switch (emergencyPdnForEmergencySupl) { + case GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES: + return 1; + case GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO: + default: + return 0; + } +} + +uint32_t +GnssAdapter::convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices) +{ + switch (suplEmergencyServices) { + case GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES: + return 1; + case GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO: + default: + return 0; + } +} + +uint32_t +GnssAdapter::convertSuplMode(const GnssConfigSuplModeMask suplModeMask) +{ + uint32_t mask = 0; + if (GNSS_CONFIG_SUPL_MODE_MSB_BIT & suplModeMask) { + mask |= (1<<0); + } + if (GNSS_CONFIG_SUPL_MODE_MSA_BIT & suplModeMask) { + mask |= (1<<1); + } + return mask; +} + +void +GnssAdapter::readConfigCommand() +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgReadConfig : public LocMsg { + GnssAdapter* mAdapter; + ContextBase& mContext; + inline MsgReadConfig(GnssAdapter* adapter, + ContextBase& context) : + LocMsg(), + mAdapter(adapter), + mContext(context) {} + inline virtual void proc() const { + static bool confReadDone = false; + if (!confReadDone) { + confReadDone = true; + // reads config into mContext->mGps_conf + mContext.readConfig(); + + uint32_t allowFlpNetworkFixes = 0; + static const loc_param_s_type flp_conf_param_table[] = + { + {"ALLOW_NETWORK_FIXES", &allowFlpNetworkFixes, NULL, 'n'}, + }; + UTIL_READ_CONF(LOC_PATH_FLP_CONF, flp_conf_param_table); + LOC_LOGd("allowFlpNetworkFixes %u", allowFlpNetworkFixes); + mAdapter->setAllowFlpNetworkFixes(allowFlpNetworkFixes); + } + } + }; + + if (mContext != NULL) { + sendMsg(new MsgReadConfig(this, *mContext)); + } +} + +void +GnssAdapter::setSuplHostServer(const char* server, int port, LocServerType type) +{ + if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) { + char serverUrl[MAX_URL_LEN] = {}; + int32_t length = -1; + const char noHost[] = "NONE"; + + if ((NULL == server) || (server[0] == 0) || + (strncasecmp(noHost, server, sizeof(noHost)) == 0)) { + serverUrl[0] = '\0'; + length = 0; + } else if (port > 0) { + length = snprintf(serverUrl, sizeof(serverUrl), "%s:%u", server, port); + } + if (LOC_AGPS_SUPL_SERVER != type && LOC_AGPS_MO_SUPL_SERVER != type) { + LOC_LOGe("Invalid type=%d", type); + } else if (length >= 0) { + if (LOC_AGPS_SUPL_SERVER == type) { + getServerUrl().assign(serverUrl); + strlcpy(ContextBase::mGps_conf.SUPL_HOST, + (nullptr == server) ? serverUrl : server, + LOC_MAX_PARAM_STRING); + ContextBase::mGps_conf.SUPL_PORT = port; + } else { + if (strncasecmp(getMoServerUrl().c_str(), serverUrl, sizeof(serverUrl)) != 0) { + getMoServerUrl().assign(serverUrl); + } + } + } + } +} + +void +GnssAdapter::setConfig() +{ + LOC_LOGD("%s]: ", __func__); + + // set nmea mask type + uint32_t mask = 0; + if (NMEA_PROVIDER_MP == ContextBase::mGps_conf.NMEA_PROVIDER) { + mask |= LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK; + if (ContextBase::mGps_conf.NMEA_TAG_BLOCK_GROUPING_ENABLED) { + mask |= LOC_NMEA_MASK_TAGBLOCK_V02; + } + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) { + mask |= LOC_NMEA_MASK_DEBUG_V02; + } + if (mNmeaMask != mask) { + mNmeaMask = mask; + if (mNmeaMask) { + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if ((it->second.gnssNmeaCb != nullptr)) { + updateEvtMask(LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT, + LOC_REGISTRATION_MASK_ENABLED); + break; + } + } + } + } + + std::string oldMoServerUrl = getMoServerUrl(); + setSuplHostServer(ContextBase::mGps_conf.SUPL_HOST, + ContextBase::mGps_conf.SUPL_PORT, + LOC_AGPS_SUPL_SERVER); + setSuplHostServer(ContextBase::mGps_conf.MO_SUPL_HOST, + ContextBase::mGps_conf.MO_SUPL_PORT, + LOC_AGPS_MO_SUPL_SERVER); + + // inject the configurations into modem + loc_gps_cfg_s gpsConf = ContextBase::mGps_conf; + loc_sap_cfg_s_type sapConf = ContextBase::mSap_conf; + + //cache the injected configuration with GnssConfigRequested struct + GnssConfig gnssConfigRequested = {}; + gnssConfigRequested.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT | + GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + /* Here we process an SSR. We need to set the GPS_LOCK to the proper values, as follows: + 1. Q behavior. This is identified by mSupportNfwControl being 1. In this case + ContextBase::mGps_conf.GPS_LOCK is a "state", meaning it should reflect the + NV value. Therefore we will set the NV to ContextBase::mGps_conf.GPS_LOCK + 2. P behavior. This is identified by mSupportNfwControl being 0. In this case + ContextBase::mGps_conf.GPS_LOCK is a "configuration", meaning it should hold + the "mask" for NI. There are two subcases: + a. Location enabled in GUI (1 == getAfwControlId()). We need to set + the NV to GNSS_CONFIG_GPS_LOCK_NONE (both MO and NI enabled) + b. Location disabled in GUI (0 == getAfwControlId()). We need to set + the NV to ContextBase::mGps_conf.GPS_LOCK (the "mask", which is SIM-card + specific) + */ + if (mSupportNfwControl || (0 == getAfwControlId())) { + gnssConfigRequested.gpsLock = gpsConf.GPS_LOCK; + } else { + gnssConfigRequested.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + } + gnssConfigRequested.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT | + GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT | + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT | + GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT; + gnssConfigRequested.suplVersion = mLocApi->convertSuplVersion(gpsConf.SUPL_VER); + gnssConfigRequested.lppProfileMask = gpsConf.LPP_PROFILE; + gnssConfigRequested.aGlonassPositionProtocolMask = gpsConf.A_GLONASS_POS_PROTOCOL_SELECT; + if (gpsConf.LPPE_CP_TECHNOLOGY) { + gnssConfigRequested.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT; + gnssConfigRequested.lppeControlPlaneMask = + mLocApi->convertLppeCp(gpsConf.LPPE_CP_TECHNOLOGY); + } + + if (gpsConf.LPPE_UP_TECHNOLOGY) { + gnssConfigRequested.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT; + gnssConfigRequested.lppeUserPlaneMask = + mLocApi->convertLppeUp(gpsConf.LPPE_UP_TECHNOLOGY); + } + gnssConfigRequested.blacklistedSvIds.assign(mBlacklistedSvIds.begin(), + mBlacklistedSvIds.end()); + mLocApi->sendMsg(new LocApiMsg( + [this, gpsConf, sapConf, oldMoServerUrl, gnssConfigRequested] () mutable { + gnssUpdateConfig(oldMoServerUrl, gnssConfigRequested, gnssConfigRequested); + + // set nmea mask type + uint32_t mask = 0; + if (NMEA_PROVIDER_MP == gpsConf.NMEA_PROVIDER) { + mask |= LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK; + if (gpsConf.NMEA_TAG_BLOCK_GROUPING_ENABLED) { + mask |= LOC_NMEA_MASK_TAGBLOCK_V02; + } + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) { + mask |= LOC_NMEA_MASK_DEBUG_V02; + } + + if (mask != 0) { + mLocApi->setNMEATypesSync(mask); + } + + // load tunc configuration from config file on first boot-up, + // e.g.: adapter.mLocConfigInfo.tuncConfigInfo.isValid is false + if (mLocConfigInfo.tuncConfigInfo.isValid == false) { + mLocConfigInfo.tuncConfigInfo.isValid = true; + mLocConfigInfo.tuncConfigInfo.enable = + (gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENABLED == 1); + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs = + (float)gpsConf.CONSTRAINED_TIME_UNCERTAINTY_THRESHOLD; + mLocConfigInfo.tuncConfigInfo.energyBudget = + gpsConf.CONSTRAINED_TIME_UNCERTAINTY_ENERGY_BUDGET; + } + + mLocApi->setConstrainedTuncMode( + mLocConfigInfo.tuncConfigInfo.enable, + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs, + mLocConfigInfo.tuncConfigInfo.energyBudget); + + // load pace configuration from config file on first boot-up, + // e.g.: adapter.mLocConfigInfo.paceConfigInfo.isValid is false + if (mLocConfigInfo.paceConfigInfo.isValid == false) { + mLocConfigInfo.paceConfigInfo.isValid = true; + mLocConfigInfo.paceConfigInfo.enable = + (gpsConf.POSITION_ASSISTED_CLOCK_ESTIMATOR_ENABLED==1); + } + mLocApi->setPositionAssistedClockEstimatorMode( + mLocConfigInfo.paceConfigInfo.enable); + + // we do not support control robust location from gps.conf + if (mLocConfigInfo.robustLocationConfigInfo.isValid == true) { + mLocApi->configRobustLocation( + mLocConfigInfo.robustLocationConfigInfo.enable, + mLocConfigInfo.robustLocationConfigInfo.enableFor911); + } + + if (sapConf.GYRO_BIAS_RANDOM_WALK_VALID || + sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID || + sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) { + mLocApi->setSensorPropertiesSync( + sapConf.GYRO_BIAS_RANDOM_WALK_VALID, + sapConf.GYRO_BIAS_RANDOM_WALK, + sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, + sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, + sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, + sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY); + } + mLocApi->setSensorPerfControlConfigSync( + sapConf.SENSOR_CONTROL_MODE, + sapConf.SENSOR_ACCEL_SAMPLES_PER_BATCH, + sapConf.SENSOR_ACCEL_BATCHES_PER_SEC, + sapConf.SENSOR_GYRO_SAMPLES_PER_BATCH, + sapConf.SENSOR_GYRO_BATCHES_PER_SEC, + sapConf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, + sapConf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, + sapConf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, + sapConf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, + sapConf.SENSOR_ALGORITHM_CONFIG_MASK); + } )); + // deal with Measurement Corrections + if (true == mIsMeasCorrInterfaceOpen) { + initMeasCorr(true); + } +} + +std::vector GnssAdapter::gnssUpdateConfig(const std::string& oldMoServerUrl, + GnssConfig& gnssConfigRequested, GnssConfig& gnssConfigNeedEngineUpdate, size_t count) { + loc_gps_cfg_s gpsConf = ContextBase::mGps_conf; + size_t index = 0; + LocationError err = LOCATION_ERROR_SUCCESS; + std::vector errsList = {err}; + if (count > 0) { + errsList.insert(errsList.begin(), count, LOCATION_ERROR_SUCCESS); + } + + std::string serverUrl = getServerUrl(); + std::string moServerUrl = getMoServerUrl(); + + int serverUrlLen = serverUrl.length(); + int moServerUrlLen = moServerUrl.length(); + + if (!ContextBase::mGps_conf.AGPS_CONFIG_INJECT) { + LOC_LOGd("AGPS_CONFIG_INJECT is 0. Not setting flags for AGPS configurations"); + gnssConfigRequested.flags &= ~(GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT | + GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT | + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT | + GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT); + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + err = mLocApi->setGpsLockSync(gnssConfigRequested.gpsLock); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & + GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.assistanceServer.type == + GNSS_ASSISTANCE_TYPE_SUPL) { + err = mLocApi->setServerSync( + serverUrl.c_str(), serverUrlLen, LOC_AGPS_SUPL_SERVER); + if (index < count) { + errsList[index] = err; + } + if (0 != oldMoServerUrl.compare(moServerUrl)) { + LocationError locErr = + mLocApi->setServerSync(moServerUrl.c_str(), + moServerUrlLen, + LOC_AGPS_MO_SUPL_SERVER); + if (locErr != LOCATION_ERROR_SUCCESS) { + LOC_LOGe("Error while setting MO SUPL_HOST server:%s", + moServerUrl.c_str()); + } + } + } else if (gnssConfigNeedEngineUpdate.assistanceServer.type == + GNSS_ASSISTANCE_TYPE_C2K) { + struct in_addr addr; + struct hostent* hp; + bool resolveAddrSuccess = true; + + hp = gethostbyname( + gnssConfigNeedEngineUpdate.assistanceServer.hostName); + if (hp != NULL) { /* DNS OK */ + memcpy(&addr, hp->h_addr_list[0], hp->h_length); + } else { + /* Try IP representation */ + if (inet_aton( + gnssConfigNeedEngineUpdate.assistanceServer.hostName, + &addr) == 0) { + /* IP not valid */ + LOC_LOGE("%s]: hostname '%s' cannot be resolved ", + __func__, + gnssConfigNeedEngineUpdate.assistanceServer.hostName); + if (index < count) { + errsList[index] = LOCATION_ERROR_INVALID_PARAMETER; + } + } else { + resolveAddrSuccess = false; + } + } + + if (resolveAddrSuccess) { + unsigned int ip = htonl(addr.s_addr); + err = mLocApi->setServerSync(ip, + gnssConfigNeedEngineUpdate.assistanceServer.port, + LOC_AGPS_CDMA_PDE_SERVER); + if (index < count) { + errsList[index] = err; + } + } + } + } + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + err = mLocApi->setSUPLVersionSync(gnssConfigRequested.suplVersion); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + err = mLocApi->setLPPConfigSync(gnssConfigRequested.lppProfileMask); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + err = mLocApi->setLPPeProtocolCpSync( + gnssConfigRequested.lppeControlPlaneMask); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + err = mLocApi->setLPPeProtocolUpSync( + gnssConfigRequested.lppeUserPlaneMask); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + err = mLocApi->setAGLONASSProtocolSync( + gnssConfigRequested.aGlonassPositionProtocolMask); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + // Check if feature is supported + if (!ContextBase::isFeatureSupported( + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + LOC_LOGe("Feature constellation enablement not supported."); + err = LOCATION_ERROR_NOT_SUPPORTED; + } else { + // Send the SV ID Config to Modem + mBlacklistedSvIds.assign(gnssConfigRequested.blacklistedSvIds.begin(), + gnssConfigRequested.blacklistedSvIds.end()); + err = gnssSvIdConfigUpdateSync(gnssConfigRequested.blacklistedSvIds); + if (LOCATION_ERROR_SUCCESS != err) { + LOC_LOGe("Failed to send config to modem, err %d", err); + } + } + if (index < count) { + errsList[index] = err; + } + index++; + } + if (gnssConfigRequested.flags & + GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) { + if (gnssConfigNeedEngineUpdate.flags & + GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) { + err = mLocApi->setEmergencyExtensionWindowSync( + gnssConfigRequested.emergencyExtensionSeconds); + if (index < count) { + errsList[index] = err; + } + } + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT) { + GnssConfig gnssConfig = {}; + gnssConfig.flags = GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT; + gnssConfig.minSvElevation = gnssConfigRequested.minSvElevation; + err = mLocApi->setParameterSync(gnssConfig); + if (index < count) { + errsList[index] = err; + } + index++; + } + + return errsList; +} + +uint32_t* +GnssAdapter::gnssUpdateConfigCommand(const GnssConfig& config) +{ + // count the number of bits set + GnssConfigFlagsMask flagsCopy = config.flags; + size_t count = 0; + while (flagsCopy > 0) { + if (flagsCopy & 1) { + count++; + } + flagsCopy >>= 1; + } + std::string idsString = "["; + uint32_t* ids = NULL; + if (count > 0) { + ids = new uint32_t[count]; + if (ids == nullptr) { + LOC_LOGE("%s] new allocation failed, fatal error.", __func__); + return nullptr; + } + for (size_t i=0; i < count; ++i) { + ids[i] = generateSessionId(); + IF_LOC_LOGD { + idsString += std::to_string(ids[i]) + " "; + } + } + } + idsString += "]"; + + LOC_LOGD("%s]: ids %s flags 0x%X", __func__, idsString.c_str(), config.flags); + + struct MsgGnssUpdateConfig : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + GnssConfig mConfig; + size_t mCount; + uint32_t* mIds; + inline MsgGnssUpdateConfig(GnssAdapter& adapter, + LocApiBase& api, + GnssConfig config, + uint32_t* ids, + size_t count) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mConfig(config), + mCount(count), + mIds(nullptr) { + if (mCount > 0) { + mIds = new uint32_t[count]; + if (mIds) { + for (uint32_t index = 0; index < count; index++) { + mIds[index] = ids[index]; + } + } else { + LOC_LOGe("memory allocation for mIds failed"); + } + } + } + + inline MsgGnssUpdateConfig(const MsgGnssUpdateConfig& obj) : + MsgGnssUpdateConfig(obj.mAdapter, obj.mApi, obj.mConfig, + obj.mIds, obj.mCount) {} + + inline virtual ~MsgGnssUpdateConfig() + { + if (nullptr != mIds) delete[] mIds; + } + + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgGnssUpdateConfig(*this)); + return; + } + GnssAdapter& adapter = mAdapter; + size_t countOfConfigs = mCount; + GnssConfig gnssConfigRequested = mConfig; + GnssConfig gnssConfigNeedEngineUpdate = mConfig; + + std::vector sessionIds; + sessionIds.assign(mIds, mIds + mCount); + std::vector errs(mCount, LOCATION_ERROR_SUCCESS); + int index = 0; + bool needSuspendResume = false; + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + GnssConfigGpsLock newGpsLock = gnssConfigRequested.gpsLock; + + newGpsLock |= GNSS_CONFIG_GPS_LOCK_MO; + ContextBase::mGps_conf.GPS_LOCK = newGpsLock; + /* If we get here it means that the changes in the framework to request for + 'P' behavior were made, and therefore we need to "behave" as in 'P' + However, we need to determine if enableCommand function has already been + called, since it could get called before this function.*/ + if (0 != mAdapter.getAfwControlId()) { + /* enableCommand function has already been called since getAfwControlId + returns non zero. Now there are two possible cases: + 1. This is the first time this function is called + (mSupportNfwControl is true). We need to behave as in 'P', but + for the first time, meaning MO was enabled, but NI was not, so + we need to unlock NI + 2. This is not the first time this function is called, meaning we + are already behaving as in 'P'. No need to update the configuration + in this case (return to 'P' code) */ + if (mAdapter.mSupportNfwControl) { + // case 1 above + newGpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + } else { + // case 2 above + gnssConfigNeedEngineUpdate.flags &= ~(GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT); + } + } + gnssConfigRequested.gpsLock = newGpsLock; + mAdapter.mSupportNfwControl = false; + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + uint32_t newSuplVersion = + mAdapter.convertSuplVersion(gnssConfigRequested.suplVersion); + ContextBase::mGps_conf.SUPL_VER = newSuplVersion; + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + if (GNSS_ASSISTANCE_TYPE_SUPL == mConfig.assistanceServer.type) { + mAdapter.setSuplHostServer(mConfig.assistanceServer.hostName, + mConfig.assistanceServer.port, + LOC_AGPS_SUPL_SERVER); + } else { + LOC_LOGE("%s]: Not a valid gnss assistance type %u", + __func__, mConfig.assistanceServer.type); + errs.at(index) = LOCATION_ERROR_INVALID_PARAMETER; + gnssConfigNeedEngineUpdate.flags &= + ~(GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT); + } + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + uint32_t newLppProfileMask = gnssConfigRequested.lppProfileMask; + ContextBase::mGps_conf.LPP_PROFILE = newLppProfileMask; + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + uint32_t newLppeControlPlaneMask = + mAdapter.convertLppeCp(gnssConfigRequested.lppeControlPlaneMask); + ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY = newLppeControlPlaneMask; + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + uint32_t newLppeUserPlaneMask = + mAdapter.convertLppeUp(gnssConfigRequested.lppeUserPlaneMask); + ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY = newLppeUserPlaneMask; + index++; + } + if (gnssConfigRequested.flags & + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + uint32_t newAGloProtMask = + mAdapter.convertAGloProt(gnssConfigRequested.aGlonassPositionProtocolMask); + ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = newAGloProtMask; + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + uint32_t newEP4ES = mAdapter.convertEP4ES( + gnssConfigRequested.emergencyPdnForEmergencySupl); + if (newEP4ES != ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) { + ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = newEP4ES; + } + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + uint32_t newSuplEs = mAdapter.convertSuplEs( + gnssConfigRequested.suplEmergencyServices); + if (newSuplEs != ContextBase::mGps_conf.SUPL_ES) { + ContextBase::mGps_conf.SUPL_ES = newSuplEs; + } + index++; + } + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + uint32_t newSuplMode = mAdapter.convertSuplMode(gnssConfigRequested.suplModeMask); + ContextBase::mGps_conf.SUPL_MODE = newSuplMode; + mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); + index++; + } + + if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT) { + needSuspendResume = true; + index++; + } + + if (needSuspendResume == true) { + mAdapter.suspendSessions(); + } + LocApiCollectiveResponse *configCollectiveResponse = new LocApiCollectiveResponse( + *adapter.getContext(), + [&adapter, sessionIds, countOfConfigs] (std::vector errs) { + + std::vector ids(sessionIds); + adapter.reportResponse(countOfConfigs, errs.data(), ids.data()); + }); + + mApi.sendMsg(new LocApiMsg( + [&adapter, gnssConfigRequested, gnssConfigNeedEngineUpdate, + countOfConfigs, configCollectiveResponse, errs] () mutable { + std::vector errsList = adapter.gnssUpdateConfig("", + gnssConfigRequested, gnssConfigNeedEngineUpdate, countOfConfigs); + + configCollectiveResponse->returnToSender(errsList); + })); + + if (needSuspendResume == true) { + mAdapter.restartSessions(); + } + } + }; + + if (NULL != ids) { + sendMsg(new MsgGnssUpdateConfig(*this, *mLocApi, config, ids, count)); + } else { + LOC_LOGE("%s]: No GNSS config items to update", __func__); + } + + return ids; +} + +void +GnssAdapter::gnssSvIdConfigUpdate(const std::vector& blacklistedSvIds) +{ + // Clear the existing config + memset(&mGnssSvIdConfig, 0, sizeof(GnssSvIdConfig)); + + // Convert the sv id lists to masks + bool convertSuccess = convertToGnssSvIdConfig(blacklistedSvIds, mGnssSvIdConfig); + + // Now send to Modem if conversion successful + if (convertSuccess) { + gnssSvIdConfigUpdate(); + } else { + LOC_LOGe("convertToGnssSvIdConfig failed"); + } +} + +void +GnssAdapter::gnssSvIdConfigUpdate() +{ + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 + ", qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", navic 0x%" PRIx64, + mGnssSvIdConfig.bdsBlacklistSvMask, mGnssSvIdConfig.gloBlacklistSvMask, + mGnssSvIdConfig.qzssBlacklistSvMask, mGnssSvIdConfig.galBlacklistSvMask, + mGnssSvIdConfig.sbasBlacklistSvMask, mGnssSvIdConfig.navicBlacklistSvMask); + // Now set required blacklisted SVs + mLocApi->setBlacklistSv(mGnssSvIdConfig); +} + +LocationError +GnssAdapter::gnssSvIdConfigUpdateSync(const std::vector& blacklistedSvIds) +{ + // Clear the existing config + memset(&mGnssSvIdConfig, 0, sizeof(GnssSvIdConfig)); + + // Convert the sv id lists to masks + convertToGnssSvIdConfig(blacklistedSvIds, mGnssSvIdConfig); + + // Now send to Modem + return gnssSvIdConfigUpdateSync(); +} + +LocationError +GnssAdapter::gnssSvIdConfigUpdateSync() +{ + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 + ", qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", navic 0x%" PRIx64, + mGnssSvIdConfig.bdsBlacklistSvMask, mGnssSvIdConfig.gloBlacklistSvMask, + mGnssSvIdConfig.qzssBlacklistSvMask, mGnssSvIdConfig.galBlacklistSvMask, + mGnssSvIdConfig.sbasBlacklistSvMask, mGnssSvIdConfig.navicBlacklistSvMask); + + // Now set required blacklisted SVs + return mLocApi->setBlacklistSvSync(mGnssSvIdConfig); +} + +void +GnssAdapter::gnssSecondaryBandConfigUpdate(LocApiResponse* locApiResponse) +{ + LOC_LOGd("secondary band config, size %d, enabled constellation 0x%" PRIx64 "," + "disabled constellation 0x%" PRIx64 "", mGnssSeconaryBandConfig.size, + mGnssSeconaryBandConfig.enabledSvTypesMask, + mGnssSeconaryBandConfig.blacklistedSvTypesMask); + if (mGnssSeconaryBandConfig.size == sizeof(mGnssSeconaryBandConfig)) { + // Now set required secondary band config + mLocApi->configConstellationMultiBand(mGnssSeconaryBandConfig, locApiResponse); + } +} + +uint32_t* +GnssAdapter::gnssGetConfigCommand(GnssConfigFlagsMask configMask) { + + // count the number of bits set + GnssConfigFlagsMask flagsCopy = configMask; + size_t count = 0; + while (flagsCopy > 0) { + if (flagsCopy & 1) { + count++; + } + flagsCopy >>= 1; + } + std::string idsString = "["; + uint32_t* ids = NULL; + if (count > 0) { + ids = new uint32_t[count]; + if (nullptr == ids) { + LOC_LOGe("new allocation failed, fatal error."); + return nullptr; + } + for (size_t i=0; i < count; ++i) { + ids[i] = generateSessionId(); + IF_LOC_LOGD { + idsString += std::to_string(ids[i]) + " "; + } + } + } + idsString += "]"; + + LOC_LOGd("ids %s flags 0x%X", idsString.c_str(), configMask); + + struct MsgGnssGetConfig : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + GnssConfigFlagsMask mConfigMask; + uint32_t* mIds; + size_t mCount; + inline MsgGnssGetConfig(GnssAdapter& adapter, + LocApiBase& api, + GnssConfigFlagsMask configMask, + uint32_t* ids, + size_t count) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mConfigMask(configMask), + mCount(count), + mIds(nullptr) { + if (mCount > 0) { + mIds = new uint32_t[count]; + if (mIds) { + for (uint32_t index = 0; index < count; index++) { + mIds[index] = ids[index]; + } + } else { + LOC_LOGe("memory allocation for mIds failed"); + } + } + } + + inline MsgGnssGetConfig(const MsgGnssGetConfig& obj) : + MsgGnssGetConfig(obj.mAdapter, obj.mApi, obj.mConfigMask, + obj.mIds, obj.mCount) {} + + inline virtual ~MsgGnssGetConfig() + { + if (nullptr != mIds) delete[] mIds; + } + inline virtual void proc() const { + if (!mAdapter.isEngineCapabilitiesKnown()) { + mAdapter.mPendingMsgs.push_back(new MsgGnssGetConfig(*this)); + return; + } + LocationError* errs = new LocationError[mCount]; + LocationError err = LOCATION_ERROR_SUCCESS; + uint32_t index = 0; + + if (nullptr == errs) { + LOC_LOGE("%s] new allocation failed, fatal error.", __func__); + return; + } + + if (mConfigMask & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) { + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) { + err = LOCATION_ERROR_NOT_SUPPORTED; + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) { + // Check if feature is supported + if (!ContextBase::isFeatureSupported( + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + LOC_LOGe("Feature not supported."); + err = LOCATION_ERROR_NOT_SUPPORTED; + } else { + // Send request to Modem to fetch the config + mApi.getBlacklistSv(); + err = LOCATION_ERROR_SUCCESS; + } + if (index < mCount) { + errs[index++] = err; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) { + err = LOCATION_ERROR_NOT_SUPPORTED; + if (index < mCount) { + errs[index++] = LOCATION_ERROR_NOT_SUPPORTED; + } + } + if (mConfigMask & GNSS_CONFIG_FLAGS_ROBUST_LOCATION_BIT) { + uint32_t sessionId = *(mIds+index); + LocApiResponse* locApiResponse = + new LocApiResponse(*mAdapter.getContext(), + [this, sessionId] (LocationError err) { + mAdapter.reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + mAdapter.reportResponse(LOCATION_ERROR_GENERAL_FAILURE, sessionId); + } else { + mApi.getRobustLocationConfig(sessionId, locApiResponse); + } + } + + if (mConfigMask & GNSS_CONFIG_FLAGS_MIN_GPS_WEEK_BIT) { + uint32_t sessionId = *(mIds+index); + LocApiResponse* locApiResponse = + new LocApiResponse(*mAdapter.getContext(), + [this, sessionId] (LocationError err) { + mAdapter.reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + mAdapter.reportResponse(LOCATION_ERROR_GENERAL_FAILURE, sessionId); + } else { + mApi.getMinGpsWeek(sessionId, locApiResponse); + } + } + + if (mConfigMask & GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT) { + uint32_t sessionId = *(mIds+index); + LocApiResponse* locApiResponse = + new LocApiResponse(*mAdapter.getContext(), + [this, sessionId] (LocationError err) { + mAdapter.reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + mAdapter.reportResponse(LOCATION_ERROR_GENERAL_FAILURE, sessionId); + } else { + mApi.getParameter(sessionId, GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT, + locApiResponse); + } + } + + mAdapter.reportResponse(index, errs, mIds); + delete[] errs; + + } + }; + + if (NULL != ids) { + sendMsg(new MsgGnssGetConfig(*this, *mLocApi, configMask, ids, count)); + } else { + LOC_LOGe("No GNSS config items to Get"); + } + + return ids; +} + +bool +GnssAdapter::convertToGnssSvIdConfig( + const std::vector& blacklistedSvIds, GnssSvIdConfig& config) +{ + bool retVal = false; + config.size = sizeof(GnssSvIdConfig); + + // Empty vector => Clear any previous blacklisted SVs + if (0 == blacklistedSvIds.size()) { + config.gloBlacklistSvMask = 0; + config.bdsBlacklistSvMask = 0; + config.qzssBlacklistSvMask = 0; + config.galBlacklistSvMask = 0; + config.sbasBlacklistSvMask = 0; + config.navicBlacklistSvMask = 0; + retVal = true; + } else { + // Parse the vector and convert SV IDs to mask values + for (GnssSvIdSource source : blacklistedSvIds) { + uint64_t* svMaskPtr = NULL; + GnssSvId initialSvId = 0; + uint16_t svIndexOffset = 0; + switch(source.constellation) { + case GNSS_SV_TYPE_GLONASS: + svMaskPtr = &config.gloBlacklistSvMask; + initialSvId = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID; + break; + case GNSS_SV_TYPE_BEIDOU: + svMaskPtr = &config.bdsBlacklistSvMask; + initialSvId = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID; + break; + case GNSS_SV_TYPE_QZSS: + svMaskPtr = &config.qzssBlacklistSvMask; + initialSvId = GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID; + break; + case GNSS_SV_TYPE_GALILEO: + svMaskPtr = &config.galBlacklistSvMask; + initialSvId = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID; + break; + case GNSS_SV_TYPE_SBAS: + // SBAS does not support enable/disable whole constellation + // so do not set up svTypeMask for SBAS + svMaskPtr = &config.sbasBlacklistSvMask; + // SBAS currently has two ranges, [120, 158] and [183, 191] + if (0 == source.svId) { + LOC_LOGd("blacklist all SBAS SV"); + } else if (source.svId >= GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID) { + // handle SV id in range [183, 191] + initialSvId = GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID; + svIndexOffset = GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH; + } else if ((source.svId >= GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID) && + (source.svId < (GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID + + GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH))){ + // handle SV id in range of [120, 158] + initialSvId = GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID; + } else { + LOC_LOGe("invalid SBAS sv id %d", source.svId); + svMaskPtr = nullptr; + } + break; + case GNSS_SV_TYPE_NAVIC: + svMaskPtr = &config.navicBlacklistSvMask; + initialSvId = GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID; + break; + default: + break; + } + + if (NULL == svMaskPtr) { + LOC_LOGe("Invalid constellation %d", source.constellation); + } else { + // SV ID 0 = All SV IDs + if (0 == source.svId) { + *svMaskPtr = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } else if (source.svId < initialSvId || source.svId >= initialSvId + 64) { + LOC_LOGe("Invalid sv id %d for sv type %d", + source.svId, source.constellation); + } else { + uint32_t shiftCnt = source.svId + svIndexOffset - initialSvId; + *svMaskPtr |= (1ULL << shiftCnt); + } + } + } + + // Return true if any one source is valid + if (0 != config.gloBlacklistSvMask || + 0 != config.bdsBlacklistSvMask || + 0 != config.galBlacklistSvMask || + 0 != config.qzssBlacklistSvMask || + 0 != config.sbasBlacklistSvMask || + 0 != config.navicBlacklistSvMask) { + retVal = true; + } + } + + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 + ", qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", navic 0x%" PRIx64, + config.bdsBlacklistSvMask, config.gloBlacklistSvMask, + config.qzssBlacklistSvMask, config.galBlacklistSvMask, + config.sbasBlacklistSvMask, config.navicBlacklistSvMask); + + return retVal; +} + +void GnssAdapter::convertFromGnssSvIdConfig( + const GnssSvIdConfig& svConfig, std::vector& blacklistedSvIds) +{ + // Convert blacklisted SV mask values to vectors + if (svConfig.bdsBlacklistSvMask) { + convertGnssSvIdMaskToList( + svConfig.bdsBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_BDS_INITIAL_SV_ID, GNSS_SV_TYPE_BEIDOU); + } + if (svConfig.galBlacklistSvMask) { + convertGnssSvIdMaskToList( + svConfig.galBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_GAL_INITIAL_SV_ID, GNSS_SV_TYPE_GALILEO); + } + if (svConfig.gloBlacklistSvMask) { + convertGnssSvIdMaskToList( + svConfig.gloBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_GLO_INITIAL_SV_ID, GNSS_SV_TYPE_GLONASS); + } + if (svConfig.qzssBlacklistSvMask) { + convertGnssSvIdMaskToList( + svConfig.qzssBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID, GNSS_SV_TYPE_QZSS); + } + if (svConfig.sbasBlacklistSvMask) { + // SBAS - SV 120 to 158, maps to 0 to 38 + // SV 183 to 191, maps to 39 to 47 + uint64_t sbasBlacklistSvMask = svConfig.sbasBlacklistSvMask; + // operate on 120 and 158 first + sbasBlacklistSvMask <<= (64 - GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH); + sbasBlacklistSvMask >>= (64 - GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH); + convertGnssSvIdMaskToList( + sbasBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID, GNSS_SV_TYPE_SBAS); + // operate on the second range + sbasBlacklistSvMask = svConfig.sbasBlacklistSvMask; + sbasBlacklistSvMask >>= GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH; + convertGnssSvIdMaskToList( + sbasBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID, GNSS_SV_TYPE_SBAS); + } + if (svConfig.navicBlacklistSvMask) { + convertGnssSvIdMaskToList( + svConfig.navicBlacklistSvMask, blacklistedSvIds, + GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID, GNSS_SV_TYPE_NAVIC); + } +} + +void GnssAdapter::convertGnssSvIdMaskToList( + uint64_t svIdMask, std::vector& svIds, + GnssSvId initialSvId, GnssSvType svType) +{ + GnssSvIdSource source = {}; + source.size = sizeof(GnssSvIdSource); + source.constellation = svType; + + // SV ID 0 => All SV IDs in mask + if (GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK == svIdMask) { + LOC_LOGd("blacklist all SVs in constellation %d", source.constellation); + source.svId = 0; + svIds.push_back(source); + return; + } + + // Convert each bit in svIdMask to vector entry + uint32_t bitNumber = 0; + while (svIdMask > 0) { + if (svIdMask & 0x1) { + source.svId = bitNumber + initialSvId; + // SBAS has two ranges: + // SBAS - SV 120 to 158, maps to 0 to 38 + // SV 183 to 191, maps to 39 to 47 + // #define GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID 120 + // #define GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH 39 + // #define GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID 183 + if (svType == GNSS_SV_TYPE_SBAS) { + if (bitNumber >= GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH) { + source.svId = bitNumber - GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH + + GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID; + } + } + svIds.push_back(source); + } + bitNumber++; + svIdMask >>= 1; + } +} + +void GnssAdapter::reportGnssSvIdConfigEvent(const GnssSvIdConfig& config) +{ + struct MsgReportGnssSvIdConfig : public LocMsg { + GnssAdapter& mAdapter; + const GnssSvIdConfig mConfig; + inline MsgReportGnssSvIdConfig(GnssAdapter& adapter, + const GnssSvIdConfig& config) : + LocMsg(), + mAdapter(adapter), + mConfig(config) {} + inline virtual void proc() const { + mAdapter.reportGnssSvIdConfig(mConfig); + } + }; + + sendMsg(new MsgReportGnssSvIdConfig(*this, config)); +} + +void GnssAdapter::reportGnssSvIdConfig(const GnssSvIdConfig& svIdConfig) +{ + GnssConfig config = {}; + config.size = sizeof(GnssConfig); + + // Invoke control clients config callback + if (nullptr != mControlCallbacks.gnssConfigCb && + svIdConfig.size == sizeof(GnssSvIdConfig)) { + + convertFromGnssSvIdConfig(svIdConfig, config.blacklistedSvIds); + if (config.blacklistedSvIds.size() > 0) { + config.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT; + } + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 ", " + "qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", navic 0x%" PRIx64, + svIdConfig.bdsBlacklistSvMask, svIdConfig.gloBlacklistSvMask, + svIdConfig.qzssBlacklistSvMask, svIdConfig.galBlacklistSvMask, + svIdConfig.sbasBlacklistSvMask, svIdConfig.navicBlacklistSvMask); + // use 0 session id to indicate that receiver does not yet care about session id + mControlCallbacks.gnssConfigCb(0, config); + } else { + LOC_LOGe("Failed to report, size %d", (uint32_t)config.size); + } +} + +void +GnssAdapter::gnssUpdateSvTypeConfigCommand(GnssSvTypeConfig config) +{ + struct MsgGnssUpdateSvTypeConfig : public LocMsg { + GnssAdapter* mAdapter; + LocApiBase* mApi; + GnssSvTypeConfig mConfig; + inline MsgGnssUpdateSvTypeConfig( + GnssAdapter* adapter, + LocApiBase* api, + GnssSvTypeConfig& config) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mConfig(config) {} + inline virtual void proc() const { + if (!mAdapter->isEngineCapabilitiesKnown()) { + mAdapter->mPendingMsgs.push_back(new MsgGnssUpdateSvTypeConfig(*this)); + return; + } + // Check if feature is supported + if (!ContextBase::isFeatureSupported( + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + LOC_LOGe("Feature not supported."); + } else { + // Send update request to modem + mAdapter->gnssSvTypeConfigUpdate(mConfig); + } + } + }; + + sendMsg(new MsgGnssUpdateSvTypeConfig(this, mLocApi, config)); +} + +void +GnssAdapter::gnssSvTypeConfigUpdate(const GnssSvTypeConfig& config) +{ + // Gather bits removed from enabled mask + GnssSvTypesMask enabledRemoved = mGnssSvTypeConfig.enabledSvTypesMask & + (mGnssSvTypeConfig.enabledSvTypesMask ^ config.enabledSvTypesMask); + // Send reset if any constellation is removed from the enabled list + bool sendReset = (enabledRemoved != 0); + // Save new config and update + gnssSetSvTypeConfig(config); + gnssSvTypeConfigUpdate(sendReset); +} + +void +GnssAdapter::gnssSvTypeConfigUpdate(bool sendReset) +{ + LOC_LOGd("size %" PRIu32" constellations blacklisted 0x%" PRIx64 ", enabled 0x%" PRIx64 + ", sendReset %d", + mGnssSvTypeConfig.size, mGnssSvTypeConfig.blacklistedSvTypesMask, + mGnssSvTypeConfig.enabledSvTypesMask, sendReset); + + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 + ", qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", Navic 0x%" PRIx64, + mGnssSvIdConfig.bdsBlacklistSvMask, mGnssSvIdConfig.gloBlacklistSvMask, + mGnssSvIdConfig.qzssBlacklistSvMask, mGnssSvIdConfig.galBlacklistSvMask, + mGnssSvIdConfig.sbasBlacklistSvMask, mGnssSvIdConfig.navicBlacklistSvMask); + + LOC_LOGd("blacklist bds 0x%" PRIx64 ", glo 0x%" PRIx64 + ", qzss 0x%" PRIx64 ", gal 0x%" PRIx64 ", sbas 0x%" PRIx64 ", Navic 0x%" PRIx64, + mGnssSvIdConfig.bdsBlacklistSvMask, mGnssSvIdConfig.gloBlacklistSvMask, + mGnssSvIdConfig.qzssBlacklistSvMask, mGnssSvIdConfig.galBlacklistSvMask, + mGnssSvIdConfig.sbasBlacklistSvMask, mGnssSvIdConfig.navicBlacklistSvMask); + + if (mGnssSvTypeConfig.size == sizeof(mGnssSvTypeConfig)) { + + if (sendReset) { + mLocApi->resetConstellationControl(); + } + + GnssSvIdConfig blacklistConfig = {}; + // Revert to previously blacklisted SVs for each enabled constellation + blacklistConfig = mGnssSvIdConfig; + // Blacklist all SVs for each disabled constellation + if (mGnssSvTypeConfig.blacklistedSvTypesMask) { + if (mGnssSvTypeConfig.blacklistedSvTypesMask & GNSS_SV_TYPES_MASK_GLO_BIT) { + blacklistConfig.gloBlacklistSvMask = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } + if (mGnssSvTypeConfig.blacklistedSvTypesMask & GNSS_SV_TYPES_MASK_BDS_BIT) { + blacklistConfig.bdsBlacklistSvMask = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } + if (mGnssSvTypeConfig.blacklistedSvTypesMask & GNSS_SV_TYPES_MASK_QZSS_BIT) { + blacklistConfig.qzssBlacklistSvMask = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } + if (mGnssSvTypeConfig.blacklistedSvTypesMask & GNSS_SV_TYPES_MASK_GAL_BIT) { + blacklistConfig.galBlacklistSvMask = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } + if (mGnssSvTypeConfig.blacklistedSvTypesMask & GNSS_SV_TYPES_MASK_NAVIC_BIT) { + blacklistConfig.navicBlacklistSvMask = GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK; + } + } + + // Send blacklist info + mLocApi->setBlacklistSv(blacklistConfig); + + // Send only enabled constellation config + if (mGnssSvTypeConfig.enabledSvTypesMask) { + GnssSvTypeConfig svTypeConfig = {sizeof(GnssSvTypeConfig), 0, 0}; + svTypeConfig.enabledSvTypesMask = mGnssSvTypeConfig.enabledSvTypesMask; + mLocApi->setConstellationControl(svTypeConfig); + } + } +} + +void +GnssAdapter::gnssGetSvTypeConfigCommand(GnssSvTypeConfigCallback callback) +{ + struct MsgGnssGetSvTypeConfig : public LocMsg { + GnssAdapter* mAdapter; + LocApiBase* mApi; + GnssSvTypeConfigCallback mCallback; + inline MsgGnssGetSvTypeConfig( + GnssAdapter* adapter, + LocApiBase* api, + GnssSvTypeConfigCallback callback) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mCallback(callback) {} + inline virtual void proc() const { + if (!mAdapter->isEngineCapabilitiesKnown()) { + mAdapter->mPendingMsgs.push_back(new MsgGnssGetSvTypeConfig(*this)); + return; + } + if (!ContextBase::isFeatureSupported( + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + LOC_LOGe("Feature not supported."); + } else { + // Save the callback + mAdapter->gnssSetSvTypeConfigCallback(mCallback); + // Send GET request to modem + mApi->getConstellationControl(); + } + } + }; + + sendMsg(new MsgGnssGetSvTypeConfig(this, mLocApi, callback)); +} + +void +GnssAdapter::gnssResetSvTypeConfigCommand() +{ + struct MsgGnssResetSvTypeConfig : public LocMsg { + GnssAdapter* mAdapter; + LocApiBase* mApi; + inline MsgGnssResetSvTypeConfig( + GnssAdapter* adapter, + LocApiBase* api) : + LocMsg(), + mAdapter(adapter), + mApi(api) {} + inline virtual void proc() const { + if (!mAdapter->isEngineCapabilitiesKnown()) { + mAdapter->mPendingMsgs.push_back(new MsgGnssResetSvTypeConfig(*this)); + return; + } + if (!ContextBase::isFeatureSupported( + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + LOC_LOGe("Feature not supported."); + } else { + // Reset constellation config + mAdapter->gnssSetSvTypeConfig({sizeof(GnssSvTypeConfig), 0, 0}); + // Re-enforce SV blacklist config + mAdapter->gnssSvIdConfigUpdate(); + // Send reset request to modem + mApi->resetConstellationControl(); + } + } + }; + + sendMsg(new MsgGnssResetSvTypeConfig(this, mLocApi)); +} + +void GnssAdapter::reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& config) +{ + struct MsgReportGnssSvTypeConfig : public LocMsg { + GnssAdapter& mAdapter; + const GnssSvTypeConfig mConfig; + inline MsgReportGnssSvTypeConfig(GnssAdapter& adapter, + const GnssSvTypeConfig& config) : + LocMsg(), + mAdapter(adapter), + mConfig(config) {} + inline virtual void proc() const { + mAdapter.reportGnssSvTypeConfig(mConfig); + } + }; + + sendMsg(new MsgReportGnssSvTypeConfig(*this, config)); +} + +void GnssAdapter::reportGnssSvTypeConfig(const GnssSvTypeConfig& config) +{ + // Invoke Get SV Type Callback + if (NULL != mGnssSvTypeConfigCb && + config.size == sizeof(GnssSvTypeConfig)) { + LOC_LOGd("constellations blacklisted 0x%" PRIx64 ", enabled 0x%" PRIx64, + config.blacklistedSvTypesMask, config.enabledSvTypesMask); + mGnssSvTypeConfigCb(config); + } else { + LOC_LOGe("Failed to report, size %d", (uint32_t)config.size); + } +} + +void GnssAdapter::deleteAidingData(const GnssAidingData &data, uint32_t sessionId) { + struct timespec bootDeleteAidingDataTime; + int64_t bootDeleteTimeMs; + if (clock_gettime(CLOCK_BOOTTIME, &bootDeleteAidingDataTime) == 0) { + bootDeleteTimeMs = bootDeleteAidingDataTime.tv_sec * 1000000; + int64_t diffTimeBFirSecDelete = bootDeleteTimeMs - mLastDeleteAidingDataTime; + if (diffTimeBFirSecDelete > DELETE_AIDING_DATA_EXPECTED_TIME_MS) { + mLocApi->deleteAidingData(data, new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId); + })); + mLastDeleteAidingDataTime = bootDeleteTimeMs; + } + } +} + +uint32_t +GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data) +{ + uint32_t sessionId = generateSessionId(); + LOC_LOGD("%s]: id %u", __func__, sessionId); + + struct MsgDeleteAidingData : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + GnssAidingData mData; + inline MsgDeleteAidingData(GnssAdapter& adapter, + uint32_t sessionId, + GnssAidingData& data) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mData(data) {} + inline virtual void proc() const { + if ((mData.posEngineMask & STANDARD_POSITIONING_ENGINE) != 0) { + mAdapter.deleteAidingData(mData, mSessionId); + SystemStatus* s = mAdapter.getSystemStatus(); + if ((nullptr != s) && (mData.deleteAll)) { + s->setDefaultGnssEngineStates(); + } + } + + bool retVal = mAdapter.mEngHubProxy->gnssDeleteAidingData(mData); + // When SPE engine is invoked, responseCb will be invoked + // from QMI Loc API call. + // When SPE engine is not invoked, we also need to deliver responseCb + if ((mData.posEngineMask & STANDARD_POSITIONING_ENGINE) == 0) { + LocationError err = LOCATION_ERROR_NOT_SUPPORTED; + if (retVal == true) { + err = LOCATION_ERROR_SUCCESS; + } + mAdapter.reportResponse(err, mSessionId); + } + } + }; + + sendMsg(new MsgDeleteAidingData(*this, sessionId, data)); + return sessionId; +} + +void +GnssAdapter::gnssUpdateXtraThrottleCommand(const bool enabled) +{ + LOC_LOGD("%s] enabled:%d", __func__, enabled); + + struct UpdateXtraThrottleMsg : public LocMsg { + GnssAdapter& mAdapter; + const bool mEnabled; + inline UpdateXtraThrottleMsg(GnssAdapter& adapter, const bool enabled) : + LocMsg(), + mAdapter(adapter), + mEnabled(enabled) {} + inline virtual void proc() const { + mAdapter.mXtraObserver.updateXtraThrottle(mEnabled); + } + }; + + sendMsg(new UpdateXtraThrottleMsg(*this, enabled)); +} + +void +GnssAdapter::injectLocationCommand(double latitude, double longitude, float accuracy) +{ + LOC_LOGD("%s]: latitude %8.4f longitude %8.4f accuracy %8.4f", + __func__, latitude, longitude, accuracy); + + struct MsgInjectLocation : public LocMsg { + LocApiBase& mApi; + ContextBase& mContext; + BlockCPIInfo& mBlockCPI; + double mLatitude; + double mLongitude; + float mAccuracy; + bool mOnDemandCpi; + inline MsgInjectLocation(LocApiBase& api, + ContextBase& context, + BlockCPIInfo& blockCPIInfo, + double latitude, + double longitude, + float accuracy, + bool onDemandCpi) : + LocMsg(), + mApi(api), + mContext(context), + mBlockCPI(blockCPIInfo), + mLatitude(latitude), + mLongitude(longitude), + mAccuracy(accuracy), + mOnDemandCpi(onDemandCpi) {} + inline virtual void proc() const { + if ((uptimeMillis() <= mBlockCPI.blockedTillTsMs) && + (fabs(mLatitude-mBlockCPI.latitude) <= mBlockCPI.latLonDiffThreshold) && + (fabs(mLongitude-mBlockCPI.longitude) <= mBlockCPI.latLonDiffThreshold)) { + + LOC_LOGD("%s]: positon injection blocked: lat: %f, lon: %f, accuracy: %f", + __func__, mLatitude, mLongitude, mAccuracy); + + } else { + mApi.injectPosition(mLatitude, mLongitude, mAccuracy, mOnDemandCpi); + } + } + }; + + sendMsg(new MsgInjectLocation(*mLocApi, *mContext, mBlockCPIInfo, + latitude, longitude, accuracy, mOdcpiRequestActive)); +} + +void +GnssAdapter::injectLocationExtCommand(const GnssLocationInfoNotification &locationInfo) +{ + LOC_LOGd("latitude %8.4f longitude %8.4f accuracy %8.4f, tech mask 0x%x", + locationInfo.location.latitude, locationInfo.location.longitude, + locationInfo.location.accuracy, locationInfo.location.techMask); + + struct MsgInjectLocationExt : public LocMsg { + LocApiBase& mApi; + ContextBase& mContext; + GnssLocationInfoNotification mLocationInfo; + inline MsgInjectLocationExt(LocApiBase& api, + ContextBase& context, + GnssLocationInfoNotification locationInfo) : + LocMsg(), + mApi(api), + mContext(context), + mLocationInfo(locationInfo) {} + inline virtual void proc() const { + // false to indicate for none-ODCPI + mApi.injectPosition(mLocationInfo, false); + } + }; + + sendMsg(new MsgInjectLocationExt(*mLocApi, *mContext, locationInfo)); +} + +void +GnssAdapter::injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty) +{ + LOC_LOGD("%s]: time %lld timeReference %lld uncertainty %d", + __func__, (long long)time, (long long)timeReference, uncertainty); + + struct MsgInjectTime : public LocMsg { + LocApiBase& mApi; + ContextBase& mContext; + int64_t mTime; + int64_t mTimeReference; + int32_t mUncertainty; + inline MsgInjectTime(LocApiBase& api, + ContextBase& context, + int64_t time, + int64_t timeReference, + int32_t uncertainty) : + LocMsg(), + mApi(api), + mContext(context), + mTime(time), + mTimeReference(timeReference), + mUncertainty(uncertainty) {} + inline virtual void proc() const { + mApi.setTime(mTime, mTimeReference, mUncertainty); + } + }; + + sendMsg(new MsgInjectTime(*mLocApi, *mContext, time, timeReference, uncertainty)); +} + +// This command is to called to block the position to be injected to the modem. +// This can happen for network position that comes from modem. +void +GnssAdapter::blockCPICommand(double latitude, double longitude, + float accuracy, int blockDurationMsec, + double latLonDiffThreshold) +{ + struct MsgBlockCPI : public LocMsg { + BlockCPIInfo& mDstCPIInfo; + BlockCPIInfo mSrcCPIInfo; + + inline MsgBlockCPI(BlockCPIInfo& dstCPIInfo, + BlockCPIInfo& srcCPIInfo) : + mDstCPIInfo(dstCPIInfo), + mSrcCPIInfo(srcCPIInfo) {} + inline virtual void proc() const { + // in the same hal thread, save the cpi to be blocked + // the global variable + mDstCPIInfo = mSrcCPIInfo; + } + }; + + // construct the new block CPI info and queue on the same thread + // for processing + BlockCPIInfo blockCPIInfo; + blockCPIInfo.latitude = latitude; + blockCPIInfo.longitude = longitude; + blockCPIInfo.accuracy = accuracy; + blockCPIInfo.blockedTillTsMs = uptimeMillis() + blockDurationMsec; + blockCPIInfo.latLonDiffThreshold = latLonDiffThreshold; + + LOC_LOGD("%s]: block CPI lat: %f, lon: %f ", __func__, latitude, longitude); + // send a message to record down the coarse position + // to be blocked from injection in the master copy (mBlockCPIInfo) + sendMsg(new MsgBlockCPI(mBlockCPIInfo, blockCPIInfo)); +} + +void +GnssAdapter::updateSystemPowerState(PowerStateType systemPowerState) { + if (POWER_STATE_UNKNOWN != systemPowerState) { + mSystemPowerState = systemPowerState; + mLocApi->updateSystemPowerState(mSystemPowerState); + } +} + +void +GnssAdapter::updateSystemPowerStateCommand(PowerStateType systemPowerState) { + LOC_LOGd("power event %d", systemPowerState); + + struct MsgUpdatePowerState : public LocMsg { + GnssAdapter& mAdapter; + PowerStateType mSystemPowerState; + + inline MsgUpdatePowerState(GnssAdapter& adapter, + PowerStateType systemPowerState) : + LocMsg(), + mAdapter(adapter), + mSystemPowerState(systemPowerState) {} + inline virtual void proc() const { + mAdapter.updateSystemPowerState(mSystemPowerState); + } + }; + + sendMsg(new MsgUpdatePowerState(*this, systemPowerState)); +} + +void +GnssAdapter::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + struct MsgAddClient : public LocMsg { + GnssAdapter& mAdapter; + LocationAPI* mClient; + const LocationCallbacks mCallbacks; + inline MsgAddClient(GnssAdapter& adapter, + LocationAPI* client, + const LocationCallbacks& callbacks) : + LocMsg(), + mAdapter(adapter), + mClient(client), + mCallbacks(callbacks) {} + inline virtual void proc() const { + // check whether we need to notify client of cached location system info + mAdapter.notifyClientOfCachedLocationSystemInfo(mClient, mCallbacks); + mAdapter.saveClient(mClient, mCallbacks); + } + }; + + sendMsg(new MsgAddClient(*this, client, callbacks)); +} + +void +GnssAdapter::stopClientSessions(LocationAPI* client) +{ + LOC_LOGD("%s]: client %p", __func__, client); + + /* Time-based Tracking */ + std::vector vTimeBasedTrackingClient; + for (auto it : mTimeBasedTrackingSessions) { + if (client == it.first.client) { + vTimeBasedTrackingClient.emplace_back(it.first.client, it.first.id); + } + } + for (auto key : vTimeBasedTrackingClient) { + stopTimeBasedTrackingMultiplex(key.client, key.id); + eraseTrackingSession(key.client, key.id); + } + + /* Distance-based Tracking */ + for (auto it = mDistanceBasedTrackingSessions.begin(); + it != mDistanceBasedTrackingSessions.end(); /* no increment here*/) { + if (client == it->first.client) { + mLocApi->stopDistanceBasedTracking(it->first.id, new LocApiResponse(*getContext(), + [this, client, id=it->first.id] (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + eraseTrackingSession(client, id); + } + } + )); + } + ++it; // increment only when not erasing an iterator + } + +} + +void +GnssAdapter::updateClientsEventMask() +{ + // need to register for leap second info + // for proper nmea generation + LOC_API_ADAPTER_EVENT_MASK_T mask = LOC_API_ADAPTER_BIT_LOC_SYSTEM_INFO | + LOC_API_ADAPTER_BIT_EVENT_REPORT_INFO; + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (it->second.trackingCb != nullptr || + it->second.gnssLocationInfoCb != nullptr || + it->second.engineLocationsInfoCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT; + } + if (it->second.gnssSvCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_SATELLITE_REPORT; + } + if ((it->second.gnssNmeaCb != nullptr) && (mNmeaMask)) { + mask |= LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; + } + if (it->second.gnssMeasurementsCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; + } + if (it->second.gnssDataCb != nullptr) { + mask |= LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT; + mask |= LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; + updateNmeaMask(mNmeaMask | LOC_NMEA_MASK_DEBUG_V02); + } + } + + /* + ** For Automotive use cases we need to enable MEASUREMENT, POLY and EPHEMERIS + ** when QDR is enabled (e.g.: either enabled via conf file or + ** engine hub is loaded successfully). + ** Note: this need to be called from msg queue thread. + */ + if((1 == ContextBase::mGps_conf.EXTERNAL_DR_ENABLED) || + (true == initEngHubProxy())) { + mask |= LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT; + mask |= LOC_API_ADAPTER_BIT_GNSS_SV_POLYNOMIAL_REPORT; + mask |= LOC_API_ADAPTER_BIT_PARSED_UNPROPAGATED_POSITION_REPORT; + mask |= LOC_API_ADAPTER_BIT_GNSS_SV_EPHEMERIS_REPORT; + + // Nhz measurement bit is set based on callback from loc eng hub + // for Nhz engines. + mask |= checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT); + + LOC_LOGd("Auto usecase, Enable MEAS/POLY/EPHEMERIS - mask 0x%" PRIx64 "", + mask); + } + + if (mAgpsManager.isRegistered()) { + mask |= LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST; + } + // Add ODCPI handling + if (nullptr != mOdcpiRequestCb) { + mask |= LOC_API_ADAPTER_BIT_REQUEST_WIFI; + } + + // need to register for leap second info + // for proper nmea generation + mask |= LOC_API_ADAPTER_BIT_LOC_SYSTEM_INFO; + + // always register for NI NOTIFY VERIFY to handle internally in HAL + mask |= LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; + + // Enable the latency report + if (mask & LOC_API_ADAPTER_BIT_GNSS_MEASUREMENT) { + if (mLogger.isLogEnabled()) { + mask |= LOC_API_ADAPTER_BIT_LATENCY_INFORMATION; + } + } + + updateEvtMask(mask, LOC_REGISTRATION_MASK_SET); +} + +void +GnssAdapter::handleEngineUpEvent() +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgHandleEngineUpEvent : public LocMsg { + GnssAdapter& mAdapter; + inline MsgHandleEngineUpEvent(GnssAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + virtual void proc() const { + mAdapter.setEngineCapabilitiesKnown(true); + mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); + // must be called only after capabilities are known + mAdapter.setConfig(); + mAdapter.gnssSvIdConfigUpdate(); + mAdapter.gnssSvTypeConfigUpdate(); + mAdapter.updateSystemPowerState(mAdapter.getSystemPowerState()); + mAdapter.gnssSecondaryBandConfigUpdate(); + // start CDFW service + mAdapter.initCDFWService(); + // restart sessions + mAdapter.restartSessions(true); + for (auto msg: mAdapter.mPendingMsgs) { + mAdapter.sendMsg(msg); + } + mAdapter.mPendingMsgs.clear(); + } + }; + + readConfigCommand(); + sendMsg(new MsgHandleEngineUpEvent(*this)); +} + +void +GnssAdapter::restartSessions(bool modemSSR) +{ + LOC_LOGi(":enter"); + + if (modemSSR) { + // odcpi session is no longer active after restart + mOdcpiRequestActive = false; + } + + // SPE will be restarted now, so set this variable to false. + mSPEAlreadyRunningAtHighestInterval = false; + + if (false == mTimeBasedTrackingSessions.empty()) { + // inform engine hub that GNSS session is about to start + mEngHubProxy->gnssSetFixMode(mLocPositionMode); + mEngHubProxy->gnssStartFix(); + checkUpdateDgnssNtrip(false); + } + + checkAndRestartSPESession(); +} + +void GnssAdapter::checkAndRestartSPESession() +{ + LOC_LOGD("%s]: ", __func__); + + // SPE will be restarted now, so set this variable to false. + mSPEAlreadyRunningAtHighestInterval = false; + + checkAndRestartTimeBasedSession(); + + for (auto it = mDistanceBasedTrackingSessions.begin(); + it != mDistanceBasedTrackingSessions.end(); ++it) { + mLocApi->startDistanceBasedTracking(it->first.id, it->second, + new LocApiResponse(*getContext(), + [] (LocationError /*err*/) {})); + } +} + +// suspend all on-going sessions +void +GnssAdapter::suspendSessions() +{ + LOC_LOGi(":enter"); + + if (!mTimeBasedTrackingSessions.empty()) { + // inform engine hub that GNSS session has stopped + mEngHubProxy->gnssStopFix(); + mLocApi->stopFix(nullptr); + if (isDgnssNmeaRequired()) { + mDgnssState &= ~DGNSS_STATE_NO_NMEA_PENDING; + } + stopDgnssNtrip(); + mSPEAlreadyRunningAtHighestInterval = false; + } +} + +void GnssAdapter::checkAndRestartTimeBasedSession() +{ + LOC_LOGD("%s]: ", __func__); + + if (!mTimeBasedTrackingSessions.empty()) { + // get the LocationOptions that has the smallest interval, which should be the active one + TrackingOptions smallestIntervalOptions; // size is zero until set for the first time + TrackingOptions highestPowerTrackingOptions; + memset(&smallestIntervalOptions, 0, sizeof(smallestIntervalOptions)); + memset(&highestPowerTrackingOptions, 0, sizeof(highestPowerTrackingOptions)); + for (auto it = mTimeBasedTrackingSessions.begin(); + it != mTimeBasedTrackingSessions.end(); ++it) { + // size of zero means we havent set it yet + if (0 == smallestIntervalOptions.size || + it->second.minInterval < smallestIntervalOptions.minInterval) { + smallestIntervalOptions = it->second; + } + GnssPowerMode powerMode = it->second.powerMode; + // Size of zero means we havent set it yet + if (0 == highestPowerTrackingOptions.size || + (GNSS_POWER_MODE_INVALID != powerMode && + powerMode < highestPowerTrackingOptions.powerMode)) { + highestPowerTrackingOptions = it->second; + } + } + + highestPowerTrackingOptions.setLocationOptions(smallestIntervalOptions); + // want to run SPE session at a fixed min interval in some automotive scenarios + if(!checkAndSetSPEToRunforNHz(highestPowerTrackingOptions)) { + mLocApi->startTimeBasedTracking(highestPowerTrackingOptions, nullptr); + } + } +} + +LocationCapabilitiesMask +GnssAdapter::getCapabilities() +{ + LocationCapabilitiesMask mask = 0; + uint32_t carrierCapabilities = ContextBase::getCarrierCapabilities(); + // time based tracking always supported + mask |= LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT; + // geofence always supported + mask |= LOCATION_CAPABILITIES_GEOFENCE_BIT; + if (carrierCapabilities & LOC_GPS_CAPABILITY_MSB) { + mask |= LOCATION_CAPABILITIES_GNSS_MSB_BIT; + } + if (LOC_GPS_CAPABILITY_MSA & carrierCapabilities) { + mask |= LOCATION_CAPABILITIES_GNSS_MSA_BIT; + } + if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)) { + mask |= LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT | + LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT; + } + if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) { + mask |= LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT; + } + if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING)) { + mask |= LOCATION_CAPABILITIES_OUTDOOR_TRIP_BATCHING_BIT; + } + if (ContextBase::gnssConstellationConfig()) { + mask |= LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) { + mask |= LOCATION_CAPABILITIES_DEBUG_NMEA_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02)) { + mask |= LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT; + } + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_AGPM_V02)) { + mask |= LOCATION_CAPABILITIES_AGPM_BIT; + } + //Get QWES feature status mask + mask |= ContextBase::getQwesFeatureStatus(); + return mask; +} + +void +GnssAdapter::notifyClientOfCachedLocationSystemInfo( + LocationAPI* client, const LocationCallbacks& callbacks) { + + if (mLocSystemInfo.systemInfoMask) { + // client need to be notified if client has not yet previously registered + // for the info but now register for it. + bool notifyClientOfSystemInfo = false; + // check whether we need to notify client of cached location system info + // + // client need to be notified if client has not yet previously registered + // for the info but now register for it. + if (callbacks.locationSystemInfoCb) { + notifyClientOfSystemInfo = true; + auto it = mClientData.find(client); + if (it != mClientData.end()) { + LocationCallbacks oldCallbacks = it->second; + if (oldCallbacks.locationSystemInfoCb) { + notifyClientOfSystemInfo = false; + } + } + } + + if (notifyClientOfSystemInfo) { + callbacks.locationSystemInfoCb(mLocSystemInfo); + } + } +} + +bool +GnssAdapter::isTimeBasedTrackingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + return (mTimeBasedTrackingSessions.find(key) != mTimeBasedTrackingSessions.end()); +} + +bool +GnssAdapter::isDistanceBasedTrackingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + return (mDistanceBasedTrackingSessions.find(key) != mDistanceBasedTrackingSessions.end()); +} + +bool +GnssAdapter::hasCallbacksToStartTracking(LocationAPI* client) +{ + bool allowed = false; + auto it = mClientData.find(client); + if (it != mClientData.end()) { + if (it->second.trackingCb || it->second.gnssLocationInfoCb || + it->second.engineLocationsInfoCb || it->second.gnssMeasurementsCb || + it->second.gnssDataCb || it->second.gnssSvCb || it->second.gnssNmeaCb) { + allowed = true; + } else { + LOC_LOGi("missing right callback to start tracking") + } + } else { + LOC_LOGi("client %p not found", client) + } + return allowed; +} + +bool +GnssAdapter::isTrackingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + return (mTimeBasedTrackingSessions.find(key) != mTimeBasedTrackingSessions.end()); +} + +void +GnssAdapter::reportPowerStateIfChanged() +{ + bool newPowerOn = !mTimeBasedTrackingSessions.empty() || + !mDistanceBasedTrackingSessions.empty(); + if (newPowerOn != mPowerOn) { + mPowerOn = newPowerOn; + if (mPowerStateCb != nullptr) { + mPowerStateCb(mPowerOn); + } + } +} + +void +GnssAdapter::getPowerStateChangesCommand(std::function powerStateCb) +{ + LOC_LOGD("%s]: ", __func__); + + struct MsgReportLocation : public LocMsg { + GnssAdapter& mAdapter; + std::function mPowerStateCb; + inline MsgReportLocation(GnssAdapter& adapter, + std::function powerStateCb) : + LocMsg(), + mAdapter(adapter), + mPowerStateCb(powerStateCb) {} + inline virtual void proc() const { + mAdapter.savePowerStateCallback(mPowerStateCb); + mPowerStateCb(mAdapter.getPowerState()); + } + }; + + sendMsg(new MsgReportLocation(*this, powerStateCb)); +} + +void +GnssAdapter::saveTrackingSession(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& options) +{ + LocationSessionKey key(client, sessionId); + if ((options.minDistance > 0) && + ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) { + mDistanceBasedTrackingSessions[key] = options; + } else { + mTimeBasedTrackingSessions[key] = options; + } + reportPowerStateIfChanged(); +} + +void +GnssAdapter::eraseTrackingSession(LocationAPI* client, uint32_t sessionId) +{ + LocationSessionKey key(client, sessionId); + auto it = mTimeBasedTrackingSessions.find(key); + if (it != mTimeBasedTrackingSessions.end()) { + mTimeBasedTrackingSessions.erase(it); + } else { + auto itr = mDistanceBasedTrackingSessions.find(key); + if (itr != mDistanceBasedTrackingSessions.end()) { + mDistanceBasedTrackingSessions.erase(itr); + } + } + reportPowerStateIfChanged(); +} + +bool GnssAdapter::setLocPositionMode(const LocPosMode& mode) { + if (!mLocPositionMode.equals(mode)) { + mLocPositionMode = mode; + return true; + } else { + return false; + } +} + +void +GnssAdapter::reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId) +{ + LOC_LOGD("%s]: client %p id %u err %u", __func__, client, sessionId, err); + + auto it = mClientData.find(client); + if (it != mClientData.end() && it->second.responseCb != nullptr) { + it->second.responseCb(err, sessionId); + } else { + LOC_LOGW("%s]: client %p id %u not found in data", __func__, client, sessionId); + } +} + +void +GnssAdapter::reportResponse(LocationError err, uint32_t sessionId) +{ + LOC_LOGD("%s]: id %u err %u", __func__, sessionId, err); + + if (mControlCallbacks.size > 0 && mControlCallbacks.responseCb != nullptr) { + mControlCallbacks.responseCb(err, sessionId); + } else { + LOC_LOGW("%s]: control client response callback not found", __func__); + } +} + +void +GnssAdapter::reportResponse(size_t count, LocationError* errs, uint32_t* ids) +{ + IF_LOC_LOGD { + std::string idsString = "["; + std::string errsString = "["; + if (NULL != ids && NULL != errs) { + for (size_t i=0; i < count; ++i) { + idsString += std::to_string(ids[i]) + " "; + errsString += std::to_string(errs[i]) + " "; + } + } + idsString += "]"; + errsString += "]"; + + LOC_LOGD("%s]: ids %s errs %s", + __func__, idsString.c_str(), errsString.c_str()); + } + + if (mControlCallbacks.size > 0 && mControlCallbacks.collectiveResponseCb != nullptr) { + mControlCallbacks.collectiveResponseCb(count, errs, ids); + } else { + LOC_LOGW("%s]: control client callback not found", __func__); + } +} + +uint32_t +GnssAdapter::startTrackingCommand(LocationAPI* client, TrackingOptions& options) +{ + uint32_t sessionId = generateSessionId(); + LOC_LOGD("%s]: client %p id %u minInterval %u minDistance %u mode %u powermode %u tbm %u", + __func__, client, sessionId, options.minInterval, options.minDistance, options.mode, + options.powerMode, options.tbm); + + struct MsgStartTracking : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + mutable TrackingOptions mOptions; + inline MsgStartTracking(GnssAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId, + TrackingOptions options) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId), + mOptions(options) {} + inline virtual void proc() const { + // distance based tracking will need to know engine capabilities before it can start + if (!mAdapter.isEngineCapabilitiesKnown() && mOptions.minDistance > 0) { + mAdapter.mPendingMsgs.push_back(new MsgStartTracking(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + if (!mAdapter.hasCallbacksToStartTracking(mClient)) { + err = LOCATION_ERROR_CALLBACK_MISSING; + } else if (0 == mOptions.size) { + err = LOCATION_ERROR_INVALID_PARAMETER; + } else { + if (mOptions.minInterval < MIN_TRACKING_INTERVAL) { + mOptions.minInterval = MIN_TRACKING_INTERVAL; + } + if (mOptions.minDistance > 0 && + ContextBase::isMessageSupported( + LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) { + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + mApi.startDistanceBasedTracking(mSessionId, mOptions, + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, mClient = mClient] + (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + mAdapter.eraseTrackingSession(mClient, mSessionId); + } + mAdapter.reportResponse(mClient, err, mSessionId); + })); + } else { + if (GNSS_POWER_MODE_M4 == mOptions.powerMode && + mOptions.tbm > TRACKING_TBM_THRESHOLD_MILLIS) { + LOC_LOGd("TBM (%d) > %d Falling back to M2 power mode", + mOptions.tbm, TRACKING_TBM_THRESHOLD_MILLIS); + mOptions.powerMode = GNSS_POWER_MODE_M2; + } + // Api doesn't support multiple clients for time based tracking, so mutiplex + bool reportToClientWithNoWait = + mAdapter.startTimeBasedTrackingMultiplex(mClient, mSessionId, mOptions); + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + + if (reportToClientWithNoWait) { + mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId); + } + } + } + } + }; + + sendMsg(new MsgStartTracking(*this, *mLocApi, client, sessionId, options)); + return sessionId; + +} + +bool +GnssAdapter::startTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& options) +{ + bool reportToClientWithNoWait = true; + + if (mTimeBasedTrackingSessions.empty()) { + /*Reset previous NMEA reported time stamp */ + mPrevNmeaRptTimeNsec = 0; + startTimeBasedTracking(client, sessionId, options); + // need to wait for QMI callback + reportToClientWithNoWait = false; + } else { + // find the smallest interval and powerMode + TrackingOptions multiplexedOptions = {}; // size is 0 until set for the first time + GnssPowerMode multiplexedPowerMode = GNSS_POWER_MODE_INVALID; + memset(&multiplexedOptions, 0, sizeof(multiplexedOptions)); + for (auto it = mTimeBasedTrackingSessions.begin(); it != mTimeBasedTrackingSessions.end(); ++it) { + // if not set or there is a new smallest interval, then set the new interval + if (0 == multiplexedOptions.size || + it->second.minInterval < multiplexedOptions.minInterval) { + multiplexedOptions = it->second; + } + // if session is not the one we are updating and either powerMode + // is not set or there is a new smallest powerMode, then set the new powerMode + if (GNSS_POWER_MODE_INVALID == multiplexedPowerMode || + it->second.powerMode < multiplexedPowerMode) { + multiplexedPowerMode = it->second.powerMode; + } + } + bool updateOptions = false; + // if session we are starting has smaller interval then next smallest + if (options.minInterval < multiplexedOptions.minInterval) { + multiplexedOptions.minInterval = options.minInterval; + updateOptions = true; + } + + // if session we are starting has smaller powerMode then next smallest + if (options.powerMode < multiplexedPowerMode) { + multiplexedOptions.powerMode = options.powerMode; + updateOptions = true; + } + if (updateOptions) { + // restart time based tracking with the newly updated options + + startTimeBasedTracking(client, sessionId, multiplexedOptions); + // need to wait for QMI callback + reportToClientWithNoWait = false; + } + // else part: no QMI call is made, need to report back to client right away + } + + return reportToClientWithNoWait; +} + +void +GnssAdapter::startTimeBasedTracking(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& trackingOptions) +{ + LOC_LOGd("minInterval %u minDistance %u mode %u powermode %u tbm %u", + trackingOptions.minInterval, trackingOptions.minDistance, + trackingOptions.mode, trackingOptions.powerMode, trackingOptions.tbm); + LocPosMode locPosMode = {}; + convertOptions(locPosMode, trackingOptions); + // save position mode parameters + setLocPositionMode(locPosMode); + // inform engine hub that GNSS session is about to start + mEngHubProxy->gnssSetFixMode(mLocPositionMode); + mEngHubProxy->gnssStartFix(); + + // want to run SPE session at a fixed min interval in some automotive scenarios + // use a local copy of TrackingOptions as the TBF may get modified in the + // checkAndSetSPEToRunforNHz function + TrackingOptions tempOptions(trackingOptions); + if (!checkAndSetSPEToRunforNHz(tempOptions)) { + mLocApi->startTimeBasedTracking(tempOptions, new LocApiResponse(*getContext(), + [this, client, sessionId] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + eraseTrackingSession(client, sessionId); + } else { + checkUpdateDgnssNtrip(false); + } + + reportResponse(client, err, sessionId); + } + )); + } else { + reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId); + } + +} + +void +GnssAdapter::updateTracking(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& updatedOptions, const TrackingOptions& oldOptions) +{ + LocPosMode locPosMode = {}; + convertOptions(locPosMode, updatedOptions); + // save position mode parameters + setLocPositionMode(locPosMode); + + // inform engine hub that GNSS session is about to start + mEngHubProxy->gnssSetFixMode(mLocPositionMode); + mEngHubProxy->gnssStartFix(); + + // want to run SPE session at a fixed min interval in some automotive scenarios + // use a local copy of TrackingOptions as the TBF may get modified in the + // checkAndSetSPEToRunforNHz function + TrackingOptions tempOptions(updatedOptions); + if(!checkAndSetSPEToRunforNHz(tempOptions)) { + mLocApi->startTimeBasedTracking(tempOptions, new LocApiResponse(*getContext(), + [this, client, sessionId, oldOptions] (LocationError err) { + if (LOCATION_ERROR_SUCCESS != err) { + // restore the old LocationOptions + saveTrackingSession(client, sessionId, oldOptions); + } + reportResponse(client, err, sessionId); + } + )); + } else { + reportResponse(client, LOCATION_ERROR_SUCCESS, sessionId); + } +} + +void +GnssAdapter::updateTrackingOptionsCommand(LocationAPI* client, uint32_t id, + TrackingOptions& options) +{ + LOC_LOGD("%s]: client %p id %u minInterval %u mode %u", + __func__, client, id, options.minInterval, options.mode); + + struct MsgUpdateTracking : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + mutable TrackingOptions mOptions; + inline MsgUpdateTracking(GnssAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId, + TrackingOptions options) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId), + mOptions(options) {} + inline virtual void proc() const { + // distance based tracking will need to know engine capabilities before it can start + if (!mAdapter.isEngineCapabilitiesKnown() && mOptions.minDistance > 0) { + mAdapter.mPendingMsgs.push_back(new MsgUpdateTracking(*this)); + return; + } + LocationError err = LOCATION_ERROR_SUCCESS; + bool isTimeBased = mAdapter.isTimeBasedTrackingSession(mClient, mSessionId); + bool isDistanceBased = mAdapter.isDistanceBasedTrackingSession(mClient, mSessionId); + if (!isTimeBased && !isDistanceBased) { + err = LOCATION_ERROR_ID_UNKNOWN; + } else if (0 == mOptions.size) { + err = LOCATION_ERROR_INVALID_PARAMETER; + } + if (LOCATION_ERROR_SUCCESS != err) { + mAdapter.reportResponse(mClient, err, mSessionId); + } else { + if (GNSS_POWER_MODE_M4 == mOptions.powerMode && + mOptions.tbm > TRACKING_TBM_THRESHOLD_MILLIS) { + LOC_LOGd("TBM (%d) > %d Falling back to M2 power mode", + mOptions.tbm, TRACKING_TBM_THRESHOLD_MILLIS); + mOptions.powerMode = GNSS_POWER_MODE_M2; + } + if (mOptions.minInterval < MIN_TRACKING_INTERVAL) { + mOptions.minInterval = MIN_TRACKING_INTERVAL; + } + // Now update session as required + if (isTimeBased && mOptions.minDistance > 0) { + // switch from time based to distance based + // Api doesn't support multiple clients for time based tracking, so mutiplex + bool reportToClientWithNoWait = + mAdapter.stopTimeBasedTrackingMultiplex(mClient, mSessionId); + // erases the time based Session + mAdapter.eraseTrackingSession(mClient, mSessionId); + if (reportToClientWithNoWait) { + mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId); + } + // saves as distance based Session + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + mApi.startDistanceBasedTracking(mSessionId, mOptions, + new LocApiResponse(*mAdapter.getContext(), + [] (LocationError /*err*/) {})); + } else if (isDistanceBased && mOptions.minDistance == 0) { + // switch from distance based to time based + mAdapter.eraseTrackingSession(mClient, mSessionId); + mApi.stopDistanceBasedTracking(mSessionId, new LocApiResponse( + *mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, mOptions = mOptions, + mClient = mClient] (LocationError /*err*/) { + // Api doesn't support multiple clients for time based tracking, + // so mutiplex + bool reportToClientWithNoWait = + mAdapter.startTimeBasedTrackingMultiplex(mClient, mSessionId, + mOptions); + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + + if (reportToClientWithNoWait) { + mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId); + } + })); + } else if (isTimeBased) { + // update time based tracking + // Api doesn't support multiple clients for time based tracking, so mutiplex + bool reportToClientWithNoWait = + mAdapter.updateTrackingMultiplex(mClient, mSessionId, mOptions); + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + + if (reportToClientWithNoWait) { + mAdapter.reportResponse(mClient, err, mSessionId); + } + } else if (isDistanceBased) { + // restart distance based tracking + mApi.stopDistanceBasedTracking(mSessionId, new LocApiResponse( + *mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, mOptions = mOptions, + mClient = mClient, &mApi = mApi] (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + mApi.startDistanceBasedTracking(mSessionId, mOptions, + new LocApiResponse(*mAdapter.getContext(), + [&mAdapter, mClient, mSessionId, mOptions] + (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + mAdapter.saveTrackingSession(mClient, mSessionId, mOptions); + } + mAdapter.reportResponse(mClient, err, mSessionId); + })); + } + })); + } + } + } + }; + + sendMsg(new MsgUpdateTracking(*this, *mLocApi, client, id, options)); +} + +bool +GnssAdapter::updateTrackingMultiplex(LocationAPI* client, uint32_t id, + const TrackingOptions& trackingOptions) +{ + bool reportToClientWithNoWait = true; + + LocationSessionKey key(client, id); + // get the session we are updating + auto it = mTimeBasedTrackingSessions.find(key); + + // cache the clients existing LocationOptions + TrackingOptions oldOptions = it->second; + + // if session we are updating exists and the minInterval or powerMode has changed + if (it != mTimeBasedTrackingSessions.end() && + (it->second.minInterval != trackingOptions.minInterval || + it->second.powerMode != trackingOptions.powerMode)) { + // find the smallest interval and powerMode, other than the session we are updating + TrackingOptions multiplexedOptions = {}; // size is 0 until set for the first time + GnssPowerMode multiplexedPowerMode = GNSS_POWER_MODE_INVALID; + memset(&multiplexedOptions, 0, sizeof(multiplexedOptions)); + for (auto it2 = mTimeBasedTrackingSessions.begin(); + it2 != mTimeBasedTrackingSessions.end(); ++it2) { + // if session is not the one we are updating and either interval + // is not set or there is a new smallest interval, then set the new interval + if (it2->first != key && (0 == multiplexedOptions.size || + it2->second.minInterval < multiplexedOptions.minInterval)) { + multiplexedOptions = it2->second; + } + // if session is not the one we are updating and either powerMode + // is not set or there is a new smallest powerMode, then set the new powerMode + if (it2->first != key && (GNSS_POWER_MODE_INVALID == multiplexedPowerMode || + it2->second.powerMode < multiplexedPowerMode)) { + multiplexedPowerMode = it2->second.powerMode; + } + // else part: no QMI call is made, need to report back to client right away + } + bool updateOptions = false; + // if session we are updating has smaller interval then next smallest + if (trackingOptions.minInterval < multiplexedOptions.minInterval) { + multiplexedOptions.minInterval = trackingOptions.minInterval; + updateOptions = true; + } + // if session we are updating has smaller powerMode then next smallest + if (trackingOptions.powerMode < multiplexedPowerMode) { + multiplexedOptions.powerMode = trackingOptions.powerMode; + updateOptions = true; + } + // if only one session exists, then tracking should be updated with it + if (1 == mTimeBasedTrackingSessions.size()) { + multiplexedOptions = trackingOptions; + updateOptions = true; + } + if (updateOptions) { + // restart time based tracking with the newly updated options + updateTracking(client, id, multiplexedOptions, oldOptions); + // need to wait for QMI callback + reportToClientWithNoWait = false; + } + } + + return reportToClientWithNoWait; +} + +void +GnssAdapter::stopTrackingCommand(LocationAPI* client, uint32_t id) +{ + LOC_LOGD("%s]: client %p id %u", __func__, client, id); + + struct MsgStopTracking : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + LocationAPI* mClient; + uint32_t mSessionId; + inline MsgStopTracking(GnssAdapter& adapter, + LocApiBase& api, + LocationAPI* client, + uint32_t sessionId) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mClient(client), + mSessionId(sessionId) {} + inline virtual void proc() const { + bool isTimeBased = mAdapter.isTimeBasedTrackingSession(mClient, mSessionId); + bool isDistanceBased = mAdapter.isDistanceBasedTrackingSession(mClient, mSessionId); + if (isTimeBased || isDistanceBased) { + if (isTimeBased) { + // Api doesn't support multiple clients for time based tracking, so mutiplex + bool reportToClientWithNoWait = + mAdapter.stopTimeBasedTrackingMultiplex(mClient, mSessionId); + mAdapter.eraseTrackingSession(mClient, mSessionId); + + if (reportToClientWithNoWait) { + mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId); + } + } else if (isDistanceBased) { + mApi.stopDistanceBasedTracking(mSessionId, new LocApiResponse( + *mAdapter.getContext(), + [&mAdapter = mAdapter, mSessionId = mSessionId, mClient = mClient] + (LocationError err) { + if (LOCATION_ERROR_SUCCESS == err) { + mAdapter.eraseTrackingSession(mClient, mSessionId); + } + mAdapter.reportResponse(mClient, err, mSessionId); + })); + } + } else { + mAdapter.reportResponse(mClient, LOCATION_ERROR_ID_UNKNOWN, mSessionId); + } + + } + }; + + sendMsg(new MsgStopTracking(*this, *mLocApi, client, id)); +} + +bool +GnssAdapter::stopTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t id) +{ + bool reportToClientWithNoWait = true; + + if (1 == mTimeBasedTrackingSessions.size()) { + stopTracking(client, id); + // need to wait for QMI callback + reportToClientWithNoWait = false; + } else { + LocationSessionKey key(client, id); + + // get the session we are stopping + auto it = mTimeBasedTrackingSessions.find(key); + if (it != mTimeBasedTrackingSessions.end()) { + // find the smallest interval and powerMode, other than the session we are stopping + TrackingOptions multiplexedOptions = {}; // size is 0 until set for the first time + GnssPowerMode multiplexedPowerMode = GNSS_POWER_MODE_INVALID; + memset(&multiplexedOptions, 0, sizeof(multiplexedOptions)); + for (auto it2 = mTimeBasedTrackingSessions.begin(); + it2 != mTimeBasedTrackingSessions.end(); ++it2) { + // if session is not the one we are stopping and either interval + // is not set or there is a new smallest interval, then set the new interval + if (it2->first != key && (0 == multiplexedOptions.size || + it2->second.minInterval < multiplexedOptions.minInterval)) { + multiplexedOptions = it2->second; + } + // if session is not the one we are stopping and either powerMode + // is not set or there is a new smallest powerMode, then set the new powerMode + if (it2->first != key && (GNSS_POWER_MODE_INVALID == multiplexedPowerMode || + it2->second.powerMode < multiplexedPowerMode)) { + multiplexedPowerMode = it2->second.powerMode; + } + } + // if session we are stopping has smaller interval then next smallest or + // if session we are stopping has smaller powerMode then next smallest + if (it->second.minInterval < multiplexedOptions.minInterval || + it->second.powerMode < multiplexedPowerMode) { + multiplexedOptions.powerMode = multiplexedPowerMode; + // restart time based tracking with the newly updated options + startTimeBasedTracking(client, id, multiplexedOptions); + // need to wait for QMI callback + reportToClientWithNoWait = false; + } + // else part: no QMI call is made, need to report back to client right away + } + } + return reportToClientWithNoWait; +} + +void +GnssAdapter::stopTracking(LocationAPI* client, uint32_t id) +{ + // inform engine hub that GNSS session has stopped + mEngHubProxy->gnssStopFix(); + + mLocApi->stopFix(new LocApiResponse(*getContext(), + [this, client, id] (LocationError err) { + reportResponse(client, err, id); + })); + + if (isDgnssNmeaRequired()) { + mDgnssState &= ~DGNSS_STATE_NO_NMEA_PENDING; + } + stopDgnssNtrip(); + + mSPEAlreadyRunningAtHighestInterval = false; +} + +bool +GnssAdapter::hasNiNotifyCallback(LocationAPI* client) +{ + auto it = mClientData.find(client); + return (it != mClientData.end() && it->second.gnssNiCb); +} + +void +GnssAdapter::gnssNiResponseCommand(LocationAPI* client, + uint32_t id, + GnssNiResponse response) +{ + LOC_LOGD("%s]: client %p id %u response %u", __func__, client, id, response); + + struct MsgGnssNiResponse : public LocMsg { + GnssAdapter& mAdapter; + LocationAPI* mClient; + uint32_t mSessionId; + GnssNiResponse mResponse; + inline MsgGnssNiResponse(GnssAdapter& adapter, + LocationAPI* client, + uint32_t sessionId, + GnssNiResponse response) : + LocMsg(), + mAdapter(adapter), + mClient(client), + mSessionId(sessionId), + mResponse(response) {} + inline virtual void proc() const { + NiData& niData = mAdapter.getNiData(); + LocationError err = LOCATION_ERROR_SUCCESS; + if (!mAdapter.hasNiNotifyCallback(mClient)) { + err = LOCATION_ERROR_ID_UNKNOWN; + } else { + NiSession* pSession = NULL; + if (mSessionId == niData.sessionEs.reqID && + NULL != niData.sessionEs.rawRequest) { + pSession = &niData.sessionEs; + // ignore any SUPL NI non-Es session if a SUPL NI ES is accepted + if (mResponse == GNSS_NI_RESPONSE_ACCEPT && + NULL != niData.session.rawRequest) { + pthread_mutex_lock(&niData.session.tLock); + niData.session.resp = GNSS_NI_RESPONSE_IGNORE; + niData.session.respRecvd = true; + pthread_cond_signal(&niData.session.tCond); + pthread_mutex_unlock(&niData.session.tLock); + } + } else if (mSessionId == niData.session.reqID && + NULL != niData.session.rawRequest) { + pSession = &niData.session; + } + + if (pSession) { + LOC_LOGI("%s]: gnssNiResponseCommand: send user mResponse %u for id %u", + __func__, mResponse, mSessionId); + pthread_mutex_lock(&pSession->tLock); + pSession->resp = mResponse; + pSession->respRecvd = true; + pthread_cond_signal(&pSession->tCond); + pthread_mutex_unlock(&pSession->tLock); + } else { + err = LOCATION_ERROR_ID_UNKNOWN; + LOC_LOGE("%s]: gnssNiResponseCommand: id %u not an active session", + __func__, mSessionId); + } + } + mAdapter.reportResponse(mClient, err, mSessionId); + } + }; + + sendMsg(new MsgGnssNiResponse(*this, client, id, response)); + +} + +void +GnssAdapter::gnssNiResponseCommand(GnssNiResponse response, void* rawRequest) +{ + LOC_LOGD("%s]: response %u", __func__, response); + + struct MsgGnssNiResponse : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + const GnssNiResponse mResponse; + const void* mPayload; + inline MsgGnssNiResponse(GnssAdapter& adapter, + LocApiBase& api, + const GnssNiResponse response, + const void* rawRequest) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mResponse(response), + mPayload(rawRequest) {} + inline virtual ~MsgGnssNiResponse() { + } + inline virtual void proc() const { + mApi.informNiResponse(mResponse, mPayload); + } + }; + + sendMsg(new MsgGnssNiResponse(*this, *mLocApi, response, rawRequest)); + +} + +uint32_t +GnssAdapter::enableCommand(LocationTechnologyType techType) +{ + uint32_t sessionId = generateSessionId(); + LOC_LOGD("%s]: id %u techType %u", __func__, sessionId, techType); + + struct MsgEnableGnss : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + ContextBase& mContext; + uint32_t mSessionId; + LocationTechnologyType mTechType; + inline MsgEnableGnss(GnssAdapter& adapter, + LocApiBase& api, + ContextBase& context, + uint32_t sessionId, + LocationTechnologyType techType) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mContext(context), + mSessionId(sessionId), + mTechType(techType) {} + inline virtual void proc() const { + LocationError err = LOCATION_ERROR_SUCCESS; + uint32_t afwControlId = mAdapter.getAfwControlId(); + if (mTechType != LOCATION_TECHNOLOGY_TYPE_GNSS) { + err = LOCATION_ERROR_INVALID_PARAMETER; + } else if (afwControlId > 0) { + err = LOCATION_ERROR_ALREADY_STARTED; + } else { + mContext.modemPowerVote(true); + mAdapter.setAfwControlId(mSessionId); + + GnssConfigGpsLock gpsLock = GNSS_CONFIG_GPS_LOCK_NONE; + if (mAdapter.mSupportNfwControl) { + ContextBase::mGps_conf.GPS_LOCK &= GNSS_CONFIG_GPS_LOCK_NI; + gpsLock = ContextBase::mGps_conf.GPS_LOCK; + } + mApi.sendMsg(new LocApiMsg([&mApi = mApi, gpsLock]() { + mApi.setGpsLockSync(gpsLock); + })); + mAdapter.mXtraObserver.updateLockStatus(gpsLock); + } + mAdapter.reportResponse(err, mSessionId); + } + }; + + if (mContext != NULL) { + sendMsg(new MsgEnableGnss(*this, *mLocApi, *mContext, sessionId, techType)); + } else { + LOC_LOGE("%s]: Context is NULL", __func__); + } + + return sessionId; +} + +void +GnssAdapter::disableCommand(uint32_t id) +{ + LOC_LOGD("%s]: id %u", __func__, id); + + struct MsgDisableGnss : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + ContextBase& mContext; + uint32_t mSessionId; + inline MsgDisableGnss(GnssAdapter& adapter, + LocApiBase& api, + ContextBase& context, + uint32_t sessionId) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mContext(context), + mSessionId(sessionId) {} + inline virtual void proc() const { + LocationError err = LOCATION_ERROR_SUCCESS; + uint32_t afwControlId = mAdapter.getAfwControlId(); + if (afwControlId != mSessionId) { + err = LOCATION_ERROR_ID_UNKNOWN; + } else { + mContext.modemPowerVote(false); + mAdapter.setAfwControlId(0); + + if (mAdapter.mSupportNfwControl) { + /* We need to disable MO (AFW) */ + ContextBase::mGps_conf.GPS_LOCK |= GNSS_CONFIG_GPS_LOCK_MO; + } + GnssConfigGpsLock gpsLock = ContextBase::mGps_conf.GPS_LOCK; + mApi.sendMsg(new LocApiMsg([&mApi = mApi, gpsLock]() { + mApi.setGpsLockSync(gpsLock); + })); + mAdapter.mXtraObserver.updateLockStatus(gpsLock); + } + mAdapter.reportResponse(err, mSessionId); + } + }; + + if (mContext != NULL) { + sendMsg(new MsgDisableGnss(*this, *mLocApi, *mContext, id)); + } + +} + +// This function computes the VRP based latitude, longitude and alittude, and +// north, east and up velocity and save the result into EHubTechReport. +void +GnssAdapter::computeVRPBasedLla(const UlpLocation& loc, GpsLocationExtended& locExt, + const LeverArmConfigInfo& leverArmConfigInfo) { + + float leverArm[3]; + float rollPitchYaw[3]; + double lla[3]; + + uint16_t locFlags = loc.gpsLocation.flags; + uint64_t locExtFlags = locExt.flags; + + // check for SPE fix + if (!((locExtFlags & GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE) && + (locExt.locOutputEngType == LOC_OUTPUT_ENGINE_SPE))){ + LOC_LOGv("not SPE fix, return"); + return; + } + + // we can only do translation if we have VRP based lever ARM info + LeverArmTypeMask leverArmFlags = leverArmConfigInfo.leverArmValidMask; + if (!(leverArmFlags & LEVER_ARM_TYPE_GNSS_TO_VRP_BIT)) { + LOC_LOGd("no VRP based lever ARM info"); + return; + } + + leverArm[0] = leverArmConfigInfo.gnssToVRP.forwardOffsetMeters; + leverArm[1] = leverArmConfigInfo.gnssToVRP.sidewaysOffsetMeters; + leverArm[2] = leverArmConfigInfo.gnssToVRP.upOffsetMeters; + + if ((locFlags & LOC_GPS_LOCATION_HAS_LAT_LONG) && + (locFlags & LOC_GPS_LOCATION_HAS_ALTITUDE) && + (locFlags & LOCATION_HAS_BEARING_BIT)) { + + lla[0] = loc.gpsLocation.latitude * DEG2RAD; + lla[1] = loc.gpsLocation.longitude * DEG2RAD; + lla[2] = loc.gpsLocation.altitude; + + rollPitchYaw[0] = 0.0f; + rollPitchYaw[1] = 0.0f; + rollPitchYaw[2] = loc.gpsLocation.bearing * DEG2RAD; + + loc_convert_lla_gnss_to_vrp(lla, rollPitchYaw, leverArm); + + // assign the converted value into position report and + // set up valid mask + locExt.llaVRPBased.latitude = lla[0] * RAD2DEG; + locExt.llaVRPBased.longitude = lla[1] * RAD2DEG; + locExt.llaVRPBased.altitude = lla[2]; + locExt.flags |= GPS_LOCATION_EXTENDED_HAS_LLA_VRP_BASED; + } else { + LOC_LOGd("SPE fix missing latitude/longitude/alitutde"); + return; + } +} + +void +GnssAdapter::reportPositionEvent(const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask techMask, + GnssDataNotification* pDataNotify, + int msInWeek) +{ + // this position is from QMI LOC API, then send report to engine hub + // also, send out SPE fix promptly to the clients that have registered + // with SPE report + LOC_LOGd("reportPositionEvent, eng type: %d, unpro %d, sess status %d msInWeek %d", + locationExtended.locOutputEngType, + ulpLocation.unpropagatedPosition, status, msInWeek); + + struct MsgReportSPEPosition : public LocMsg { + GnssAdapter& mAdapter; + mutable UlpLocation mUlpLocation; + mutable GpsLocationExtended mLocationExtended; + enum loc_sess_status mStatus; + LocPosTechMask mTechMask; + mutable GnssDataNotification mDataNotify; + int mMsInWeek; + + inline MsgReportSPEPosition(GnssAdapter& adapter, + const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask techMask, + GnssDataNotification dataNotify, + int msInWeek) : + LocMsg(), + mAdapter(adapter), + mUlpLocation(ulpLocation), + mLocationExtended(locationExtended), + mStatus(status), + mTechMask(techMask), + mDataNotify(dataNotify), + mMsInWeek(msInWeek) {} + inline virtual void proc() const { + if (mAdapter.mTimeBasedTrackingSessions.empty() && + mAdapter.mDistanceBasedTrackingSessions.empty()) { + LOC_LOGd("reportPositionEvent, no session on-going, throw away the SPE reports"); + return; + } + + if (false == mUlpLocation.unpropagatedPosition && mDataNotify.size != 0) { + if (mMsInWeek >= 0) { + mAdapter.getDataInformation((GnssDataNotification&)mDataNotify, + mMsInWeek); + } + mAdapter.reportData(mDataNotify); + } + + if (true == mAdapter.initEngHubProxy()){ + // send the SPE fix to engine hub + mAdapter.mEngHubProxy->gnssReportPosition(mUlpLocation, mLocationExtended, mStatus); + // report out all SPE fix if it is not propagated, even for failed fix + if (false == mUlpLocation.unpropagatedPosition) { + EngineLocationInfo engLocationInfo = {}; + engLocationInfo.location = mUlpLocation; + engLocationInfo.locationExtended = mLocationExtended; + engLocationInfo.sessionStatus = mStatus; + + // obtain the VRP based latitude/longitude/altitude for SPE fix + computeVRPBasedLla(engLocationInfo.location, + engLocationInfo.locationExtended, + mAdapter.mLocConfigInfo.leverArmConfigInfo); + mAdapter.reportEnginePositions(1, &engLocationInfo); + } + return; + } + + // unpropagated report: is only for engine hub to consume and no need + // to send out to the clients + if (true == mUlpLocation.unpropagatedPosition) { + return; + } + + // extract bug report info - this returns true if consumed by systemstatus + SystemStatus* s = mAdapter.getSystemStatus(); + if ((nullptr != s) && + ((LOC_SESS_SUCCESS == mStatus) || (LOC_SESS_INTERMEDIATE == mStatus))){ + s->eventPosition(mUlpLocation, mLocationExtended); + } + + mAdapter.reportPosition(mUlpLocation, mLocationExtended, mStatus, mTechMask); + } + }; + + if (mContext != NULL) { + GnssDataNotification dataNotifyCopy = {}; + if (pDataNotify) { + dataNotifyCopy = *pDataNotify; + dataNotifyCopy.size = sizeof(dataNotifyCopy); + } + sendMsg(new MsgReportSPEPosition(*this, ulpLocation, locationExtended, + status, techMask, dataNotifyCopy, msInWeek)); + } +} + +void +GnssAdapter::reportEnginePositionsEvent(unsigned int count, + EngineLocationInfo* locationArr) +{ + struct MsgReportEnginePositions : public LocMsg { + GnssAdapter& mAdapter; + unsigned int mCount; + EngineLocationInfo mEngLocInfo[LOC_OUTPUT_ENGINE_COUNT]; + inline MsgReportEnginePositions(GnssAdapter& adapter, + unsigned int count, + EngineLocationInfo* locationArr) : + LocMsg(), + mAdapter(adapter), + mCount(count) { + if (mCount > LOC_OUTPUT_ENGINE_COUNT) { + mCount = LOC_OUTPUT_ENGINE_COUNT; + } + if (mCount > 0) { + memcpy(mEngLocInfo, locationArr, sizeof(EngineLocationInfo)*mCount); + } + } + inline virtual void proc() const { + mAdapter.reportEnginePositions(mCount, mEngLocInfo); + } + }; + + sendMsg(new MsgReportEnginePositions(*this, count, locationArr)); +} + +bool +GnssAdapter::needReportForGnssClient(const UlpLocation& ulpLocation, + enum loc_sess_status status, + LocPosTechMask techMask) { + bool reported = false; + + // if engine hub is enabled, aka, any of the engine services is enabled, + // then always output position reported by engine hub to requesting client + if (true == initEngHubProxy()) { + reported = true; + } else { + reported = LocApiBase::needReport(ulpLocation, status, techMask); + } + return reported; +} + +bool +GnssAdapter::needReportForFlpClient(enum loc_sess_status status, + LocPosTechMask techMask) { + if (((LOC_SESS_INTERMEDIATE == status) && !(techMask & LOC_POS_TECH_MASK_SENSORS) && + (!getAllowFlpNetworkFixes())) || + (LOC_SESS_FAILURE == status)) { + return false; + } else { + return true; + } +} + +bool +GnssAdapter::isFlpClient(LocationCallbacks& locationCallbacks) +{ + return (locationCallbacks.gnssLocationInfoCb == nullptr && + locationCallbacks.gnssSvCb == nullptr && + locationCallbacks.gnssNmeaCb == nullptr && + locationCallbacks.gnssDataCb == nullptr && + locationCallbacks.gnssMeasurementsCb == nullptr); +} + +bool GnssAdapter::needToGenerateNmeaReport(const uint32_t &gpsTimeOfWeekMs, + const struct timespec32_t &apTimeStamp) +{ + bool retVal = false; + uint64_t currentTimeNsec = 0; + + if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && !mTimeBasedTrackingSessions.empty()) { + currentTimeNsec = (apTimeStamp.tv_sec * BILLION_NSEC + apTimeStamp.tv_nsec); + if ((GNSS_NMEA_REPORT_RATE_NHZ == ContextBase::sNmeaReportRate) || + (GPS_DEFAULT_FIX_INTERVAL_MS <= mLocPositionMode.min_interval)) { + retVal = true; + } else { /*tbf is less than 1000 milli-seconds and NMEA reporting rate is set to 1Hz */ + /* Always send NMEA string for first position report + * Send when gpsTimeOfWeekMs is closely aligned with integer boundary + */ + if ((0 == mPrevNmeaRptTimeNsec) || + (0 != gpsTimeOfWeekMs) && (NMEA_MIN_THRESHOLD_MSEC >= (gpsTimeOfWeekMs % 1000))) { + retVal = true; + } else { + uint64_t timeDiffMsec = ((currentTimeNsec - mPrevNmeaRptTimeNsec) / 1000000); + // Send when the delta time becomes >= 1 sec + if (NMEA_MAX_THRESHOLD_MSEC <= timeDiffMsec) { + retVal = true; + } + } + } + if (true == retVal) { + mPrevNmeaRptTimeNsec = currentTimeNsec; + } + } + return retVal; +} + +void +GnssAdapter::logLatencyInfo() +{ + if (0 == mGnssLatencyInfoQueue.size()) { + LOC_LOGv("mGnssLatencyInfoQueue.size is 0"); + return; + } + mGnssLatencyInfoQueue.front().hlosQtimer5 = getQTimerTickCount(); + if (0 == mGnssLatencyInfoQueue.front().hlosQtimer3) { + /* if SPE from engine hub is not reported then hlosQtimer3 = 0, set it + equal to hlosQtimer2 to make sense */ + LOC_LOGv("hlosQtimer3 is 0, setting it to hlosQtimer2"); + mGnssLatencyInfoQueue.front().hlosQtimer3 = mGnssLatencyInfoQueue.front().hlosQtimer2; + } + if (0 == mGnssLatencyInfoQueue.front().hlosQtimer4) { + /* if PPE from engine hub is not reported then hlosQtimer4 = 0, set it + equal to hlosQtimer3 to make sense */ + LOC_LOGv("hlosQtimer4 is 0, setting it to hlosQtimer3"); + mGnssLatencyInfoQueue.front().hlosQtimer4 = mGnssLatencyInfoQueue.front().hlosQtimer3; + } + if (mGnssLatencyInfoQueue.front().hlosQtimer4 < mGnssLatencyInfoQueue.front().hlosQtimer3) { + /* hlosQtimer3 is timestamped when SPE from engine hub is reported, + and hlosQtimer4 is timestamped when PPE from engine hub is reported. + The order is random though, hence making sure the timestamps are sorted */ + LOC_LOGv("hlosQtimer4 is < hlosQtimer3, swapping them"); + std::swap(mGnssLatencyInfoQueue.front().hlosQtimer3, + mGnssLatencyInfoQueue.front().hlosQtimer4); + } + LOC_LOGv("meQtimer1=%" PRIi64 " " + "meQtimer2=%" PRIi64 " " + "meQtimer3=%" PRIi64 " " + "peQtimer1=%" PRIi64 " " + "peQtimer2=%" PRIi64 " " + "peQtimer3=%" PRIi64 " " + "smQtimer1=%" PRIi64 " " + "smQtimer2=%" PRIi64 " " + "smQtimer3=%" PRIi64 " " + "locMwQtimer=%" PRIi64 " " + "hlosQtimer1=%" PRIi64 " " + "hlosQtimer2=%" PRIi64 " " + "hlosQtimer3=%" PRIi64 " " + "hlosQtimer4=%" PRIi64 " " + "hlosQtimer5=%" PRIi64 " ", + mGnssLatencyInfoQueue.front().meQtimer1, mGnssLatencyInfoQueue.front().meQtimer2, + mGnssLatencyInfoQueue.front().meQtimer3, mGnssLatencyInfoQueue.front().peQtimer1, + mGnssLatencyInfoQueue.front().peQtimer2, mGnssLatencyInfoQueue.front().peQtimer3, + mGnssLatencyInfoQueue.front().smQtimer1, mGnssLatencyInfoQueue.front().smQtimer2, + mGnssLatencyInfoQueue.front().smQtimer3, mGnssLatencyInfoQueue.front().locMwQtimer, + mGnssLatencyInfoQueue.front().hlosQtimer1, mGnssLatencyInfoQueue.front().hlosQtimer2, + mGnssLatencyInfoQueue.front().hlosQtimer3, mGnssLatencyInfoQueue.front().hlosQtimer4, + mGnssLatencyInfoQueue.front().hlosQtimer5); + mLogger.log(mGnssLatencyInfoQueue.front()); + mGnssLatencyInfoQueue.pop(); + LOC_LOGv("mGnssLatencyInfoQueue.size after pop=%zu", mGnssLatencyInfoQueue.size()); +} + +// only fused report (when engine hub is enabled) or +// SPE report (when engine hub is disabled) will reach this function +void +GnssAdapter::reportPosition(const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask techMask) +{ + bool reportToGnssClient = needReportForGnssClient(ulpLocation, status, techMask); + bool reportToFlpClient = needReportForFlpClient(status, techMask); + + if (reportToGnssClient || reportToFlpClient) { + GnssLocationInfoNotification locationInfo = {}; + convertLocationInfo(locationInfo, locationExtended, status); + convertLocation(locationInfo.location, ulpLocation, locationExtended); + logLatencyInfo(); + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if ((reportToFlpClient && isFlpClient(it->second)) || + (reportToGnssClient && !isFlpClient(it->second))) { + if (nullptr != it->second.gnssLocationInfoCb) { + it->second.gnssLocationInfoCb(locationInfo); + } else if ((nullptr != it->second.engineLocationsInfoCb) && + (false == initEngHubProxy())) { + // if engine hub is disabled, this is SPE fix from modem + // we need to mark one copy marked as fused and one copy marked as PPE + // and dispatch it to the engineLocationsInfoCb + GnssLocationInfoNotification engLocationsInfo[2]; + engLocationsInfo[0] = locationInfo; + engLocationsInfo[0].locOutputEngType = LOC_OUTPUT_ENGINE_FUSED; + engLocationsInfo[0].flags |= GNSS_LOCATION_INFO_OUTPUT_ENG_TYPE_BIT; + engLocationsInfo[1] = locationInfo; + it->second.engineLocationsInfoCb(2, engLocationsInfo); + } else if (nullptr != it->second.trackingCb) { + it->second.trackingCb(locationInfo.location); + } + } + } + + mGnssSvIdUsedInPosAvail = false; + mGnssMbSvIdUsedInPosAvail = false; + if (reportToGnssClient) { + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA) { + mGnssSvIdUsedInPosAvail = true; + mGnssSvIdUsedInPosition = locationExtended.gnss_sv_used_ids; + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MULTIBAND) { + mGnssMbSvIdUsedInPosAvail = true; + mGnssMbSvIdUsedInPosition = locationExtended.gnss_mb_sv_used_ids; + } + } + + // if PACE is enabled + if ((true == mLocConfigInfo.paceConfigInfo.isValid) && + (true == mLocConfigInfo.paceConfigInfo.enable)) { + // If fix has sensor contribution, and it is fused fix with DRE engine + // contributing to the fix, inject to modem + if ((LOC_POS_TECH_MASK_SENSORS & techMask) && + (locationInfo.flags & GNSS_LOCATION_INFO_OUTPUT_ENG_TYPE_BIT) && + (locationInfo.locOutputEngType == LOC_OUTPUT_ENGINE_FUSED) && + (locationInfo.flags & GNSS_LOCATION_INFO_OUTPUT_ENG_MASK_BIT) && + (locationInfo.locOutputEngMask & DEAD_RECKONING_ENGINE)) { + mLocApi->injectPosition(locationInfo, false); + } + } + } + } + + if (needToGenerateNmeaReport(locationExtended.gpsTime.gpsTimeOfWeekMs, + locationExtended.timeStamp.apTimeStamp)) { + /*Only BlankNMEA sentence needs to be processed and sent, if both lat, long is 0 & + horReliability is not set. */ + bool blank_fix = ((0 == ulpLocation.gpsLocation.latitude) && + (0 == ulpLocation.gpsLocation.longitude) && + (LOC_RELIABILITY_NOT_SET == locationExtended.horizontal_reliability)); + uint8_t generate_nmea = (reportToGnssClient && status != LOC_SESS_FAILURE && !blank_fix); + bool custom_nmea_gga = (1 == ContextBase::mGps_conf.CUSTOM_NMEA_GGA_FIX_QUALITY_ENABLED); + bool isTagBlockGroupingEnabled = + (1 == ContextBase::mGps_conf.NMEA_TAG_BLOCK_GROUPING_ENABLED); + std::vector nmeaArraystr; + int indexOfGGA = -1; + loc_nmea_generate_pos(ulpLocation, locationExtended, mLocSystemInfo, generate_nmea, + custom_nmea_gga, nmeaArraystr, indexOfGGA, isTagBlockGroupingEnabled); + stringstream ss; + for (auto itor = nmeaArraystr.begin(); itor != nmeaArraystr.end(); ++itor) { + ss << *itor; + } + string s = ss.str(); + reportNmea(s.c_str(), s.length()); + + /* DgnssNtrip */ + if (-1 != indexOfGGA && isDgnssNmeaRequired()) { + mDgnssState |= DGNSS_STATE_NO_NMEA_PENDING; + mStartDgnssNtripParams.nmea = std::move(nmeaArraystr[indexOfGGA]); + bool isLocationValid = (0 != ulpLocation.gpsLocation.latitude) || + (0 != ulpLocation.gpsLocation.longitude); + checkUpdateDgnssNtrip(isLocationValid); + } + } +} + +void +GnssAdapter::reportLatencyInfoEvent(const GnssLatencyInfo& gnssLatencyInfo) +{ + struct MsgReportLatencyInfo : public LocMsg { + GnssAdapter& mAdapter; + GnssLatencyInfo mGnssLatencyInfo; + inline MsgReportLatencyInfo(GnssAdapter& adapter, + const GnssLatencyInfo& gnssLatencyInfo) : + mGnssLatencyInfo(gnssLatencyInfo), + mAdapter(adapter) {} + inline virtual void proc() const { + mAdapter.mGnssLatencyInfoQueue.push(mGnssLatencyInfo); + LOC_LOGv("mGnssLatencyInfoQueue.size after push=%zu", + mAdapter.mGnssLatencyInfoQueue.size()); + } + }; + sendMsg(new MsgReportLatencyInfo(*this, gnssLatencyInfo)); +} + +void +GnssAdapter::reportEnginePositions(unsigned int count, + const EngineLocationInfo* locationArr) +{ + bool needReportEnginePositions = false; + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.engineLocationsInfoCb) { + needReportEnginePositions = true; + break; + } + } + + GnssLocationInfoNotification locationInfo[LOC_OUTPUT_ENGINE_COUNT] = {}; + for (unsigned int i = 0; i < count; i++) { + const EngineLocationInfo* engLocation = (locationArr+i); + // if it is fused/default location, call reportPosition maintain legacy behavior + if ((GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE & engLocation->locationExtended.flags) && + (LOC_OUTPUT_ENGINE_FUSED == engLocation->locationExtended.locOutputEngType)) { + reportPosition(engLocation->location, + engLocation->locationExtended, + engLocation->sessionStatus, + engLocation->location.tech_mask); + } + + if (needReportEnginePositions) { + convertLocationInfo(locationInfo[i], engLocation->locationExtended, + engLocation->sessionStatus); + convertLocation(locationInfo[i].location, + engLocation->location, + engLocation->locationExtended); + } + } + + const EngineLocationInfo* engLocation = locationArr; + LOC_LOGv("engLocation->locationExtended.locOutputEngType=%d", + engLocation->locationExtended.locOutputEngType); + + if (0 != mGnssLatencyInfoQueue.size()) { + if ((GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE & engLocation->locationExtended.flags) && + (LOC_OUTPUT_ENGINE_SPE == engLocation->locationExtended.locOutputEngType)) { + mGnssLatencyInfoQueue.front().hlosQtimer3 = getQTimerTickCount(); + LOC_LOGv("SPE hlosQtimer3=%" PRIi64 " ", mGnssLatencyInfoQueue.front().hlosQtimer3); + } + if ((GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE & engLocation->locationExtended.flags) && + (LOC_OUTPUT_ENGINE_PPE == engLocation->locationExtended.locOutputEngType)) { + mGnssLatencyInfoQueue.front().hlosQtimer4 = getQTimerTickCount(); + LOC_LOGv("PPE hlosQtimer4=%" PRIi64 " ", mGnssLatencyInfoQueue.front().hlosQtimer4); + } + } + if (needReportEnginePositions) { + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.engineLocationsInfoCb) { + it->second.engineLocationsInfoCb(count, locationInfo); + } + } + } +} + +void +GnssAdapter::reportSvEvent(const GnssSvNotification& svNotify, + bool fromEngineHub) +{ + if (!fromEngineHub) { + mEngHubProxy->gnssReportSv(svNotify); + if (true == initEngHubProxy()){ + return; + } + } + + struct MsgReportSv : public LocMsg { + GnssAdapter& mAdapter; + const GnssSvNotification mSvNotify; + inline MsgReportSv(GnssAdapter& adapter, + const GnssSvNotification& svNotify) : + LocMsg(), + mAdapter(adapter), + mSvNotify(svNotify) {} + inline virtual void proc() const { + mAdapter.reportSv((GnssSvNotification&)mSvNotify); + } + }; + + sendMsg(new MsgReportSv(*this, svNotify)); +} + +void +GnssAdapter::reportSv(GnssSvNotification& svNotify) +{ + int numSv = svNotify.count; + uint16_t gnssSvId = 0; + uint64_t svUsedIdMask = 0; + for (int i=0; i < numSv; i++) { + svUsedIdMask = 0; + gnssSvId = svNotify.gnssSvs[i].svId; + GnssSignalTypeMask signalTypeMask = svNotify.gnssSvs[i].gnssSignalTypeMask; + switch (svNotify.gnssSvs[i].type) { + case GNSS_SV_TYPE_GPS: + if (mGnssSvIdUsedInPosAvail) { + if (mGnssMbSvIdUsedInPosAvail) { + switch (signalTypeMask) { + case GNSS_SIGNAL_GPS_L1CA: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gps_l1ca_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GPS_L1C: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gps_l1c_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GPS_L2: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gps_l2_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GPS_L5: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gps_l5_sv_used_ids_mask; + break; + } + } else { + svUsedIdMask = mGnssSvIdUsedInPosition.gps_sv_used_ids_mask; + } + } + break; + case GNSS_SV_TYPE_GLONASS: + if (mGnssSvIdUsedInPosAvail) { + if (mGnssMbSvIdUsedInPosAvail) { + switch (signalTypeMask) { + case GNSS_SIGNAL_GLONASS_G1: + svUsedIdMask = mGnssMbSvIdUsedInPosition.glo_g1_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GLONASS_G2: + svUsedIdMask = mGnssMbSvIdUsedInPosition.glo_g2_sv_used_ids_mask; + break; + } + } else { + svUsedIdMask = mGnssSvIdUsedInPosition.glo_sv_used_ids_mask; + } + } + // map the svid to respective constellation range 1..xx + // then repective constellation svUsedIdMask map correctly to svid + gnssSvId = gnssSvId - GLO_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_BEIDOU: + if (mGnssSvIdUsedInPosAvail) { + if (mGnssMbSvIdUsedInPosAvail) { + switch (signalTypeMask) { + case GNSS_SIGNAL_BEIDOU_B1I: + svUsedIdMask = mGnssMbSvIdUsedInPosition.bds_b1i_sv_used_ids_mask; + break; + case GNSS_SIGNAL_BEIDOU_B1C: + svUsedIdMask = mGnssMbSvIdUsedInPosition.bds_b1c_sv_used_ids_mask; + break; + case GNSS_SIGNAL_BEIDOU_B2I: + svUsedIdMask = mGnssMbSvIdUsedInPosition.bds_b2i_sv_used_ids_mask; + break; + case GNSS_SIGNAL_BEIDOU_B2AI: + svUsedIdMask = mGnssMbSvIdUsedInPosition.bds_b2ai_sv_used_ids_mask; + break; + case GNSS_SIGNAL_BEIDOU_B2AQ: + svUsedIdMask = mGnssMbSvIdUsedInPosition.bds_b2aq_sv_used_ids_mask; + break; + } + } else { + svUsedIdMask = mGnssSvIdUsedInPosition.bds_sv_used_ids_mask; + } + } + gnssSvId = gnssSvId - BDS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_GALILEO: + if (mGnssSvIdUsedInPosAvail) { + if (mGnssMbSvIdUsedInPosAvail) { + switch (signalTypeMask) { + case GNSS_SIGNAL_GALILEO_E1: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gal_e1_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GALILEO_E5A: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gal_e5a_sv_used_ids_mask; + break; + case GNSS_SIGNAL_GALILEO_E5B: + svUsedIdMask = mGnssMbSvIdUsedInPosition.gal_e5b_sv_used_ids_mask; + break; + } + } else { + svUsedIdMask = mGnssSvIdUsedInPosition.gal_sv_used_ids_mask; + } + } + gnssSvId = gnssSvId - GAL_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_QZSS: + if (mGnssSvIdUsedInPosAvail) { + if (mGnssMbSvIdUsedInPosAvail) { + switch (signalTypeMask) { + case GNSS_SIGNAL_QZSS_L1CA: + svUsedIdMask = mGnssMbSvIdUsedInPosition.qzss_l1ca_sv_used_ids_mask; + break; + case GNSS_SIGNAL_QZSS_L1S: + svUsedIdMask = mGnssMbSvIdUsedInPosition.qzss_l1s_sv_used_ids_mask; + break; + case GNSS_SIGNAL_QZSS_L2: + svUsedIdMask = mGnssMbSvIdUsedInPosition.qzss_l2_sv_used_ids_mask; + break; + case GNSS_SIGNAL_QZSS_L5: + svUsedIdMask = mGnssMbSvIdUsedInPosition.qzss_l5_sv_used_ids_mask; + break; + } + } else { + svUsedIdMask = mGnssSvIdUsedInPosition.qzss_sv_used_ids_mask; + } + } + gnssSvId = gnssSvId - QZSS_SV_PRN_MIN + 1; + break; + case GNSS_SV_TYPE_NAVIC: + if (mGnssSvIdUsedInPosAvail) { + svUsedIdMask = mGnssSvIdUsedInPosition.navic_sv_used_ids_mask; + } + gnssSvId = gnssSvId - NAVIC_SV_PRN_MIN + 1; + break; + default: + svUsedIdMask = 0; + break; + } + + // If SV ID was used in previous position fix, then set USED_IN_FIX + // flag, else clear the USED_IN_FIX flag. + if (svFitsMask(svUsedIdMask, gnssSvId) && (svUsedIdMask & (1ULL << (gnssSvId - 1)))) { + svNotify.gnssSvs[i].gnssSvOptionsMask |= GNSS_SV_OPTIONS_USED_IN_FIX_BIT; + } + } + + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.gnssSvCb) { + it->second.gnssSvCb(svNotify); + } + } + + if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && + !mTimeBasedTrackingSessions.empty()) { + std::vector nmeaArraystr; + loc_nmea_generate_sv(svNotify, nmeaArraystr); + stringstream ss; + for (auto itor = nmeaArraystr.begin(); itor != nmeaArraystr.end(); ++itor) { + ss << *itor; + } + string s = ss.str(); + reportNmea(s.c_str(), s.length()); + } + + mGnssSvIdUsedInPosAvail = false; + mGnssMbSvIdUsedInPosAvail = false; +} + +void +GnssAdapter::reportNmeaEvent(const char* nmea, size_t length) +{ + if (NMEA_PROVIDER_AP == ContextBase::mGps_conf.NMEA_PROVIDER && + !loc_nmea_is_debug(nmea, length)) { + return; + } + + struct MsgReportNmea : public LocMsg { + GnssAdapter& mAdapter; + const char* mNmea; + size_t mLength; + inline MsgReportNmea(GnssAdapter& adapter, + const char* nmea, + size_t length) : + LocMsg(), + mAdapter(adapter), + mNmea(new char[length+1]), + mLength(length) { + if (mNmea == nullptr) { + LOC_LOGE("%s] new allocation failed, fatal error.", __func__); + return; + } + strlcpy((char*)mNmea, nmea, length+1); + } + inline virtual ~MsgReportNmea() + { + delete[] mNmea; + } + inline virtual void proc() const { + // extract bug report info - this returns true if consumed by systemstatus + bool ret = false; + SystemStatus* s = mAdapter.getSystemStatus(); + if (nullptr != s) { + ret = s->setNmeaString(mNmea, mLength); + } + if (false == ret) { + // forward NMEA message to upper layer + mAdapter.reportNmea(mNmea, mLength); + // DgnssNtrip + mAdapter.reportGGAToNtrip(mNmea); + } + } + }; + + sendMsg(new MsgReportNmea(*this, nmea, length)); +} + +void +GnssAdapter::reportNmea(const char* nmea, size_t length) +{ + GnssNmeaNotification nmeaNotification = {}; + nmeaNotification.size = sizeof(GnssNmeaNotification); + + struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); + int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000; + nmeaNotification.timestamp = now; + nmeaNotification.nmea = nmea; + nmeaNotification.length = length; + + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.gnssNmeaCb) { + it->second.gnssNmeaCb(nmeaNotification); + } + } + + if (isNMEAPrintEnabled()) { + LOC_LOGd("[%" PRId64 ", %zu] %s", now, length, nmea); + } +} + +void +GnssAdapter::reportDataEvent(const GnssDataNotification& dataNotify, + int msInWeek) +{ + struct MsgReportData : public LocMsg { + GnssAdapter& mAdapter; + GnssDataNotification mDataNotify; + int mMsInWeek; + inline MsgReportData(GnssAdapter& adapter, + const GnssDataNotification& dataNotify, + int msInWeek) : + LocMsg(), + mAdapter(adapter), + mDataNotify(dataNotify), + mMsInWeek(msInWeek) { + } + inline virtual void proc() const { + if (mMsInWeek >= 0) { + mAdapter.getDataInformation((GnssDataNotification&)mDataNotify, + mMsInWeek); + } + mAdapter.reportData((GnssDataNotification&)mDataNotify); + } + }; + + sendMsg(new MsgReportData(*this, dataNotify, msInWeek)); +} + +void +GnssAdapter::reportData(GnssDataNotification& dataNotify) +{ + for (int sig = 0; sig < GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES; sig++) { + if (GNSS_LOC_DATA_JAMMER_IND_BIT == + (dataNotify.gnssDataMask[sig] & GNSS_LOC_DATA_JAMMER_IND_BIT)) { + LOC_LOGv("jammerInd[%d]=%f", sig, dataNotify.jammerInd[sig]); + } + if (GNSS_LOC_DATA_AGC_BIT == + (dataNotify.gnssDataMask[sig] & GNSS_LOC_DATA_AGC_BIT)) { + LOC_LOGv("agc[%d]=%f", sig, dataNotify.agc[sig]); + } + } + for (auto it = mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.gnssDataCb) { + it->second.gnssDataCb(dataNotify); + } + } +} + +bool +GnssAdapter::requestNiNotifyEvent(const GnssNiNotification ¬ify, const void* data, + const LocInEmergency emergencyState) +{ + LOC_LOGI("%s]: notif_type: %d, timeout: %d, default_resp: %d" + "requestor_id: %s (encoding: %d) text: %s text (encoding: %d) extras: %s", + __func__, notify.type, notify.timeout, notify.timeoutResponse, + notify.requestor, notify.requestorEncoding, + notify.message, notify.messageEncoding, notify.extras); + + struct MsgReportNiNotify : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + const GnssNiNotification mNotify; + const void* mData; + const LocInEmergency mEmergencyState; + inline MsgReportNiNotify(GnssAdapter& adapter, + LocApiBase& api, + const GnssNiNotification& notify, + const void* data, + const LocInEmergency emergencyState) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mNotify(notify), + mData(data), + mEmergencyState(emergencyState) {} + inline virtual void proc() const { + bool bIsInEmergency = false; + bool bInformNiAccept = false; + + bIsInEmergency = ((LOC_IN_EMERGENCY_UNKNOWN == mEmergencyState) && + mAdapter.getE911State()) || // older modems + (LOC_IN_EMERGENCY_SET == mEmergencyState); // newer modems + + if ((mAdapter.mSupportNfwControl || 0 == mAdapter.getAfwControlId()) && + (GNSS_NI_TYPE_SUPL == mNotify.type || GNSS_NI_TYPE_EMERGENCY_SUPL == mNotify.type) + && !bIsInEmergency && + !(GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT & mNotify.options) && + (GNSS_CONFIG_GPS_LOCK_NI & ContextBase::mGps_conf.GPS_LOCK) && + 1 == ContextBase::mGps_conf.NI_SUPL_DENY_ON_NFW_LOCKED) { + /* If all these conditions are TRUE, then deny the NI Request: + -'Q' Lock behavior OR 'P' Lock behavior and GNSS is Locked + -NI SUPL Request type or NI SUPL Emergency Request type + -NOT in an Emergency Call Session + -NOT Privacy Override option + -NFW is locked and config item NI_SUPL_DENY_ON_NFW_LOCKED = 1 */ + mApi.informNiResponse(GNSS_NI_RESPONSE_DENY, mData); + } else if (GNSS_NI_TYPE_EMERGENCY_SUPL == mNotify.type) { + bInformNiAccept = bIsInEmergency || + (GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO == ContextBase::mGps_conf.SUPL_ES); + + if (bInformNiAccept) { + mAdapter.requestNiNotify(mNotify, mData, bInformNiAccept); + } else { + mApi.informNiResponse(GNSS_NI_RESPONSE_DENY, mData); + } + } else if (GNSS_NI_TYPE_CONTROL_PLANE == mNotify.type) { + if (bIsInEmergency && (1 == ContextBase::mGps_conf.CP_MTLR_ES)) { + mApi.informNiResponse(GNSS_NI_RESPONSE_ACCEPT, mData); + } + else { + mAdapter.requestNiNotify(mNotify, mData, false); + } + } else { + mAdapter.requestNiNotify(mNotify, mData, false); + } + } + }; + + sendMsg(new MsgReportNiNotify(*this, *mLocApi, notify, data, emergencyState)); + + return true; +} + +void +GnssAdapter::reportLocationSystemInfoEvent(const LocationSystemInfo & locationSystemInfo) { + + // send system info to engine hub + mEngHubProxy->gnssReportSystemInfo(locationSystemInfo); + + struct MsgLocationSystemInfo : public LocMsg { + GnssAdapter& mAdapter; + LocationSystemInfo mSystemInfo; + inline MsgLocationSystemInfo(GnssAdapter& adapter, + const LocationSystemInfo& systemInfo) : + LocMsg(), + mAdapter(adapter), + mSystemInfo(systemInfo) {} + inline virtual void proc() const { + mAdapter.reportLocationSystemInfo(mSystemInfo); + } + }; + + sendMsg(new MsgLocationSystemInfo(*this, locationSystemInfo)); +} + +void +GnssAdapter::reportLocationSystemInfo(const LocationSystemInfo & locationSystemInfo) { + // save the info into the master copy piece by piece, as other system info + // may come at different time + if (locationSystemInfo.systemInfoMask & LOCATION_SYS_INFO_LEAP_SECOND) { + mLocSystemInfo.systemInfoMask |= LOCATION_SYS_INFO_LEAP_SECOND; + + const LeapSecondSystemInfo &srcLeapSecondSysInfo = locationSystemInfo.leapSecondSysInfo; + LeapSecondSystemInfo &dstLeapSecondSysInfo = mLocSystemInfo.leapSecondSysInfo; + if (srcLeapSecondSysInfo.leapSecondInfoMask & + LEAP_SECOND_SYS_INFO_CURRENT_LEAP_SECONDS_BIT) { + dstLeapSecondSysInfo.leapSecondInfoMask |= + LEAP_SECOND_SYS_INFO_CURRENT_LEAP_SECONDS_BIT; + dstLeapSecondSysInfo.leapSecondCurrent = srcLeapSecondSysInfo.leapSecondCurrent; + } + // once leap second change event is complete, modem may send up event invalidate the leap + // second change info while AP is still processing report during leap second transition + // so, we choose to keep this info around even though it is old + if (srcLeapSecondSysInfo.leapSecondInfoMask & LEAP_SECOND_SYS_INFO_LEAP_SECOND_CHANGE_BIT) { + dstLeapSecondSysInfo.leapSecondInfoMask |= LEAP_SECOND_SYS_INFO_LEAP_SECOND_CHANGE_BIT; + dstLeapSecondSysInfo.leapSecondChangeInfo = srcLeapSecondSysInfo.leapSecondChangeInfo; + } + } + + // we received new info, inform client of the newly received info + if (locationSystemInfo.systemInfoMask) { + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (it->second.locationSystemInfoCb != nullptr) { + it->second.locationSystemInfoCb(locationSystemInfo); + } + } + } +} + +static void* niThreadProc(void *args) +{ + NiSession* pSession = (NiSession*)args; + int rc = 0; /* return code from pthread calls */ + + struct timespec present_time; + struct timespec expire_time; + + pthread_mutex_lock(&pSession->tLock); + /* Calculate absolute expire time */ + clock_gettime(CLOCK_MONOTONIC, &present_time); + expire_time.tv_sec = present_time.tv_sec + pSession->respTimeLeft; + expire_time.tv_nsec = present_time.tv_nsec; + LOC_LOGD("%s]: time out set for abs time %ld with delay %d sec", + __func__, (long)expire_time.tv_sec, pSession->respTimeLeft); + + while (!pSession->respRecvd) { + rc = pthread_cond_timedwait(&pSession->tCond, + &pSession->tLock, + &expire_time); + if (rc == ETIMEDOUT) { + pSession->resp = GNSS_NI_RESPONSE_NO_RESPONSE; + LOC_LOGD("%s]: time out after valting for specified time. Ret Val %d", + __func__, rc); + break; + } + } + LOC_LOGD("%s]: Java layer has sent us a user response and return value from " + "pthread_cond_timedwait = %d pSession->resp is %u", __func__, rc, pSession->resp); + pSession->respRecvd = false; /* Reset the user response flag for the next session*/ + + // adding this check to support modem restart, in which case, we need the thread + // to exit without calling sending data. We made sure that rawRequest is NULL in + // loc_eng_ni_reset_on_engine_restart() + GnssAdapter* adapter = pSession->adapter; + GnssNiResponse resp; + void* rawRequest = NULL; + bool sendResponse = false; + + if (NULL != pSession->rawRequest) { + if (pSession->resp != GNSS_NI_RESPONSE_IGNORE) { + resp = pSession->resp; + rawRequest = pSession->rawRequest; + sendResponse = true; + } else { + free(pSession->rawRequest); + } + pSession->rawRequest = NULL; + } + pthread_mutex_unlock(&pSession->tLock); + + pSession->respTimeLeft = 0; + pSession->reqID = 0; + + if (sendResponse) { + adapter->gnssNiResponseCommand(resp, rawRequest); + } + + return NULL; +} + +bool +GnssAdapter::requestNiNotify(const GnssNiNotification& notify, const void* data, + const bool bInformNiAccept) +{ + NiSession* pSession = NULL; + gnssNiCallback gnssNiCb = nullptr; + + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.gnssNiCb) { + gnssNiCb = it->second.gnssNiCb; + break; + } + } + if (nullptr == gnssNiCb) { + if (GNSS_NI_TYPE_EMERGENCY_SUPL == notify.type) { + if (bInformNiAccept) { + mLocApi->informNiResponse(GNSS_NI_RESPONSE_ACCEPT, data); + NiData& niData = getNiData(); + // ignore any SUPL NI non-Es session if a SUPL NI ES is accepted + if (NULL != niData.session.rawRequest) { + pthread_mutex_lock(&niData.session.tLock); + niData.session.resp = GNSS_NI_RESPONSE_IGNORE; + niData.session.respRecvd = true; + pthread_cond_signal(&niData.session.tCond); + pthread_mutex_unlock(&niData.session.tLock); + } + } + } + EXIT_LOG(%s, "no clients with gnssNiCb."); + return false; + } + + if (notify.type == GNSS_NI_TYPE_EMERGENCY_SUPL) { + if (NULL != mNiData.sessionEs.rawRequest) { + LOC_LOGI("%s]: supl es NI in progress, new supl es NI ignored, type: %d", + __func__, notify.type); + if (NULL != data) { + free((void*)data); + } + } else { + pSession = &mNiData.sessionEs; + } + } else { + if (NULL != mNiData.session.rawRequest || + NULL != mNiData.sessionEs.rawRequest) { + LOC_LOGI("%s]: supl NI in progress, new supl NI ignored, type: %d", + __func__, notify.type); + if (NULL != data) { + free((void*)data); + } + } else { + pSession = &mNiData.session; + } + } + + if (pSession) { + /* Save request */ + pSession->rawRequest = (void*)data; + pSession->reqID = ++mNiData.reqIDCounter; + pSession->adapter = this; + + int sessionId = pSession->reqID; + + /* For robustness, spawn a thread at this point to timeout to clear up the notification + * status, even though the OEM layer in java does not do so. + **/ + pSession->respTimeLeft = + 5 + (notify.timeout != 0 ? notify.timeout : LOC_NI_NO_RESPONSE_TIME); + + int rc = 0; + rc = pthread_create(&pSession->thread, NULL, niThreadProc, pSession); + if (rc) { + LOC_LOGE("%s]: Loc NI thread is not created.", __func__); + } + rc = pthread_detach(pSession->thread); + if (rc) { + LOC_LOGE("%s]: Loc NI thread is not detached.", __func__); + } + + if (nullptr != gnssNiCb) { + gnssNiCb(sessionId, notify); + } + } + + return true; +} + +void +GnssAdapter::reportGnssMeasurementsEvent(const GnssMeasurements& gnssMeasurements, + int msInWeek) +{ + LOC_LOGD("%s]: msInWeek=%d", __func__, msInWeek); + + if (0 != gnssMeasurements.gnssMeasNotification.count) { + struct MsgReportGnssMeasurementData : public LocMsg { + GnssAdapter& mAdapter; + GnssMeasurements mGnssMeasurements; + GnssMeasurementsNotification mMeasurementsNotify; + inline MsgReportGnssMeasurementData(GnssAdapter& adapter, + const GnssMeasurements& gnssMeasurements, + int msInWeek) : + LocMsg(), + mAdapter(adapter), + mMeasurementsNotify(gnssMeasurements.gnssMeasNotification) { + if (-1 != msInWeek) { + mAdapter.getAgcInformation(mMeasurementsNotify, msInWeek); + } + } + inline virtual void proc() const { + mAdapter.reportGnssMeasurementData(mMeasurementsNotify); + } + }; + + sendMsg(new MsgReportGnssMeasurementData(*this, gnssMeasurements, msInWeek)); + } + mEngHubProxy->gnssReportSvMeasurement(gnssMeasurements.gnssSvMeasurementSet); + if (mDGnssNeedReport) { + reportDGnssDataUsable(gnssMeasurements.gnssSvMeasurementSet); + } +} + +void +GnssAdapter::reportGnssMeasurementData(const GnssMeasurementsNotification& measurements) +{ + for (auto it=mClientData.begin(); it != mClientData.end(); ++it) { + if (nullptr != it->second.gnssMeasurementsCb) { + it->second.gnssMeasurementsCb(measurements); + } + } +} + +void +GnssAdapter::reportDGnssDataUsable(const GnssSvMeasurementSet &svMeasurementSet) +{ + uint32_t i; + bool preDGnssDataUsage = mDGnssDataUsage; + + mDGnssDataUsage = false; + for (i = 0; i < svMeasurementSet.svMeasCount; i++) { + const Gnss_SVMeasurementStructType& svMeas = svMeasurementSet.svMeas[i]; + if (svMeas.dgnssSvMeas.dgnssMeasStatus) { + mDGnssDataUsage = true; + break; + } + } + if (mDGnssDataUsage != preDGnssDataUsage) { + if (mCdfwInterface) { + mCdfwInterface->reportUsable(mQDgnssListenerHDL, mDGnssDataUsage); + } + } +} + +void +GnssAdapter::reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial) +{ + LOC_LOGD("%s]: ", __func__); + mEngHubProxy->gnssReportSvPolynomial(svPolynomial); +} + +void +GnssAdapter::reportSvEphemerisEvent(GnssSvEphemerisReport & svEphemeris) +{ + LOC_LOGD("%s]:", __func__); + mEngHubProxy->gnssReportSvEphemeris(svEphemeris); +} + + +bool +GnssAdapter::requestOdcpiEvent(OdcpiRequestInfo& request) +{ + struct MsgRequestOdcpi : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestInfo mOdcpiRequest; + inline MsgRequestOdcpi(GnssAdapter& adapter, OdcpiRequestInfo& request) : + LocMsg(), + mAdapter(adapter), + mOdcpiRequest(request) {} + inline virtual void proc() const { + mAdapter.requestOdcpi(mOdcpiRequest); + } + }; + + sendMsg(new MsgRequestOdcpi(*this, request)); + return true; +} + +void GnssAdapter::requestOdcpi(const OdcpiRequestInfo& request) +{ + if (nullptr != mOdcpiRequestCb) { + LOC_LOGd("request: type %d, tbf %d, isEmergency %d" + " requestActive: %d timerActive: %d", + request.type, request.tbfMillis, request.isEmergencyMode, + mOdcpiRequestActive, mOdcpiTimer.isActive()); + // ODCPI START and ODCPI STOP from modem can come in quick succession + // so the mOdcpiTimer helps avoid spamming the framework as well as + // extending the odcpi session past 30 seconds if needed + if (ODCPI_REQUEST_TYPE_START == request.type) { + if (false == mOdcpiRequestActive && false == mOdcpiTimer.isActive()) { + mOdcpiRequestCb(request); + mOdcpiRequestActive = true; + mOdcpiTimer.start(); + // if the current active odcpi session is non-emergency, and the new + // odcpi request is emergency, replace the odcpi request with new request + // and restart the timer + } else if (false == mOdcpiRequest.isEmergencyMode && + true == request.isEmergencyMode) { + mOdcpiRequestCb(request); + mOdcpiRequestActive = true; + if (true == mOdcpiTimer.isActive()) { + mOdcpiTimer.restart(); + } else { + mOdcpiTimer.start(); + } + // if ODCPI request is not active but the timer is active, then + // just update the active state and wait for timer to expire + // before requesting new ODCPI to avoid spamming ODCPI requests + } else if (false == mOdcpiRequestActive && true == mOdcpiTimer.isActive()) { + mOdcpiRequestActive = true; + } + mOdcpiRequest = request; + // the request is being stopped, but allow timer to expire first + // before stopping the timer just in case more ODCPI requests come + // to avoid spamming more odcpi requests to the framework + } else if (ODCPI_REQUEST_TYPE_STOP == request.type) { + LOC_LOGd("request: type %d, isEmergency %d", request.type, request.isEmergencyMode); + mOdcpiRequestCb(request); + mOdcpiRequestActive = false; + } else { + LOC_LOGE("Invalid ODCPI request type.."); + } + } else { + LOC_LOGw("ODCPI request not supported"); + } +} + +bool GnssAdapter::reportDeleteAidingDataEvent(GnssAidingData& aidingData) +{ + LOC_LOGD("%s]:", __func__); + mEngHubProxy->gnssDeleteAidingData(aidingData); + return true; +} + +bool GnssAdapter::reportKlobucharIonoModelEvent(GnssKlobucharIonoModel & ionoModel) +{ + LOC_LOGD("%s]:", __func__); + mEngHubProxy->gnssReportKlobucharIonoModel(ionoModel); + return true; +} + +bool GnssAdapter::reportGnssAdditionalSystemInfoEvent( + GnssAdditionalSystemInfo & additionalSystemInfo) +{ + LOC_LOGD("%s]:", __func__); + mEngHubProxy->gnssReportAdditionalSystemInfo(additionalSystemInfo); + return true; +} + +bool GnssAdapter::reportQwesCapabilities( + const std::unordered_map &featureMap) +{ + struct MsgReportQwesFeatureStatus : public LocMsg { + GnssAdapter& mAdapter; + const std::unordered_map mFeatureMap; + inline MsgReportQwesFeatureStatus(GnssAdapter& adapter, + const std::unordered_map &featureMap) : + LocMsg(), + mAdapter(adapter), + mFeatureMap(std::move(featureMap)) {} + inline virtual void proc() const { + LOC_LOGi("ReportQwesFeatureStatus before caps %" PRIx64 " ", + mAdapter.getCapabilities()); + ContextBase::setQwesFeatureStatus(mFeatureMap); + LOC_LOGi("ReportQwesFeatureStatus After caps %" PRIx64 " ", + mAdapter.getCapabilities()); + mAdapter.broadcastCapabilities(mAdapter.getCapabilities()); + } + }; + + sendMsg(new MsgReportQwesFeatureStatus(*this, featureMap)); + return true; +} + +void GnssAdapter::initOdcpiCommand(const OdcpiRequestCallback& callback, + OdcpiPrioritytype priority) +{ + struct MsgInitOdcpi : public LocMsg { + GnssAdapter& mAdapter; + OdcpiRequestCallback mOdcpiCb; + OdcpiPrioritytype mPriority; + inline MsgInitOdcpi(GnssAdapter& adapter, + const OdcpiRequestCallback& callback, + OdcpiPrioritytype priority) : + LocMsg(), + mAdapter(adapter), + mOdcpiCb(callback), mPriority(priority){} + inline virtual void proc() const { + mAdapter.initOdcpi(mOdcpiCb, mPriority); + } + }; + + sendMsg(new MsgInitOdcpi(*this, callback, priority)); +} + +void GnssAdapter::initOdcpi(const OdcpiRequestCallback& callback, + OdcpiPrioritytype priority) +{ + LOC_LOGd("In priority: %d, Curr priority: %d", priority, mCallbackPriority); + if (priority >= mCallbackPriority) { + mOdcpiRequestCb = callback; + mCallbackPriority = priority; + /* Register for WIFI request */ + updateEvtMask(LOC_API_ADAPTER_BIT_REQUEST_WIFI, + LOC_REGISTRATION_MASK_ENABLED); + } +} + +void GnssAdapter::injectOdcpiCommand(const Location& location) +{ + struct MsgInjectOdcpi : public LocMsg { + GnssAdapter& mAdapter; + Location mLocation; + inline MsgInjectOdcpi(GnssAdapter& adapter, const Location& location) : + LocMsg(), + mAdapter(adapter), + mLocation(location) {} + inline virtual void proc() const { + mAdapter.injectOdcpi(mLocation); + } + }; + + sendMsg(new MsgInjectOdcpi(*this, location)); +} + +void GnssAdapter::injectOdcpi(const Location& location) +{ + LOC_LOGd("ODCPI Injection: requestActive: %d timerActive: %d" + "lat %.7f long %.7f", + mOdcpiRequestActive, mOdcpiTimer.isActive(), + location.latitude, location.longitude); + + mLocApi->injectPosition(location, true); +} + +// Called in the context of LocTimer thread +void OdcpiTimer::timeOutCallback() +{ + if (nullptr != mAdapter) { + mAdapter->odcpiTimerExpireEvent(); + } +} + +// Called in the context of LocTimer thread +void GnssAdapter::odcpiTimerExpireEvent() +{ + struct MsgOdcpiTimerExpire : public LocMsg { + GnssAdapter& mAdapter; + inline MsgOdcpiTimerExpire(GnssAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + inline virtual void proc() const { + mAdapter.odcpiTimerExpire(); + } + }; + sendMsg(new MsgOdcpiTimerExpire(*this)); +} +void GnssAdapter::odcpiTimerExpire() +{ + LOC_LOGd("requestActive: %d timerActive: %d", + mOdcpiRequestActive, mOdcpiTimer.isActive()); + + // if ODCPI request is still active after timer + // expires, request again and restart timer + if (mOdcpiRequestActive) { + mOdcpiRequestCb(mOdcpiRequest); + mOdcpiTimer.restart(); + } else { + mOdcpiTimer.stop(); + } +} + +void +GnssAdapter::invokeGnssEnergyConsumedCallback(uint64_t energyConsumedSinceFirstBoot) { + if (mGnssEnergyConsumedCb) { + mGnssEnergyConsumedCb(energyConsumedSinceFirstBoot); + mGnssEnergyConsumedCb = nullptr; + } +} + +bool +GnssAdapter::reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot){ + LOC_LOGD("%s]: %" PRIu64 " ", __func__, energyConsumedSinceFirstBoot); + + struct MsgReportGnssGnssEngEnergyConsumed : public LocMsg { + GnssAdapter& mAdapter; + uint64_t mGnssEnergyConsumedSinceFirstBoot; + inline MsgReportGnssGnssEngEnergyConsumed(GnssAdapter& adapter, + uint64_t energyConsumed) : + LocMsg(), + mAdapter(adapter), + mGnssEnergyConsumedSinceFirstBoot(energyConsumed) {} + inline virtual void proc() const { + mAdapter.invokeGnssEnergyConsumedCallback(mGnssEnergyConsumedSinceFirstBoot); + } + }; + + sendMsg(new MsgReportGnssGnssEngEnergyConsumed(*this, energyConsumedSinceFirstBoot)); + return true; +} + +void GnssAdapter::initDefaultAgps() { + LOC_LOGD("%s]: ", __func__); + void *handle = nullptr; + + LocAgpsGetAgpsCbInfo getAgpsCbInfo = + (LocAgpsGetAgpsCbInfo)dlGetSymFromLib(handle, "libloc_net_iface.so", + "LocNetIfaceAgps_getAgpsCbInfo"); + // Below step is to make sure we init nativeAgpsHandler + // for Android platforms only + AgpsCbInfo cbInfo = {}; + if (nullptr != getAgpsCbInfo) { + cbInfo = getAgpsCbInfo(agpsOpenResultCb, agpsCloseResultCb, this); + } else { + cbInfo = mNativeAgpsHandler.getAgpsCbInfo(); + } + + if (cbInfo.statusV4Cb == nullptr) { + LOC_LOGE("%s]: statusV4Cb is nullptr!", __func__); + dlclose(handle); + return; + } + + initAgps(cbInfo); +} + +void GnssAdapter::initDefaultAgpsCommand() { + LOC_LOGD("%s]: ", __func__); + + struct MsgInitDefaultAgps : public LocMsg { + GnssAdapter& mAdapter; + inline MsgInitDefaultAgps(GnssAdapter& adapter) : + LocMsg(), + mAdapter(adapter) { + } + inline virtual void proc() const { + mAdapter.initDefaultAgps(); + } + }; + + sendMsg(new MsgInitDefaultAgps(*this)); +} + +/* INIT LOC AGPS MANAGER */ + +void GnssAdapter::initAgps(const AgpsCbInfo& cbInfo) { + LOC_LOGD("%s]:cbInfo.atlType - %d", __func__, cbInfo.atlType); + + if (!((ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSB) || + (ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSA))) { + return; + } + + mAgpsManager.createAgpsStateMachines(cbInfo); + /* Register for AGPS event mask */ + updateEvtMask(LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST, + LOC_REGISTRATION_MASK_ENABLED); +} + +void GnssAdapter::initAgpsCommand(const AgpsCbInfo& cbInfo){ + LOC_LOGI("GnssAdapter::initAgpsCommand"); + + /* Message to initialize AGPS module */ + struct AgpsMsgInit: public LocMsg { + const AgpsCbInfo mCbInfo; + GnssAdapter& mAdapter; + + inline AgpsMsgInit(const AgpsCbInfo& cbInfo, + GnssAdapter& adapter) : + LocMsg(), mCbInfo(cbInfo), mAdapter(adapter) { + LOC_LOGV("AgpsMsgInit"); + } + + inline virtual void proc() const { + LOC_LOGV("AgpsMsgInit::proc()"); + mAdapter.initAgps(mCbInfo); + } + }; + + /* Send message to initialize AGPS Manager */ + sendMsg(new AgpsMsgInit(cbInfo, *this)); +} + +void GnssAdapter::initNfwCommand(const NfwCbInfo& cbInfo) { + LOC_LOGi("GnssAdapter::initNfwCommand"); + + /* Message to initialize NFW */ + struct MsgInitNfw : public LocMsg { + const NfwCbInfo mCbInfo; + GnssAdapter& mAdapter; + + inline MsgInitNfw(const NfwCbInfo& cbInfo, + GnssAdapter& adapter) : + LocMsg(), mCbInfo(cbInfo), mAdapter(adapter) { + LOC_LOGv("MsgInitNfw"); + } + + inline virtual void proc() const { + LOC_LOGv("MsgInitNfw::proc()"); + mAdapter.initNfw(mCbInfo); + } + }; + + /* Send message to initialize NFW */ + sendMsg(new MsgInitNfw(cbInfo, *this)); +} + +void GnssAdapter::reportNfwNotificationEvent(GnssNfwNotification& notification) { + LOC_LOGi("GnssAdapter::reportNfwNotificationEvent"); + + struct MsgReportNfwNotification : public LocMsg { + const GnssNfwNotification mNotification; + GnssAdapter& mAdapter; + + inline MsgReportNfwNotification(const GnssNfwNotification& notification, + GnssAdapter& adapter) : + LocMsg(), mNotification(notification), mAdapter(adapter) { + LOC_LOGv("MsgReportNfwNotification"); + } + + inline virtual void proc() const { + LOC_LOGv("MsgReportNfwNotification::proc()"); + mAdapter.reportNfwNotification(mNotification); + } + }; + + sendMsg(new MsgReportNfwNotification(notification, *this)); +} + +/* GnssAdapter::requestATL + * Method triggered in QMI thread as part of handling below message: + * eQMI_LOC_SERVER_REQUEST_OPEN_V02 + * Triggers the AGPS state machine to setup AGPS call for below WWAN types: + * eQMI_LOC_WWAN_TYPE_INTERNET_V02 + * eQMI_LOC_WWAN_TYPE_AGNSS_V02 + * eQMI_LOC_WWAN_TYPE_AGNSS_EMERGENCY_V02 */ +bool GnssAdapter::requestATL(int connHandle, LocAGpsType agpsType, + LocApnTypeMask apnTypeMask){ + + LOC_LOGI("GnssAdapter::requestATL handle=%d agpsType=0x%X apnTypeMask=0x%X", + connHandle, agpsType, apnTypeMask); + + sendMsg( new AgpsMsgRequestATL( + &mAgpsManager, connHandle, (AGpsExtType)agpsType, + apnTypeMask)); + + return true; +} + +/* GnssAdapter::releaseATL + * Method triggered in QMI thread as part of handling below message: + * eQMI_LOC_SERVER_REQUEST_CLOSE_V02 + * Triggers teardown of an existing AGPS call */ +bool GnssAdapter::releaseATL(int connHandle){ + + LOC_LOGI("GnssAdapter::releaseATL"); + + /* Release SUPL/INTERNET/SUPL_ES ATL */ + struct AgpsMsgReleaseATL: public LocMsg { + + AgpsManager* mAgpsManager; + int mConnHandle; + + inline AgpsMsgReleaseATL(AgpsManager* agpsManager, int connHandle) : + LocMsg(), mAgpsManager(agpsManager), mConnHandle(connHandle) { + + LOC_LOGV("AgpsMsgReleaseATL"); + } + + inline virtual void proc() const { + + LOC_LOGV("AgpsMsgReleaseATL::proc()"); + mAgpsManager->releaseATL(mConnHandle); + } + }; + + sendMsg( new AgpsMsgReleaseATL(&mAgpsManager, connHandle)); + + return true; +} + +void GnssAdapter::dataConnOpenCommand( + AGpsExtType agpsType, + const char* apnName, int apnLen, AGpsBearerType bearerType){ + + LOC_LOGI("GnssAdapter::frameworkDataConnOpen"); + + struct AgpsMsgAtlOpenSuccess: public LocMsg { + + AgpsManager* mAgpsManager; + AGpsExtType mAgpsType; + char* mApnName; + int mApnLen; + AGpsBearerType mBearerType; + + inline AgpsMsgAtlOpenSuccess(AgpsManager* agpsManager, AGpsExtType agpsType, + const char* apnName, int apnLen, AGpsBearerType bearerType) : + LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType), mApnName( + new char[apnLen + 1]), mApnLen(apnLen), mBearerType(bearerType) { + + LOC_LOGV("AgpsMsgAtlOpenSuccess"); + if (mApnName == nullptr) { + LOC_LOGE("%s] new allocation failed, fatal error.", __func__); + // Reporting the failure here + mAgpsManager->reportAtlClosed(mAgpsType); + return; + } + memcpy(mApnName, apnName, apnLen); + mApnName[apnLen] = 0; + } + + inline ~AgpsMsgAtlOpenSuccess() { + delete[] mApnName; + } + + inline virtual void proc() const { + + LOC_LOGV("AgpsMsgAtlOpenSuccess::proc()"); + mAgpsManager->reportAtlOpenSuccess(mAgpsType, mApnName, mApnLen, mBearerType); + } + }; + // Added inital length checks for apnlen check to avoid security issues + // In case of failure reporting the same + if (NULL == apnName || apnLen <= 0 || apnLen > MAX_APN_LEN || + (strlen(apnName) != (unsigned)apnLen)) { + LOC_LOGe("%s]: incorrect apnlen length or incorrect apnName", __func__); + mAgpsManager.reportAtlClosed(agpsType); + } else { + sendMsg( new AgpsMsgAtlOpenSuccess( + &mAgpsManager, agpsType, apnName, apnLen, bearerType)); + } +} + +void GnssAdapter::dataConnClosedCommand(AGpsExtType agpsType){ + + LOC_LOGI("GnssAdapter::frameworkDataConnClosed"); + + struct AgpsMsgAtlClosed: public LocMsg { + + AgpsManager* mAgpsManager; + AGpsExtType mAgpsType; + + inline AgpsMsgAtlClosed(AgpsManager* agpsManager, AGpsExtType agpsType) : + LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType) { + + LOC_LOGV("AgpsMsgAtlClosed"); + } + + inline virtual void proc() const { + + LOC_LOGV("AgpsMsgAtlClosed::proc()"); + mAgpsManager->reportAtlClosed(mAgpsType); + } + }; + + sendMsg( new AgpsMsgAtlClosed(&mAgpsManager, (AGpsExtType)agpsType)); +} + +void GnssAdapter::dataConnFailedCommand(AGpsExtType agpsType){ + + LOC_LOGI("GnssAdapter::frameworkDataConnFailed"); + + struct AgpsMsgAtlOpenFailed: public LocMsg { + + AgpsManager* mAgpsManager; + AGpsExtType mAgpsType; + + inline AgpsMsgAtlOpenFailed(AgpsManager* agpsManager, AGpsExtType agpsType) : + LocMsg(), mAgpsManager(agpsManager), mAgpsType(agpsType) { + + LOC_LOGV("AgpsMsgAtlOpenFailed"); + } + + inline virtual void proc() const { + + LOC_LOGV("AgpsMsgAtlOpenFailed::proc()"); + mAgpsManager->reportAtlOpenFailed(mAgpsType); + } + }; + + sendMsg( new AgpsMsgAtlOpenFailed(&mAgpsManager, (AGpsExtType)agpsType)); +} + +void GnssAdapter::convertSatelliteInfo(std::vector& out, + const GnssSvType& in_constellation, + const SystemStatusReports& in) +{ + uint64_t sv_mask = 0ULL; + uint32_t svid_min = 0; + uint32_t svid_num = 0; + uint32_t svid_idx = 0; + + uint64_t eph_health_good_mask = 0ULL; + uint64_t eph_health_bad_mask = 0ULL; + uint64_t server_perdiction_available_mask = 0ULL; + float server_perdiction_age = 0.0f; + + // set constellationi based parameters + switch (in_constellation) { + case GNSS_SV_TYPE_GPS: + svid_min = GNSS_BUGREPORT_GPS_MIN; + svid_num = GPS_NUM; + svid_idx = 0; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mGpsGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mGpsBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mGpsXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mGpsXtraAge); + } + break; + case GNSS_SV_TYPE_GLONASS: + svid_min = GNSS_BUGREPORT_GLO_MIN; + svid_num = GLO_NUM; + svid_idx = GPS_NUM; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mGloGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mGloBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mGloXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mGloXtraAge); + } + break; + case GNSS_SV_TYPE_QZSS: + svid_min = GNSS_BUGREPORT_QZSS_MIN; + svid_num = QZSS_NUM; + svid_idx = GPS_NUM+GLO_NUM+BDS_NUM+GAL_NUM; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mQzssGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mQzssBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mQzssXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mQzssXtraAge); + } + break; + case GNSS_SV_TYPE_BEIDOU: + svid_min = GNSS_BUGREPORT_BDS_MIN; + svid_num = BDS_NUM; + svid_idx = GPS_NUM+GLO_NUM; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mBdsGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mBdsBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mBdsXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mBdsXtraAge); + } + break; + case GNSS_SV_TYPE_GALILEO: + svid_min = GNSS_BUGREPORT_GAL_MIN; + svid_num = GAL_NUM; + svid_idx = GPS_NUM+GLO_NUM+BDS_NUM; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mGalGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mGalBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mGalXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mGalXtraAge); + } + break; + case GNSS_SV_TYPE_NAVIC: + svid_min = GNSS_BUGREPORT_NAVIC_MIN; + svid_num = NAVIC_NUM; + svid_idx = GPS_NUM+GLO_NUM+QZSS_NUM+BDS_NUM+GAL_NUM; + if (!in.mSvHealth.empty()) { + eph_health_good_mask = in.mSvHealth.back().mNavicGoodMask; + eph_health_bad_mask = in.mSvHealth.back().mNavicBadMask; + } + if (!in.mXtra.empty()) { + server_perdiction_available_mask = in.mXtra.back().mNavicXtraValid; + server_perdiction_age = (float)(in.mXtra.back().mNavicXtraAge); + } + break; + default: + return; + } + + // extract each sv info from systemstatus report + for(uint32_t i=0; igetReport(reports, true); + + r.size = sizeof(r); + + // location block + r.mLocation.size = sizeof(r.mLocation); + if(!reports.mLocation.empty() && reports.mLocation.back().mValid) { + r.mLocation.mValid = true; + r.mLocation.mLocation.latitude = + reports.mLocation.back().mLocation.gpsLocation.latitude; + r.mLocation.mLocation.longitude = + reports.mLocation.back().mLocation.gpsLocation.longitude; + r.mLocation.mLocation.altitude = + reports.mLocation.back().mLocation.gpsLocation.altitude; + r.mLocation.mLocation.speed = + (double)(reports.mLocation.back().mLocation.gpsLocation.speed); + r.mLocation.mLocation.bearing = + (double)(reports.mLocation.back().mLocation.gpsLocation.bearing); + r.mLocation.mLocation.accuracy = + (double)(reports.mLocation.back().mLocation.gpsLocation.accuracy); + + r.mLocation.verticalAccuracyMeters = + reports.mLocation.back().mLocationEx.vert_unc; + r.mLocation.speedAccuracyMetersPerSecond = + reports.mLocation.back().mLocationEx.speed_unc; + r.mLocation.bearingAccuracyDegrees = + reports.mLocation.back().mLocationEx.bearing_unc; + + r.mLocation.mUtcReported = + reports.mLocation.back().mUtcReported; + } + else if(!reports.mBestPosition.empty() && reports.mBestPosition.back().mValid) { + r.mLocation.mValid = true; + r.mLocation.mLocation.latitude = + (double)(reports.mBestPosition.back().mBestLat) * RAD2DEG; + r.mLocation.mLocation.longitude = + (double)(reports.mBestPosition.back().mBestLon) * RAD2DEG; + r.mLocation.mLocation.altitude = reports.mBestPosition.back().mBestAlt; + r.mLocation.mLocation.accuracy = + (double)(reports.mBestPosition.back().mBestHepe); + + r.mLocation.mUtcReported = reports.mBestPosition.back().mUtcReported; + } + else { + r.mLocation.mValid = false; + } + + if (r.mLocation.mValid) { + LOC_LOGV("getDebugReport - lat=%f lon=%f alt=%f speed=%f", + r.mLocation.mLocation.latitude, + r.mLocation.mLocation.longitude, + r.mLocation.mLocation.altitude, + r.mLocation.mLocation.speed); + } + + // time block + r.mTime.size = sizeof(r.mTime); + if(!reports.mTimeAndClock.empty() && reports.mTimeAndClock.back().mTimeValid) { + r.mTime.mValid = true; + r.mTime.timeEstimate = + (((int64_t)(reports.mTimeAndClock.back().mGpsWeek)*7 + + GNSS_UTC_TIME_OFFSET)*24*60*60 - + (int64_t)(reports.mTimeAndClock.back().mLeapSeconds))*1000ULL + + (int64_t)(reports.mTimeAndClock.back().mGpsTowMs); + + if (reports.mTimeAndClock.back().mTimeUncNs > 0) { + // TimeUncNs value is available + r.mTime.timeUncertaintyNs = + (float)(reports.mTimeAndClock.back().mLeapSecUnc)*1000.0f + + (float)(reports.mTimeAndClock.back().mTimeUncNs); + } else { + // fall back to legacy TimeUnc + r.mTime.timeUncertaintyNs = + ((float)(reports.mTimeAndClock.back().mTimeUnc) + + (float)(reports.mTimeAndClock.back().mLeapSecUnc))*1000.0f; + } + + r.mTime.frequencyUncertaintyNsPerSec = + (float)(reports.mTimeAndClock.back().mClockFreqBiasUnc); + LOC_LOGV("getDebugReport - timeestimate=%" PRIu64 " unc=%f frequnc=%f", + r.mTime.timeEstimate, + r.mTime.timeUncertaintyNs, r.mTime.frequencyUncertaintyNsPerSec); + } + else { + r.mTime.mValid = false; + } + + // satellite info block + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_GPS, reports); + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_GLONASS, reports); + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_QZSS, reports); + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_BEIDOU, reports); + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_GALILEO, reports); + convertSatelliteInfo(r.mSatelliteInfo, GNSS_SV_TYPE_NAVIC, reports); + LOC_LOGV("getDebugReport - satellite=%zu", r.mSatelliteInfo.size()); + + return true; +} + +/* get AGC information from system status and fill it */ +void +GnssAdapter::getAgcInformation(GnssMeasurementsNotification& measurements, int msInWeek) +{ + SystemStatus* systemstatus = getSystemStatus(); + + if (nullptr != systemstatus) { + SystemStatusReports reports = {}; + systemstatus->getReport(reports, true); + + if ((!reports.mRfAndParams.empty()) && (!reports.mTimeAndClock.empty()) && + (abs(msInWeek - (int)reports.mTimeAndClock.back().mGpsTowMs) < 2000)) { + + for (size_t i = 0; i < measurements.count; i++) { + switch (measurements.measurements[i].svType) { + case GNSS_SV_TYPE_GPS: + case GNSS_SV_TYPE_QZSS: + measurements.measurements[i].agcLevelDb = + reports.mRfAndParams.back().mAgcGps; + measurements.measurements[i].flags |= + GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; + break; + + case GNSS_SV_TYPE_GALILEO: + measurements.measurements[i].agcLevelDb = + reports.mRfAndParams.back().mAgcGal; + measurements.measurements[i].flags |= + GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; + break; + + case GNSS_SV_TYPE_GLONASS: + measurements.measurements[i].agcLevelDb = + reports.mRfAndParams.back().mAgcGlo; + measurements.measurements[i].flags |= + GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; + break; + + case GNSS_SV_TYPE_BEIDOU: + measurements.measurements[i].agcLevelDb = + reports.mRfAndParams.back().mAgcBds; + measurements.measurements[i].flags |= + GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT; + break; + + case GNSS_SV_TYPE_SBAS: + case GNSS_SV_TYPE_UNKNOWN: + default: + break; + } + } + } + } +} + +/* get Data information from system status and fill it */ +void +GnssAdapter::getDataInformation(GnssDataNotification& data, int msInWeek) +{ + SystemStatus* systemstatus = getSystemStatus(); + + LOC_LOGV("%s]: msInWeek=%d", __func__, msInWeek); + if (nullptr != systemstatus) { + SystemStatusReports reports = {}; + systemstatus->getReport(reports, true); + + if ((!reports.mRfAndParams.empty()) && (!reports.mTimeAndClock.empty()) && + (abs(msInWeek - (int)reports.mTimeAndClock.back().mGpsTowMs) < 2000)) { + + for (int sig = GNSS_LOC_SIGNAL_TYPE_GPS_L1CA; + sig < GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES; sig++) { + data.gnssDataMask[sig] = 0; + data.jammerInd[sig] = 0.0; + data.agc[sig] = 0.0; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mAgcGps) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GPS_L1CA] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_GPS_L1CA] = + reports.mRfAndParams.back().mAgcGps; + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_QZSS_L1CA] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_QZSS_L1CA] = + reports.mRfAndParams.back().mAgcGps; + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_SBAS_L1_CA] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_SBAS_L1_CA] = + reports.mRfAndParams.back().mAgcGps; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mJammerGps) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GPS_L1CA] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_GPS_L1CA] = + (double)reports.mRfAndParams.back().mJammerGps; + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_QZSS_L1CA] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_QZSS_L1CA] = + (double)reports.mRfAndParams.back().mJammerGps; + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_SBAS_L1_CA] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_SBAS_L1_CA] = + (double)reports.mRfAndParams.back().mJammerGps; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mAgcGlo) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GLONASS_G1] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_GLONASS_G1] = + reports.mRfAndParams.back().mAgcGlo; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mJammerGlo) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GLONASS_G1] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_GLONASS_G1] = + (double)reports.mRfAndParams.back().mJammerGlo; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mAgcBds) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1_I] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1_I] = + reports.mRfAndParams.back().mAgcBds; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mJammerBds) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1_I] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1_I] = + (double)reports.mRfAndParams.back().mJammerBds; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mAgcGal) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GALILEO_E1_C] |= + GNSS_LOC_DATA_AGC_BIT; + data.agc[GNSS_LOC_SIGNAL_TYPE_GALILEO_E1_C] = + reports.mRfAndParams.back().mAgcGal; + } + if (GNSS_INVALID_JAMMER_IND != reports.mRfAndParams.back().mJammerGal) { + data.gnssDataMask[GNSS_LOC_SIGNAL_TYPE_GALILEO_E1_C] |= + GNSS_LOC_DATA_JAMMER_IND_BIT; + data.jammerInd[GNSS_LOC_SIGNAL_TYPE_GALILEO_E1_C] = + (double)reports.mRfAndParams.back().mJammerGal; + } + } + } +} + +/* Callbacks registered with loc_net_iface library */ +static void agpsOpenResultCb (bool isSuccess, AGpsExtType agpsType, const char* apn, + AGpsBearerType bearerType, void* userDataPtr) { + LOC_LOGD("%s]: ", __func__); + if (userDataPtr == nullptr) { + LOC_LOGE("%s]: userDataPtr is nullptr.", __func__); + return; + } + if (apn == nullptr) { + LOC_LOGE("%s]: apn is nullptr.", __func__); + return; + } + GnssAdapter* adapter = (GnssAdapter*)userDataPtr; + if (isSuccess) { + adapter->dataConnOpenCommand(agpsType, apn, strlen(apn), bearerType); + } else { + adapter->dataConnFailedCommand(agpsType); + } +} + +static void agpsCloseResultCb (bool isSuccess, AGpsExtType agpsType, void* userDataPtr) { + LOC_LOGD("%s]: ", __func__); + if (userDataPtr == nullptr) { + LOC_LOGE("%s]: userDataPtr is nullptr.", __func__); + return; + } + GnssAdapter* adapter = (GnssAdapter*)userDataPtr; + if (isSuccess) { + adapter->dataConnClosedCommand(agpsType); + } else { + adapter->dataConnFailedCommand(agpsType); + } +} + +void +GnssAdapter::saveGnssEnergyConsumedCallback(GnssEnergyConsumedCallback energyConsumedCb) { + mGnssEnergyConsumedCb = energyConsumedCb; +} + +void +GnssAdapter::getGnssEnergyConsumedCommand(GnssEnergyConsumedCallback energyConsumedCb) { + struct MsgGetGnssEnergyConsumed : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + GnssEnergyConsumedCallback mEnergyConsumedCb; + inline MsgGetGnssEnergyConsumed(GnssAdapter& adapter, LocApiBase& api, + GnssEnergyConsumedCallback energyConsumedCb) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mEnergyConsumedCb(energyConsumedCb){} + inline virtual void proc() const { + mAdapter.saveGnssEnergyConsumedCallback(mEnergyConsumedCb); + mApi.getGnssEnergyConsumed(); + } + }; + + sendMsg(new MsgGetGnssEnergyConsumed(*this, *mLocApi, energyConsumedCb)); +} + +void +GnssAdapter::nfwControlCommand(bool enable) { + struct MsgControlNfwLocationAccess : public LocMsg { + GnssAdapter& mAdapter; + LocApiBase& mApi; + bool mEnable; + inline MsgControlNfwLocationAccess(GnssAdapter& adapter, LocApiBase& api, + bool enable) : + LocMsg(), + mAdapter(adapter), + mApi(api), + mEnable(enable) {} + inline virtual void proc() const { + GnssConfigGpsLock gpsLock; + + gpsLock = ContextBase::mGps_conf.GPS_LOCK; + if (mEnable) { + gpsLock &= ~GNSS_CONFIG_GPS_LOCK_NI; + } else { + gpsLock |= GNSS_CONFIG_GPS_LOCK_NI; + } + ContextBase::mGps_conf.GPS_LOCK = gpsLock; + mApi.sendMsg(new LocApiMsg([&mApi = mApi, gpsLock]() { + mApi.setGpsLockSync((GnssConfigGpsLock)gpsLock); + })); + } + }; + + if (mSupportNfwControl) { + sendMsg(new MsgControlNfwLocationAccess(*this, *mLocApi, enable)); + } else { + LOC_LOGw("NFW control is not supported, do not use this for NFW"); + } +} + +// Set tunc constrained mode, use 0 session id to indicate +// that no callback is needed. Session id 0 is used for calls that +// are not invoked from the integration api, e.g.: initial configuration +// from the configure file +void +GnssAdapter::setConstrainedTunc(bool enable, float tuncConstraint, + uint32_t energyBudget, uint32_t sessionId) { + + mLocConfigInfo.tuncConfigInfo.isValid = true; + mLocConfigInfo.tuncConfigInfo.enable = enable; + mLocConfigInfo.tuncConfigInfo.tuncThresholdMs = tuncConstraint; + mLocConfigInfo.tuncConfigInfo.energyBudget = energyBudget; + + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->setConstrainedTuncMode( + enable, tuncConstraint, energyBudget, locApiResponse); +} + +uint32_t +GnssAdapter::setConstrainedTuncCommand (bool enable, float tuncConstraint, + uint32_t energyBudget) { + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgEnableTUNC : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + bool mEnable; + float mTuncConstraint; + uint32_t mEnergyBudget; + + inline MsgEnableTUNC(GnssAdapter& adapter, + uint32_t sessionId, + bool enable, + float tuncConstraint, + uint32_t energyBudget) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEnable(enable), + mTuncConstraint(tuncConstraint), + mEnergyBudget(energyBudget) {} + inline virtual void proc() const { + mAdapter.setConstrainedTunc(mEnable, mTuncConstraint, + mEnergyBudget, mSessionId); + } + }; + + sendMsg(new MsgEnableTUNC(*this, sessionId, enable, + tuncConstraint, energyBudget)); + + return sessionId; +} + +// Set position assisted clock estimator, use 0 session id to indicate +// that no callback is needed. Session id 0 is used for calls that are +// not invoked from the integration api, e.g.: initial configuration +// from the configure file. +void +GnssAdapter::setPositionAssistedClockEstimator(bool enable, + uint32_t sessionId) { + + mLocConfigInfo.paceConfigInfo.isValid = true; + mLocConfigInfo.paceConfigInfo.enable = enable; + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->setPositionAssistedClockEstimatorMode(enable, locApiResponse); +} + +uint32_t +GnssAdapter::setPositionAssistedClockEstimatorCommand(bool enable) { + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgEnablePACE : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + bool mEnable; + inline MsgEnablePACE(GnssAdapter& adapter, + uint32_t sessionId, bool enable) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEnable(enable){} + inline virtual void proc() const { + mAdapter.setPositionAssistedClockEstimator(mEnable, mSessionId); + } + }; + + sendMsg(new MsgEnablePACE(*this, sessionId, enable)); + return sessionId; +} + +void GnssAdapter::gnssUpdateSvConfig( + uint32_t sessionId, const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) { + + // suspend all tracking sessions to apply the constellation config + suspendSessions(); + if (constellationEnablementConfig.size == sizeof(constellationEnablementConfig)) { + // check whether if any constellation is removed from the new config + GnssSvTypesMask currentEnabledMask = mGnssSvTypeConfig.enabledSvTypesMask; + GnssSvTypesMask newEnabledMask = constellationEnablementConfig.enabledSvTypesMask; + GnssSvTypesMask enabledRemoved = currentEnabledMask & (currentEnabledMask ^ newEnabledMask); + // Send reset if any constellation is removed from the enabled list + if (enabledRemoved != 0) { + mLocApi->resetConstellationControl(); + } + + // if the constellation config is valid, issue request to modem + // to enable/disable constellation + mLocApi->setConstellationControl(mGnssSvTypeConfig); + } else if (constellationEnablementConfig.size == 0) { + // when the size is not set, meaning reset to modem default + mLocApi->resetConstellationControl(); + } + // save the constellation settings to be used for modem SSR + mGnssSvTypeConfig = constellationEnablementConfig; + + // handle blacklisted SV settings + mGnssSvIdConfig = blacklistSvConfig; + // process blacklist svs info + mBlacklistedSvIds.clear(); + // need to save the balcklisted sv info into mBlacklistedSvIds as well + convertFromGnssSvIdConfig(blacklistSvConfig, mBlacklistedSvIds); + LocApiResponse* locApiResponse = new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + mLocApi->setBlacklistSv(mGnssSvIdConfig, locApiResponse); + + // resume all tracking sessions after the constellation config has been applied + restartSessions(false); +} + +uint32_t +GnssAdapter::gnssUpdateSvConfigCommand( + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgUpdateSvConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + GnssSvTypeConfig mConstellationEnablementConfig; + GnssSvIdConfig mBlacklistSvIdConfig; + + inline MsgUpdateSvConfig(GnssAdapter& adapter, + uint32_t sessionId, + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mConstellationEnablementConfig(constellationEnablementConfig), + mBlacklistSvIdConfig(blacklistSvConfig) {} + inline virtual void proc() const { + mAdapter.gnssUpdateSvConfig(mSessionId, mConstellationEnablementConfig, + mBlacklistSvIdConfig); + } + }; + + if (sessionId != 0) { + sendMsg(new MsgUpdateSvConfig(*this, sessionId, constellationEnablementConfig, + blacklistSvConfig)); + } + return sessionId; +} + +void GnssAdapter::gnssUpdateSecondaryBandConfig( + uint32_t sessionId, const GnssSvTypeConfig& secondaryBandConfig) { + + LocApiResponse* locApiResponse = new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + + // handle secondary band info + mGnssSeconaryBandConfig = secondaryBandConfig; + gnssSecondaryBandConfigUpdate(locApiResponse); +} + +uint32_t +GnssAdapter::gnssUpdateSecondaryBandConfigCommand( + const GnssSvTypeConfig& secondaryBandConfig) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgUpdateSecondaryBandConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + GnssSvTypeConfig mSecondaryBandConfig; + + inline MsgUpdateSecondaryBandConfig(GnssAdapter& adapter, + uint32_t sessionId, + const GnssSvTypeConfig& secondaryBandConfig) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mSecondaryBandConfig(secondaryBandConfig) {} + inline virtual void proc() const { + mAdapter.gnssUpdateSecondaryBandConfig(mSessionId, mSecondaryBandConfig); + } + }; + + if (sessionId != 0) { + sendMsg(new MsgUpdateSecondaryBandConfig(*this, sessionId, secondaryBandConfig)); + } + return sessionId; +} + +// This function currently retrieves secondary band configuration +// for constellation enablement/disablement. +void +GnssAdapter::gnssGetSecondaryBandConfig(uint32_t sessionId) { + + LocApiResponse* locApiResponse = new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + + mLocApi->getConstellationMultiBandConfig(sessionId, locApiResponse); +} + +uint32_t +GnssAdapter::gnssGetSecondaryBandConfigCommand() { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgGetSecondaryBandConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + inline MsgGetSecondaryBandConfig(GnssAdapter& adapter, + uint32_t sessionId) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId) {} + inline virtual void proc() const { + mAdapter.gnssGetSecondaryBandConfig(mSessionId); + } + }; + + if (sessionId != 0) { + sendMsg(new MsgGetSecondaryBandConfig(*this, sessionId)); + } + return sessionId; +} + +void +GnssAdapter::configLeverArm(uint32_t sessionId, + const LeverArmConfigInfo& configInfo) { + + LocationError err = LOCATION_ERROR_NOT_SUPPORTED; + if (true == mEngHubProxy->configLeverArm(configInfo)) { + err = LOCATION_ERROR_SUCCESS; + } + reportResponse(err, sessionId); +} + +uint32_t +GnssAdapter::configLeverArmCommand(const LeverArmConfigInfo& configInfo) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgConfigLeverArm : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + LeverArmConfigInfo mConfigInfo; + + inline MsgConfigLeverArm(GnssAdapter& adapter, + uint32_t sessionId, + const LeverArmConfigInfo& configInfo) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mConfigInfo(configInfo) {} + inline virtual void proc() const { + // save the lever ARM config info for translating position from GNSS antenna based + // to VRP based + if (mConfigInfo.leverArmValidMask & LEVER_ARM_TYPE_GNSS_TO_VRP_BIT) { + mAdapter.mLocConfigInfo.leverArmConfigInfo.leverArmValidMask |= + LEVER_ARM_TYPE_GNSS_TO_VRP_BIT; + mAdapter.mLocConfigInfo.leverArmConfigInfo.gnssToVRP = mConfigInfo.gnssToVRP; + } + mAdapter.configLeverArm(mSessionId, mConfigInfo); + } + }; + + sendMsg(new MsgConfigLeverArm(*this, sessionId, configInfo)); + return sessionId; +} + +bool GnssAdapter::initMeasCorr(bool bSendCbWhenNotSupported) { + LOC_LOGv("GnssAdapter::initMeasCorr"); + /* Message to initialize Measurement Corrections */ + struct MsgInitMeasCorr : public LocMsg { + GnssAdapter& mAdapter; + GnssMeasurementCorrectionsCapabilitiesMask mCapMask; + + inline MsgInitMeasCorr(GnssAdapter& adapter, + GnssMeasurementCorrectionsCapabilitiesMask capMask) : + LocMsg(), mAdapter(adapter), mCapMask(capMask) { + LOC_LOGv("MsgInitMeasCorr"); + } + + inline virtual void proc() const { + LOC_LOGv("MsgInitMeasCorr::proc()"); + + mAdapter.mMeasCorrSetCapabilitiesCb(mCapMask); + } + }; + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION)) { + sendMsg(new MsgInitMeasCorr(*this, GNSS_MEAS_CORR_LOS_SATS | + GNSS_MEAS_CORR_EXCESS_PATH_LENGTH | GNSS_MEAS_CORR_REFLECTING_PLANE)); + return true; + } else { + LOC_LOGv("MEASUREMENTS_CORRECTION feature is not supported in the modem"); + if (bSendCbWhenNotSupported) { + sendMsg(new MsgInitMeasCorr(*this, 0)); + } + return false; + } +} + +bool GnssAdapter::openMeasCorrCommand(const measCorrSetCapabilitiesCb setCapabilitiesCb) { + LOC_LOGi("GnssAdapter::openMeasCorrCommand"); + + /* Send message to initialize Measurement Corrections */ + mMeasCorrSetCapabilitiesCb = setCapabilitiesCb; + mIsMeasCorrInterfaceOpen = true; + if (isEngineCapabilitiesKnown()) { + LOC_LOGv("Capabilities are known, proceed with measurement corrections init"); + return initMeasCorr(false); + } else { + LOC_LOGv("Capabilities are not known, wait for open"); + return true; + } +} + +bool GnssAdapter::measCorrSetCorrectionsCommand(const GnssMeasurementCorrections gnssMeasCorr) { + LOC_LOGi("GnssAdapter::measCorrSetCorrectionsCommand"); + + /* Message to set Measurement Corrections */ + struct MsgSetCorrectionsMeasCorr : public LocMsg { + const GnssMeasurementCorrections mGnssMeasCorr; + GnssAdapter& mAdapter; + LocApiBase& mApi; + + inline MsgSetCorrectionsMeasCorr( + const GnssMeasurementCorrections gnssMeasCorr, + GnssAdapter& adapter, + LocApiBase& api) : + LocMsg(), + mGnssMeasCorr(gnssMeasCorr), + mAdapter(adapter), + mApi(api) { + LOC_LOGv("MsgSetCorrectionsMeasCorr"); + } + + inline virtual void proc() const { + LOC_LOGv("MsgSetCorrectionsMeasCorr::proc()"); + mApi.setMeasurementCorrections(mGnssMeasCorr); + } + }; + + if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION)) { + sendMsg(new MsgSetCorrectionsMeasCorr(gnssMeasCorr, *this, *mLocApi)); + return true; + } else { + LOC_LOGw("Measurement Corrections are not supported!"); + return false; + } +} +uint32_t GnssAdapter::antennaInfoInitCommand(const antennaInfoCb antennaInfoCallback) { + LOC_LOGi("GnssAdapter::antennaInfoInitCommand"); + + /* Message to initialize Antenna Information */ + struct MsgInitAi : public LocMsg { + const antennaInfoCb mAntennaInfoCb; + GnssAdapter& mAdapter; + + inline MsgInitAi(const antennaInfoCb antennaInfoCallback, GnssAdapter& adapter) : + LocMsg(), mAntennaInfoCb(antennaInfoCallback), mAdapter(adapter) { + LOC_LOGv("MsgInitAi"); + } + + inline virtual void proc() const { + LOC_LOGv("MsgInitAi::proc()"); + mAdapter.reportGnssAntennaInformation(mAntennaInfoCb); + } + }; + if (mIsAntennaInfoInterfaceOpened) { + return ANTENNA_INFO_ERROR_ALREADY_INIT; + } else { + mIsAntennaInfoInterfaceOpened = true; + sendMsg(new MsgInitAi(antennaInfoCallback, *this)); + return ANTENNA_INFO_SUCCESS; + } +} + +void +GnssAdapter::configRobustLocation(uint32_t sessionId, + bool enable, bool enableForE911) { + + mLocConfigInfo.robustLocationConfigInfo.isValid = true; + mLocConfigInfo.robustLocationConfigInfo.enable = enable; + mLocConfigInfo.robustLocationConfigInfo.enableFor911 = enableForE911; + + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->configRobustLocation(enable, enableForE911, locApiResponse); +} + +uint32_t GnssAdapter::configRobustLocationCommand( + bool enable, bool enableForE911) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgConfigRobustLocation : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + bool mEnable; + bool mEnableForE911; + + inline MsgConfigRobustLocation(GnssAdapter& adapter, + uint32_t sessionId, + bool enable, + bool enableForE911) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEnable(enable), + mEnableForE911(enableForE911) {} + inline virtual void proc() const { + mAdapter.configRobustLocation(mSessionId, mEnable, mEnableForE911); + } + }; + + sendMsg(new MsgConfigRobustLocation(*this, sessionId, enable, enableForE911)); + return sessionId; +} + +void +GnssAdapter::configMinGpsWeek(uint32_t sessionId, uint16_t minGpsWeek) { + // suspend all sessions for modem to take the min GPS week config + suspendSessions(); + + LocApiResponse* locApiResponse = nullptr; + if (sessionId != 0) { + locApiResponse = + new LocApiResponse(*getContext(), + [this, sessionId] (LocationError err) { + reportResponse(err, sessionId);}); + if (!locApiResponse) { + LOC_LOGe("memory alloc failed"); + } + } + mLocApi->configMinGpsWeek(minGpsWeek, locApiResponse); + + // resume all tracking sessions after the min GPS week config + // has been changed + restartSessions(false); +} + +uint32_t GnssAdapter::configMinGpsWeekCommand(uint16_t minGpsWeek) { + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgConfigMinGpsWeek : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + uint16_t mMinGpsWeek; + + inline MsgConfigMinGpsWeek(GnssAdapter& adapter, + uint32_t sessionId, + uint16_t minGpsWeek) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mMinGpsWeek(minGpsWeek) {} + inline virtual void proc() const { + mAdapter.configMinGpsWeek(mSessionId, mMinGpsWeek); + } + }; + + sendMsg(new MsgConfigMinGpsWeek(*this, sessionId, minGpsWeek)); + return sessionId; +} + +uint32_t GnssAdapter::configDeadReckoningEngineParamsCommand( + const DeadReckoningEngineConfig& dreConfig) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGd("session id %u", sessionId); + + struct MsgConfigDrEngine : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + DeadReckoningEngineConfig mDreConfig; + + inline MsgConfigDrEngine(GnssAdapter& adapter, + uint32_t sessionId, + const DeadReckoningEngineConfig& dreConfig) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mDreConfig(dreConfig) {} + inline virtual void proc() const { + LocationError err = LOCATION_ERROR_NOT_SUPPORTED; + if (true == mAdapter.mEngHubProxy->configDeadReckoningEngineParams(mDreConfig)) { + err = LOCATION_ERROR_SUCCESS; + } + mAdapter.reportResponse(err, mSessionId); + } + }; + + sendMsg(new MsgConfigDrEngine(*this, sessionId, dreConfig)); + return sessionId; +} + +uint32_t GnssAdapter::configEngineRunStateCommand( + PositioningEngineMask engType, LocEngineRunState engState) { + + // generated session id will be none-zero + uint32_t sessionId = generateSessionId(); + LOC_LOGe("session id %u, eng type 0x%x, eng state %d, dre enabled %d", + sessionId, engType, engState, mDreIntEnabled); + + struct MsgConfigEngineRunState : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + PositioningEngineMask mEngType; + LocEngineRunState mEngState; + + inline MsgConfigEngineRunState(GnssAdapter& adapter, + uint32_t sessionId, + PositioningEngineMask engType, + LocEngineRunState engState) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mEngType(engType), + mEngState(engState) {} + inline virtual void proc() const { + LocationError err = LOCATION_ERROR_NOT_SUPPORTED; + // Currently, only DR engine supports pause/resume request + if ((mEngType == DEAD_RECKONING_ENGINE) && + (mAdapter.mDreIntEnabled == true)) { + if (true == mAdapter.mEngHubProxy->configEngineRunState(mEngType, mEngState)) { + err = LOCATION_ERROR_SUCCESS; + } + } + mAdapter.reportResponse(err, mSessionId); + } + }; + + sendMsg(new MsgConfigEngineRunState(*this, sessionId, engType, engState)); + + return sessionId; +} + +void GnssAdapter::reportGnssConfigEvent(uint32_t sessionId, const GnssConfig& gnssConfig) +{ + struct MsgReportGnssConfig : public LocMsg { + GnssAdapter& mAdapter; + uint32_t mSessionId; + mutable GnssConfig mGnssConfig; + inline MsgReportGnssConfig(GnssAdapter& adapter, + uint32_t sessionId, + const GnssConfig& gnssConfig) : + LocMsg(), + mAdapter(adapter), + mSessionId(sessionId), + mGnssConfig(gnssConfig) {} + inline virtual void proc() const { + // Invoke control clients config callback + if (nullptr != mAdapter.mControlCallbacks.gnssConfigCb) { + mAdapter.mControlCallbacks.gnssConfigCb(mSessionId, mGnssConfig); + } else { + LOC_LOGe("Failed to report, callback not registered"); + } + } + }; + + sendMsg(new MsgReportGnssConfig(*this, sessionId, gnssConfig)); +} + +/* ==== Eng Hub Proxy ================================================================= */ +/* ======== UTILITIES ================================================================= */ +void +GnssAdapter::initEngHubProxyCommand() { + LOC_LOGD("%s]: ", __func__); + + struct MsgInitEngHubProxy : public LocMsg { + GnssAdapter* mAdapter; + inline MsgInitEngHubProxy(GnssAdapter* adapter) : + LocMsg(), + mAdapter(adapter) {} + inline virtual void proc() const { + mAdapter->initEngHubProxy(); + } + }; + + sendMsg(new MsgInitEngHubProxy(this)); +} + +bool +GnssAdapter::initEngHubProxy() { + static bool firstTime = true; + static bool engHubLoadSuccessful = false; + + const char *error = nullptr; + unsigned int processListLength = 0; + loc_process_info_s_type* processInfoList = nullptr; + + do { + // load eng hub only once + if (firstTime == false) { + break; + } + + int rc = loc_read_process_conf(LOC_PATH_IZAT_CONF, &processListLength, + &processInfoList); + if (rc != 0) { + LOC_LOGE("%s]: failed to parse conf file", __func__); + break; + } + + bool pluginDaemonEnabled = false; + // go over the conf table to see whether any plugin daemon is enabled + for (unsigned int i = 0; i < processListLength; i++) { + if ((strncmp(processInfoList[i].name[0], PROCESS_NAME_ENGINE_SERVICE, + strlen(PROCESS_NAME_ENGINE_SERVICE)) == 0) && + (processInfoList[i].proc_status == ENABLED)) { + pluginDaemonEnabled = true; + // check if this is DRE-INT engine + if ((processInfoList[i].args[1]!= nullptr) && + (strncmp(processInfoList[i].args[1], "DRE-INT", sizeof("DRE-INT")) == 0)) { + mDreIntEnabled = true; + break; + } + } + } + + // no plugin daemon is enabled for this platform, + // check if external engine is present for which we need + // libloc_eng_hub.so to be loaded + if (pluginDaemonEnabled == false) { + UTIL_READ_CONF(LOC_PATH_IZAT_CONF, izatConfParamTable); + if (!loadEngHubForExternalEngine) { + break; + } + } + + // load the engine hub .so, if the .so is not present + // all EngHubProxyBase calls will turn into no-op. + void *handle = nullptr; + if ((handle = dlopen("libloc_eng_hub.so", RTLD_NOW)) == nullptr) { + if ((error = dlerror()) != nullptr) { + LOC_LOGE("%s]: libloc_eng_hub.so not found %s !", __func__, error); + } + break; + } + + // prepare the callback functions + // callback function for engine hub to report back position event + GnssAdapterReportEnginePositionsEventCb reportPositionEventCb = + [this](int count, EngineLocationInfo* locationArr) { + // report from engine hub on behalf of PPE will be treated as fromUlp + reportEnginePositionsEvent(count, locationArr); + }; + + // callback function for engine hub to report back sv event + GnssAdapterReportSvEventCb reportSvEventCb = + [this](const GnssSvNotification& svNotify, bool fromEngineHub) { + reportSvEvent(svNotify, fromEngineHub); + }; + + // callback function for engine hub to request for complete aiding data + GnssAdapterReqAidingDataCb reqAidingDataCb = + [this] (const GnssAidingDataSvMask& svDataMask) { + mLocApi->requestForAidingData(svDataMask); + }; + + GnssAdapterUpdateNHzRequirementCb updateNHzRequirementCb = + [this] (bool nHzNeeded, bool nHzMeasNeeded) { + + if (nHzMeasNeeded && + (!checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT))) { + updateEvtMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT, + LOC_REGISTRATION_MASK_ENABLED); + } else if (checkMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT)) { + updateEvtMask(LOC_API_ADAPTER_BIT_GNSS_NHZ_MEASUREMENT, + LOC_REGISTRATION_MASK_DISABLED); + } + + if (mNHzNeeded != nHzNeeded) { + mNHzNeeded = nHzNeeded; + checkAndRestartSPESession(); + } + }; + + GnssAdapterUpdateQwesFeatureStatusCb updateQwesFeatureStatusCb = + [this] (const std::unordered_map &featureMap) { + reportQwesCapabilities(featureMap); + }; + + getEngHubProxyFn* getter = (getEngHubProxyFn*) dlsym(handle, "getEngHubProxy"); + if(getter != nullptr) { + EngineHubProxyBase* hubProxy = (*getter) (mMsgTask, mSystemStatus->getOsObserver(), + reportPositionEventCb, + reportSvEventCb, reqAidingDataCb, + updateNHzRequirementCb, + updateQwesFeatureStatusCb); + if (hubProxy != nullptr) { + mEngHubProxy = hubProxy; + engHubLoadSuccessful = true; + } + } + else { + LOC_LOGD("%s]: entered, did not find function", __func__); + } + + LOC_LOGD("%s]: first time initialization %d, returned %d", + __func__, firstTime, engHubLoadSuccessful); + + } while (0); + + if (processInfoList != nullptr) { + free (processInfoList); + processInfoList = nullptr; + } + + firstTime = false; + return engHubLoadSuccessful; +} + +std::vector +GnssAdapter::parseDoublesString(char* dString) { + std::vector dVector; + char* tmp = NULL; + char* substr; + + dVector.clear(); + for (substr = strtok_r(dString, " ", &tmp); + substr != NULL; + substr = strtok_r(NULL, " ", &tmp)) { + dVector.push_back(std::stod(substr)); + } + return dVector; +} + +void +GnssAdapter::reportGnssAntennaInformation(const antennaInfoCb antennaInfoCallback) +{ +#define MAX_TEXT_WIDTH 50 +#define MAX_COLUMN_WIDTH 20 + + /* parse antenna_corrections file and fill in + a vector of GnssAntennaInformation data structure */ + + std::vector gnssAntennaInformations; + GnssAntennaInformation gnssAntennaInfo; + + uint32_t antennaInfoVectorSize; + loc_param_s_type ant_info_vector_table[] = + { + { "ANTENNA_INFO_VECTOR_SIZE", &antennaInfoVectorSize, NULL, 'n' } + }; + UTIL_READ_CONF(LOC_PATH_ANT_CORR, ant_info_vector_table); + + for (uint32_t i = 0; i < antennaInfoVectorSize; i++) { + double carrierFrequencyMHz; + char pcOffsetStr[LOC_MAX_PARAM_STRING]; + uint32_t numberOfRows = 0; + uint32_t numberOfColumns = 0; + uint32_t numberOfRowsSGC = 0; + uint32_t numberOfColumnsSGC = 0; + + gnssAntennaInfo.phaseCenterVariationCorrectionMillimeters.clear(); + gnssAntennaInfo.phaseCenterVariationCorrectionUncertaintyMillimeters.clear(); + gnssAntennaInfo.signalGainCorrectionDbi.clear(); + gnssAntennaInfo.signalGainCorrectionUncertaintyDbi.clear(); + string s1 = "CARRIER_FREQUENCY_"; + s1 += to_string(i); + string s2 = "PC_OFFSET_"; + s2 += to_string(i); + string s3 = "NUMBER_OF_ROWS_"; + s3 += to_string(i); + string s4 = "NUMBER_OF_COLUMNS_"; + s4 += to_string(i); + string s5 = "NUMBER_OF_ROWS_SGC_"; + s5 += to_string(i); + string s6 = "NUMBER_OF_COLUMNS_SGC_"; + s6 += to_string(i); + + gnssAntennaInfo.size = sizeof(gnssAntennaInfo); + loc_param_s_type ant_cf_table[] = + { + { s1.c_str(), &carrierFrequencyMHz, NULL, 'f' }, + { s2.c_str(), &pcOffsetStr, NULL, 's' }, + { s3.c_str(), &numberOfRows, NULL, 'n' }, + { s4.c_str(), &numberOfColumns, NULL, 'n' }, + { s5.c_str(), &numberOfRowsSGC, NULL, 'n' }, + { s6.c_str(), &numberOfColumnsSGC, NULL, 'n' }, + }; + UTIL_READ_CONF(LOC_PATH_ANT_CORR, ant_cf_table); + + if (0 == numberOfRowsSGC) { + numberOfRowsSGC = numberOfRows; + } + if (0 == numberOfColumnsSGC) { + numberOfColumnsSGC = numberOfColumns; + } + + gnssAntennaInfo.carrierFrequencyMHz = carrierFrequencyMHz; + + // now parse pcOffsetStr to get each entry + std::vector pcOffset; + pcOffset = parseDoublesString(pcOffsetStr); + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.size = + sizeof(gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters); + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.x = pcOffset[0]; + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.xUncertainty = pcOffset[1]; + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.y = pcOffset[2]; + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.yUncertainty = pcOffset[3]; + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.z = pcOffset[4]; + gnssAntennaInfo.phaseCenterOffsetCoordinateMillimeters.zUncertainty = pcOffset[5]; + + uint16_t array_size = MAX_TEXT_WIDTH + MAX_COLUMN_WIDTH*numberOfColumns; + uint16_t array_size_SGC = MAX_TEXT_WIDTH + MAX_COLUMN_WIDTH*numberOfColumnsSGC; + for (uint32_t j = 0; j < numberOfRows; j++) { + char pcVarCorrStr[array_size]; + char pcVarCorrUncStr[array_size]; + + string s1 = "PC_VARIATION_CORRECTION_" + to_string(i) + "_ROW_"; + s1 += to_string(j); + string s2 = "PC_VARIATION_CORRECTION_UNC_" + to_string(i) + "_ROW_"; + s2 += to_string(j); + + loc_param_s_type ant_row_table[] = + { + { s1.c_str(), &pcVarCorrStr, NULL, 's' }, + { s2.c_str(), &pcVarCorrUncStr, NULL, 's' }, + }; + UTIL_READ_CONF_LONG(LOC_PATH_ANT_CORR, ant_row_table, array_size); + + gnssAntennaInfo.phaseCenterVariationCorrectionMillimeters.push_back( + parseDoublesString(pcVarCorrStr)); + gnssAntennaInfo.phaseCenterVariationCorrectionUncertaintyMillimeters.push_back( + parseDoublesString(pcVarCorrUncStr)); + } + for (uint32_t j = 0; j < numberOfRowsSGC; j++) { + char sigGainCorrStr[array_size_SGC]; + char sigGainCorrUncStr[array_size_SGC]; + + string s3 = "SIGNAL_GAIN_CORRECTION_" + to_string(i) + "_ROW_"; + s3 += to_string(j); + string s4 = "SIGNAL_GAIN_CORRECTION_UNC_" + to_string(i) + "_ROW_"; + s4 += to_string(j); + + loc_param_s_type ant_row_table[] = + { + { s3.c_str(), &sigGainCorrStr, NULL, 's' }, + { s4.c_str(), &sigGainCorrUncStr, NULL, 's' }, + }; + UTIL_READ_CONF_LONG(LOC_PATH_ANT_CORR, ant_row_table, array_size_SGC); + + gnssAntennaInfo.signalGainCorrectionDbi.push_back( + parseDoublesString(sigGainCorrStr)); + gnssAntennaInfo.signalGainCorrectionUncertaintyDbi.push_back( + parseDoublesString(sigGainCorrUncStr)); + } + gnssAntennaInformations.push_back(std::move(gnssAntennaInfo)); + } + antennaInfoCallback(gnssAntennaInformations); +} + +/* ==== DGnss Usable Reporter ========================================================= */ +/* ======== UTILITIES ================================================================= */ + +void GnssAdapter::initCDFWService() +{ + LOC_LOGv("mCdfwInterface %p", mCdfwInterface); + if (nullptr == mCdfwInterface) { + void* libHandle = nullptr; + const char* libName = "libcdfw.so"; + + libHandle = nullptr; + getCdfwInterface getter = (getCdfwInterface)dlGetSymFromLib(libHandle, + libName, "getQCdfwInterface"); + if (nullptr == getter) { + LOC_LOGe("dlGetSymFromLib getQCdfwInterface failed"); + } else { + mCdfwInterface = getter(); + } + + if (nullptr != mCdfwInterface) { + QDgnssSessionActiveCb qDgnssSessionActiveCb = [this] (bool sessionActive) { + mDGnssNeedReport = sessionActive; + }; + mCdfwInterface->startDgnssApiService(*mMsgTask); + mQDgnssListenerHDL = mCdfwInterface->createUsableReporter(qDgnssSessionActiveCb); + } + } +} + +/*==== DGnss Ntrip Source ==========================================================*/ +void GnssAdapter::enablePPENtripStreamCommand(const GnssNtripConnectionParams& params, + bool enableRTKEngine) { + + (void)enableRTKEngine; //future parameter, not used + + struct enableNtripMsg : public LocMsg { + GnssAdapter& mAdapter; + const GnssNtripConnectionParams& mParams; + + inline enableNtripMsg(GnssAdapter& adapter, + const GnssNtripConnectionParams& params) : + LocMsg(), + mAdapter(adapter), + mParams(std::move(params)) {} + inline virtual void proc() const { + mAdapter.handleEnablePPENtrip(mParams); + } + }; + sendMsg(new enableNtripMsg(*this, params)); +} + +void GnssAdapter::handleEnablePPENtrip(const GnssNtripConnectionParams& params) { + LOC_LOGd("%d %s %d %s %s %s %d mSendNmeaConsent %d", + params.useSSL, params.hostNameOrIp.data(), params.port, + params.mountPoint.data(), params.username.data(), params.password.data(), + params.requiresNmeaLocation, mSendNmeaConsent); + + GnssNtripConnectionParams* pNtripParams = &(mStartDgnssNtripParams.ntripParams); + + if (pNtripParams->useSSL == params.useSSL && + 0 == pNtripParams->hostNameOrIp.compare(params.hostNameOrIp) && + pNtripParams->port == params.port && + 0 == pNtripParams->mountPoint.compare(params.mountPoint) && + 0 == pNtripParams->username.compare(params.username) && + 0 == pNtripParams->password.compare(params.password) && + pNtripParams->requiresNmeaLocation == params.requiresNmeaLocation && + mDgnssState & DGNSS_STATE_ENABLE_NTRIP_COMMAND) { + LOC_LOGd("received same Ntrip param"); + return; + } + + mDgnssState |= DGNSS_STATE_ENABLE_NTRIP_COMMAND; + mDgnssState |= DGNSS_STATE_NO_NMEA_PENDING; + mDgnssState &= ~DGNSS_STATE_NTRIP_SESSION_STARTED; + + mStartDgnssNtripParams.ntripParams = std::move(params); + mStartDgnssNtripParams.nmea.clear(); + if (mSendNmeaConsent && pNtripParams->requiresNmeaLocation) { + mDgnssState &= ~DGNSS_STATE_NO_NMEA_PENDING; + mDgnssLastNmeaBootTimeMilli = 0; + return; + } + + checkUpdateDgnssNtrip(false); +} + +void GnssAdapter::disablePPENtripStreamCommand() { + struct disableNtripMsg : public LocMsg { + GnssAdapter& mAdapter; + + inline disableNtripMsg(GnssAdapter& adapter) : + LocMsg(), + mAdapter(adapter) {} + inline virtual void proc() const { + mAdapter.handleDisablePPENtrip(); + } + }; + sendMsg(new disableNtripMsg(*this)); +} + +void GnssAdapter::handleDisablePPENtrip() { + mDgnssState &= ~DGNSS_STATE_ENABLE_NTRIP_COMMAND; + mDgnssState |= DGNSS_STATE_NO_NMEA_PENDING; + stopDgnssNtrip(); +} + +void GnssAdapter::checkUpdateDgnssNtrip(bool isLocationValid) { + LOC_LOGd("isInSession %d mDgnssState 0x%x isLocationValid %d", + isInSession(), mDgnssState, isLocationValid); + if (isInSession()) { + uint64_t curBootTime = getBootTimeMilliSec(); + if (mDgnssState == (DGNSS_STATE_ENABLE_NTRIP_COMMAND | DGNSS_STATE_NO_NMEA_PENDING)) { + mDgnssState |= DGNSS_STATE_NTRIP_SESSION_STARTED; + mXtraObserver.startDgnssSource(mStartDgnssNtripParams); + if (isDgnssNmeaRequired()) { + mDgnssLastNmeaBootTimeMilli = curBootTime; + } + } else if ((mDgnssState & DGNSS_STATE_NTRIP_SESSION_STARTED) && isLocationValid && + isDgnssNmeaRequired() && + curBootTime - mDgnssLastNmeaBootTimeMilli > DGNSS_RANGE_UPDATE_TIME_10MIN_IN_MILLI ) { + mXtraObserver.updateNmeaToDgnssServer(mStartDgnssNtripParams.nmea); + mDgnssLastNmeaBootTimeMilli = curBootTime; + } + } +} + +void GnssAdapter::stopDgnssNtrip() { + LOC_LOGd("isInSession %d mDgnssState 0x%x", isInSession(), mDgnssState); + mStartDgnssNtripParams.nmea.clear(); + if (mDgnssState & DGNSS_STATE_NTRIP_SESSION_STARTED) { + mDgnssState &= ~DGNSS_STATE_NTRIP_SESSION_STARTED; + mXtraObserver.stopDgnssSource(); + } +} + +void GnssAdapter::reportGGAToNtrip(const char* nmea) { + +#define POS_OF_GGA (3) //start position of "GGA" +#define COMMAS_BEFORE_VALID (6) //"$GPGGA,,,,,,0,,,,,,,,*hh" + + if (!isDgnssNmeaRequired()) { + return; + } + + if (nullptr == nmea || 0 == strlen(nmea)) { + return; + } + + string nmeaString(nmea); + size_t foundPos = nmeaString.find("GGA"); + size_t foundNth = 0; + string GGAString; + + if (foundPos != string::npos && foundPos >= POS_OF_GGA) { + size_t foundNextSentence = nmeaString.find("$", foundPos); + if (foundNextSentence != string::npos) { + /* remove other sentences after GGA */ + GGAString = nmeaString.substr(foundPos - POS_OF_GGA, foundNextSentence); + } else { + /* GGA is the last sentence */ + GGAString = nmeaString.substr(foundPos - POS_OF_GGA); + } + LOC_LOGd("GGAString %s", GGAString.c_str()); + + foundPos = GGAString.find(","); + while (foundPos != string::npos && foundNth < COMMAS_BEFORE_VALID) { + foundPos++; + foundNth++; + foundPos = GGAString.find(",", foundPos); + } + + if (COMMAS_BEFORE_VALID == foundNth && GGAString.at(foundPos-1) != '0') { + mDgnssState |= DGNSS_STATE_NO_NMEA_PENDING; + mStartDgnssNtripParams.nmea = std::move(GGAString); + checkUpdateDgnssNtrip(true); + } + } + + return; +} diff --git a/gps/gnss/GnssAdapter.h b/gps/gnss/GnssAdapter.h new file mode 100644 index 0000000..6b8d024 --- /dev/null +++ b/gps/gnss/GnssAdapter.h @@ -0,0 +1,648 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef GNSS_ADAPTER_H +#define GNSS_ADAPTER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_URL_LEN 256 +#define NMEA_SENTENCE_MAX_LENGTH 200 +#define GLONASS_SV_ID_OFFSET 64 +#define MAX_SATELLITES_IN_USE 12 +#define LOC_NI_NO_RESPONSE_TIME 20 +#define LOC_GPS_NI_RESPONSE_IGNORE 4 +#define ODCPI_EXPECTED_INJECTION_TIME_MS 10000 +#define DELETE_AIDING_DATA_EXPECTED_TIME_MS 5000 + +class GnssAdapter; + +typedef std::map LocationSessionMap; +typedef std::map TrackingOptionsMap; + +class OdcpiTimer : public LocTimer { +public: + OdcpiTimer(GnssAdapter* adapter) : + LocTimer(), mAdapter(adapter), mActive(false) {} + + inline void start() { + mActive = true; + LocTimer::start(ODCPI_EXPECTED_INJECTION_TIME_MS, false); + } + inline void stop() { + mActive = false; + LocTimer::stop(); + } + inline void restart() { + stop(); + start(); + } + inline bool isActive() { + return mActive; + } + +private: + // Override + virtual void timeOutCallback() override; + + GnssAdapter* mAdapter; + bool mActive; +}; + +typedef struct { + pthread_t thread; /* NI thread */ + uint32_t respTimeLeft; /* examine time for NI response */ + bool respRecvd; /* NI User reponse received or not from Java layer*/ + void* rawRequest; + uint32_t reqID; /* ID to check against response */ + GnssNiResponse resp; + pthread_cond_t tCond; + pthread_mutex_t tLock; + GnssAdapter* adapter; +} NiSession; +typedef struct { + NiSession session; /* SUPL NI Session */ + NiSession sessionEs; /* Emergency SUPL NI Session */ + uint32_t reqIDCounter; +} NiData; + +typedef enum { + NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA + NMEA_PROVIDER_MP // Modem Processor Provider of NMEA +} NmeaProviderType; +typedef struct { + GnssSvType svType; + const char* talker; + uint64_t mask; + uint32_t svIdOffset; +} NmeaSvMeta; + +typedef struct { + double latitude; + double longitude; + float accuracy; + // the CPI will be blocked until the boot time + // specified in blockedTillTsMs + int64_t blockedTillTsMs; + // CPIs whose both latitude and longitude differ + // no more than latLonThreshold will be blocked + // in units of degree + double latLonDiffThreshold; +} BlockCPIInfo; + +typedef struct { + bool isValid; + bool enable; + float tuncThresholdMs; // need to be specified if enable is true + uint32_t energyBudget; // need to be specified if enable is true +} TuncConfigInfo; + +typedef struct { + bool isValid; + bool enable; +} PaceConfigInfo; + +typedef struct { + bool isValid; + bool enable; + bool enableFor911; +} RobustLocationConfigInfo; + +typedef struct { + TuncConfigInfo tuncConfigInfo; + PaceConfigInfo paceConfigInfo; + RobustLocationConfigInfo robustLocationConfigInfo; + LeverArmConfigInfo leverArmConfigInfo; +} LocIntegrationConfigInfo; + +using namespace loc_core; + +namespace loc_core { + class SystemStatus; +} + +typedef std::function GnssEnergyConsumedCallback; + +typedef void* QDgnssListenerHDL; +typedef std::function QDgnssSessionActiveCb; + +struct CdfwInterface { + void (*startDgnssApiService)(const MsgTask& msgTask); + QDgnssListenerHDL (*createUsableReporter)( + QDgnssSessionActiveCb sessionActiveCb); + void (*destroyUsableReporter)(QDgnssListenerHDL handle); + void (*reportUsable)(QDgnssListenerHDL handle, bool usable); +}; + +typedef uint16_t DGnssStateBitMask; +#define DGNSS_STATE_ENABLE_NTRIP_COMMAND 0X01 +#define DGNSS_STATE_NO_NMEA_PENDING 0X02 +#define DGNSS_STATE_NTRIP_SESSION_STARTED 0X04 + +class GnssReportLoggerUtil { +public: + typedef void (*LogGnssLatency)(const GnssLatencyInfo& gnssLatencyMeasInfo); + + GnssReportLoggerUtil() : mLogLatency(nullptr) { + const char* libname = "liblocdiagiface.so"; + void* libHandle = nullptr; + mLogLatency = (LogGnssLatency)dlGetSymFromLib(libHandle, libname, "LogGnssLatency"); + } + + bool isLogEnabled(); + void log(const GnssLatencyInfo& gnssLatencyMeasInfo); + +private: + LogGnssLatency mLogLatency; +}; + +class GnssAdapter : public LocAdapterBase { + + /* ==== Engine Hub ===================================================================== */ + EngineHubProxyBase* mEngHubProxy; + bool mNHzNeeded; + bool mSPEAlreadyRunningAtHighestInterval; + + /* ==== TRACKING ======================================================================= */ + TrackingOptionsMap mTimeBasedTrackingSessions; + LocationSessionMap mDistanceBasedTrackingSessions; + LocPosMode mLocPositionMode; + GnssSvUsedInPosition mGnssSvIdUsedInPosition; + bool mGnssSvIdUsedInPosAvail; + GnssSvMbUsedInPosition mGnssMbSvIdUsedInPosition; + bool mGnssMbSvIdUsedInPosAvail; + + /* ==== CONTROL ======================================================================== */ + LocationControlCallbacks mControlCallbacks; + uint32_t mAfwControlId; + uint32_t mNmeaMask; + uint64_t mPrevNmeaRptTimeNsec; + GnssSvIdConfig mGnssSvIdConfig; + GnssSvTypeConfig mGnssSeconaryBandConfig; + GnssSvTypeConfig mGnssSvTypeConfig; + GnssSvTypeConfigCallback mGnssSvTypeConfigCb; + bool mSupportNfwControl; + LocIntegrationConfigInfo mLocConfigInfo; + + /* ==== NI ============================================================================= */ + NiData mNiData; + + /* ==== AGPS =========================================================================== */ + // This must be initialized via initAgps() + AgpsManager mAgpsManager; + void initAgps(const AgpsCbInfo& cbInfo); + + /* ==== NFW =========================================================================== */ + NfwStatusCb mNfwCb; + IsInEmergencySession mIsE911Session; + inline void initNfw(const NfwCbInfo& cbInfo) { + mNfwCb = (NfwStatusCb)cbInfo.visibilityControlCb; + mIsE911Session = (IsInEmergencySession)cbInfo.isInEmergencySession; + } + + /* ==== Measurement Corrections========================================================= */ + bool mIsMeasCorrInterfaceOpen; + measCorrSetCapabilitiesCb mMeasCorrSetCapabilitiesCb; + bool initMeasCorr(bool bSendCbWhenNotSupported); + bool mIsAntennaInfoInterfaceOpened; + + /* ==== DGNSS Data Usable Report======================================================== */ + QDgnssListenerHDL mQDgnssListenerHDL; + const CdfwInterface* mCdfwInterface; + bool mDGnssNeedReport; + bool mDGnssDataUsage; + void reportDGnssDataUsable(const GnssSvMeasurementSet &svMeasurementSet); + + /* ==== ODCPI ========================================================================== */ + OdcpiRequestCallback mOdcpiRequestCb; + bool mOdcpiRequestActive; + OdcpiPrioritytype mCallbackPriority; + OdcpiTimer mOdcpiTimer; + OdcpiRequestInfo mOdcpiRequest; + void odcpiTimerExpire(); + + /* ==== DELETEAIDINGDATA =============================================================== */ + int64_t mLastDeleteAidingDataTime; + + /* === SystemStatus ===================================================================== */ + SystemStatus* mSystemStatus; + std::string mServerUrl; + std::string mMoServerUrl; + XtraSystemStatusObserver mXtraObserver; + LocationSystemInfo mLocSystemInfo; + std::vector mBlacklistedSvIds; + PowerStateType mSystemPowerState; + + /* === Misc ===================================================================== */ + BlockCPIInfo mBlockCPIInfo; + bool mPowerOn; + uint32_t mAllowFlpNetworkFixes; + std::queue mGnssLatencyInfoQueue; + GnssReportLoggerUtil mLogger; + bool mDreIntEnabled; + + /* === NativeAgpsHandler ======================================================== */ + NativeAgpsHandler mNativeAgpsHandler; + + /* === Misc callback from QMI LOC API ============================================== */ + GnssEnergyConsumedCallback mGnssEnergyConsumedCb; + std::function mPowerStateCb; + + /*==== CONVERSION ===================================================================*/ + static void convertOptions(LocPosMode& out, const TrackingOptions& trackingOptions); + static void convertLocation(Location& out, const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended); + static void convertLocationInfo(GnssLocationInfoNotification& out, + const GpsLocationExtended& locationExtended, + loc_sess_status status); + static uint16_t getNumSvUsed(uint64_t svUsedIdsMask, + int totalSvCntInThisConstellation); + + /* ======== UTILITIES ================================================================== */ + inline void initOdcpi(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); + inline void injectOdcpi(const Location& location); + static bool isFlpClient(LocationCallbacks& locationCallbacks); + + /*==== DGnss Ntrip Source ==========================================================*/ + StartDgnssNtripParams mStartDgnssNtripParams; + bool mSendNmeaConsent; + DGnssStateBitMask mDgnssState; + void checkUpdateDgnssNtrip(bool isLocationValid); + void stopDgnssNtrip(); + uint64_t mDgnssLastNmeaBootTimeMilli; + +protected: + + /* ==== CLIENT ========================================================================= */ + virtual void updateClientsEventMask(); + virtual void stopClientSessions(LocationAPI* client); + inline void setNmeaReportRateConfig(); + void logLatencyInfo(); + +public: + + GnssAdapter(); + virtual inline ~GnssAdapter() { } + + /* ==== SSR ============================================================================ */ + /* ======== EVENTS ====(Called from QMI Thread)========================================= */ + virtual void handleEngineUpEvent(); + /* ======== UTILITIES ================================================================== */ + void restartSessions(bool modemSSR = false); + void checkAndRestartTimeBasedSession(); + void checkAndRestartSPESession(); + void suspendSessions(); + + /* ==== CLIENT ========================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + virtual void addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks); + + /* ==== TRACKING ======================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + uint32_t startTrackingCommand( + LocationAPI* client, TrackingOptions& trackingOptions); + void updateTrackingOptionsCommand( + LocationAPI* client, uint32_t id, TrackingOptions& trackingOptions); + void stopTrackingCommand(LocationAPI* client, uint32_t id); + /* ======== RESPONSES ================================================================== */ + void reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId); + /* ======== UTILITIES ================================================================== */ + bool isTimeBasedTrackingSession(LocationAPI* client, uint32_t sessionId); + bool isDistanceBasedTrackingSession(LocationAPI* client, uint32_t sessionId); + bool hasCallbacksToStartTracking(LocationAPI* client); + bool isTrackingSession(LocationAPI* client, uint32_t sessionId); + void saveTrackingSession(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& trackingOptions); + void eraseTrackingSession(LocationAPI* client, uint32_t sessionId); + + bool setLocPositionMode(const LocPosMode& mode); + LocPosMode& getLocPositionMode() { return mLocPositionMode; } + + bool startTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& trackingOptions); + void startTimeBasedTracking(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& trackingOptions); + bool stopTimeBasedTrackingMultiplex(LocationAPI* client, uint32_t id); + void stopTracking(LocationAPI* client, uint32_t id); + bool updateTrackingMultiplex(LocationAPI* client, uint32_t id, + const TrackingOptions& trackingOptions); + void updateTracking(LocationAPI* client, uint32_t sessionId, + const TrackingOptions& updatedOptions, const TrackingOptions& oldOptions); + bool checkAndSetSPEToRunforNHz(TrackingOptions & out); + + void setConstrainedTunc(bool enable, float tuncConstraint, + uint32_t energyBudget, uint32_t sessionId); + void setPositionAssistedClockEstimator(bool enable, uint32_t sessionId); + void gnssUpdateSvConfig(uint32_t sessionId, + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig); + + void gnssUpdateSecondaryBandConfig( + uint32_t sessionId, const GnssSvTypeConfig& secondaryBandConfig); + void gnssGetSecondaryBandConfig(uint32_t sessionId); + void resetSvConfig(uint32_t sessionId); + void configLeverArm(uint32_t sessionId, const LeverArmConfigInfo& configInfo); + void configRobustLocation(uint32_t sessionId, bool enable, bool enableForE911); + void configMinGpsWeek(uint32_t sessionId, uint16_t minGpsWeek); + + /* ==== NI ============================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void gnssNiResponseCommand(LocationAPI* client, uint32_t id, GnssNiResponse response); + /* ======================(Called from NI Thread)======================================== */ + void gnssNiResponseCommand(GnssNiResponse response, void* rawRequest); + /* ======== UTILITIES ================================================================== */ + bool hasNiNotifyCallback(LocationAPI* client); + NiData& getNiData() { return mNiData; } + + /* ==== CONTROL CLIENT ================================================================= */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + uint32_t enableCommand(LocationTechnologyType techType); + void disableCommand(uint32_t id); + void setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks); + void readConfigCommand(); + void requestUlpCommand(); + void initEngHubProxyCommand(); + uint32_t* gnssUpdateConfigCommand(const GnssConfig& config); + uint32_t* gnssGetConfigCommand(GnssConfigFlagsMask mask); + uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data); + void deleteAidingData(const GnssAidingData &data, uint32_t sessionId); + void gnssUpdateXtraThrottleCommand(const bool enabled); + std::vector gnssUpdateConfig(const std::string& oldMoServerUrl, + GnssConfig& gnssConfigRequested, + GnssConfig& gnssConfigNeedEngineUpdate, size_t count = 0); + + /* ==== GNSS SV TYPE CONFIG ============================================================ */ + /* ==== COMMANDS ====(Called from Client Thread)======================================== */ + /* ==== These commands are received directly from client bypassing Location API ======== */ + void gnssUpdateSvTypeConfigCommand(GnssSvTypeConfig config); + void gnssGetSvTypeConfigCommand(GnssSvTypeConfigCallback callback); + void gnssResetSvTypeConfigCommand(); + + /* ==== UTILITIES ====================================================================== */ + LocationError gnssSvIdConfigUpdateSync(const std::vector& blacklistedSvIds); + LocationError gnssSvIdConfigUpdateSync(); + void gnssSvIdConfigUpdate(const std::vector& blacklistedSvIds); + void gnssSvIdConfigUpdate(); + void gnssSvTypeConfigUpdate(const GnssSvTypeConfig& config); + void gnssSvTypeConfigUpdate(bool sendReset = false); + inline void gnssSetSvTypeConfig(const GnssSvTypeConfig& config) + { mGnssSvTypeConfig = config; } + inline void gnssSetSvTypeConfigCallback(GnssSvTypeConfigCallback callback) + { mGnssSvTypeConfigCb = callback; } + inline GnssSvTypeConfigCallback gnssGetSvTypeConfigCallback() + { return mGnssSvTypeConfigCb; } + void setConfig(); + void gnssSecondaryBandConfigUpdate(LocApiResponse* locApiResponse= nullptr); + + /* ========= AGPS ====================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void initDefaultAgpsCommand(); + void initAgpsCommand(const AgpsCbInfo& cbInfo); + void initNfwCommand(const NfwCbInfo& cbInfo); + void dataConnOpenCommand(AGpsExtType agpsType, + const char* apnName, int apnLen, AGpsBearerType bearerType); + void dataConnClosedCommand(AGpsExtType agpsType); + void dataConnFailedCommand(AGpsExtType agpsType); + void getGnssEnergyConsumedCommand(GnssEnergyConsumedCallback energyConsumedCb); + void nfwControlCommand(bool enable); + uint32_t setConstrainedTuncCommand (bool enable, float tuncConstraint, + uint32_t energyBudget); + uint32_t setPositionAssistedClockEstimatorCommand (bool enable); + uint32_t gnssUpdateSvConfigCommand(const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig); + uint32_t gnssUpdateSecondaryBandConfigCommand( + const GnssSvTypeConfig& secondaryBandConfig); + uint32_t gnssGetSecondaryBandConfigCommand(); + uint32_t configLeverArmCommand(const LeverArmConfigInfo& configInfo); + uint32_t configRobustLocationCommand(bool enable, bool enableForE911); + bool openMeasCorrCommand(const measCorrSetCapabilitiesCb setCapabilitiesCb); + bool measCorrSetCorrectionsCommand(const GnssMeasurementCorrections gnssMeasCorr); + inline void closeMeasCorrCommand() { mIsMeasCorrInterfaceOpen = false; } + uint32_t antennaInfoInitCommand(const antennaInfoCb antennaInfoCallback); + inline void antennaInfoCloseCommand() { mIsAntennaInfoInterfaceOpened = false; } + uint32_t configMinGpsWeekCommand(uint16_t minGpsWeek); + uint32_t configDeadReckoningEngineParamsCommand(const DeadReckoningEngineConfig& dreConfig); + uint32_t configEngineRunStateCommand(PositioningEngineMask engType, + LocEngineRunState engState); + + /* ========= ODCPI ===================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void initOdcpiCommand(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); + void injectOdcpiCommand(const Location& location); + /* ======== RESPONSES ================================================================== */ + void reportResponse(LocationError err, uint32_t sessionId); + void reportResponse(size_t count, LocationError* errs, uint32_t* ids); + /* ======== UTILITIES ================================================================== */ + LocationControlCallbacks& getControlCallbacks() { return mControlCallbacks; } + void setControlCallbacks(const LocationControlCallbacks& controlCallbacks) + { mControlCallbacks = controlCallbacks; } + void setAfwControlId(uint32_t id) { mAfwControlId = id; } + uint32_t getAfwControlId() { return mAfwControlId; } + virtual bool isInSession() { return !mTimeBasedTrackingSessions.empty(); } + void initDefaultAgps(); + bool initEngHubProxy(); + void initCDFWService(); + void odcpiTimerExpireEvent(); + + /* ==== REPORTS ======================================================================== */ + /* ======== EVENTS ====(Called from QMI/EngineHub Thread)===================================== */ + virtual void reportPositionEvent(const UlpLocation& ulpLocation, + const GpsLocationExtended& locationExtended, + enum loc_sess_status status, + LocPosTechMask techMask, + GnssDataNotification* pDataNotify = nullptr, + int msInWeek = -1); + virtual void reportEnginePositionsEvent(unsigned int count, + EngineLocationInfo* locationArr); + + virtual void reportSvEvent(const GnssSvNotification& svNotify, + bool fromEngineHub=false); + virtual void reportNmeaEvent(const char* nmea, size_t length); + virtual void reportDataEvent(const GnssDataNotification& dataNotify, int msInWeek); + virtual bool requestNiNotifyEvent(const GnssNiNotification& notify, const void* data, + const LocInEmergency emergencyState); + virtual void reportGnssMeasurementsEvent(const GnssMeasurements& gnssMeasurements, + int msInWeek); + virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial); + virtual void reportSvEphemerisEvent(GnssSvEphemerisReport & svEphemeris); + virtual void reportGnssSvIdConfigEvent(const GnssSvIdConfig& config); + virtual void reportGnssSvTypeConfigEvent(const GnssSvTypeConfig& config); + virtual void reportGnssConfigEvent(uint32_t sessionId, const GnssConfig& gnssConfig); + virtual bool reportGnssEngEnergyConsumedEvent(uint64_t energyConsumedSinceFirstBoot); + virtual void reportLocationSystemInfoEvent(const LocationSystemInfo& locationSystemInfo); + + virtual bool requestATL(int connHandle, LocAGpsType agps_type, LocApnTypeMask apn_type_mask); + virtual bool releaseATL(int connHandle); + virtual bool requestOdcpiEvent(OdcpiRequestInfo& request); + virtual bool reportDeleteAidingDataEvent(GnssAidingData& aidingData); + virtual bool reportKlobucharIonoModelEvent(GnssKlobucharIonoModel& ionoModel); + virtual bool reportGnssAdditionalSystemInfoEvent( + GnssAdditionalSystemInfo& additionalSystemInfo); + virtual void reportNfwNotificationEvent(GnssNfwNotification& notification); + virtual void reportLatencyInfoEvent(const GnssLatencyInfo& gnssLatencyInfo); + virtual bool reportQwesCapabilities + ( + const std::unordered_map &featureMap + ); + + /* ======== UTILITIES ================================================================= */ + bool needReportForGnssClient(const UlpLocation& ulpLocation, + enum loc_sess_status status, LocPosTechMask techMask); + bool needReportForFlpClient(enum loc_sess_status status, LocPosTechMask techMask); + bool needToGenerateNmeaReport(const uint32_t &gpsTimeOfWeekMs, + const struct timespec32_t &apTimeStamp); + void reportPosition(const UlpLocation &ulpLocation, + const GpsLocationExtended &locationExtended, + enum loc_sess_status status, + LocPosTechMask techMask); + void reportEnginePositions(unsigned int count, + const EngineLocationInfo* locationArr); + void reportSv(GnssSvNotification& svNotify); + void reportNmea(const char* nmea, size_t length); + void reportData(GnssDataNotification& dataNotify); + bool requestNiNotify(const GnssNiNotification& notify, const void* data, + const bool bInformNiAccept); + void reportGnssMeasurementData(const GnssMeasurementsNotification& measurements); + void reportGnssSvIdConfig(const GnssSvIdConfig& config); + void reportGnssSvTypeConfig(const GnssSvTypeConfig& config); + void reportGnssConfig(uint32_t sessionId, const GnssConfig& gnssConfig); + void requestOdcpi(const OdcpiRequestInfo& request); + void invokeGnssEnergyConsumedCallback(uint64_t energyConsumedSinceFirstBoot); + void saveGnssEnergyConsumedCallback(GnssEnergyConsumedCallback energyConsumedCb); + void reportLocationSystemInfo(const LocationSystemInfo & locationSystemInfo); + inline void reportNfwNotification(const GnssNfwNotification& notification) { + if (NULL != mNfwCb) { + mNfwCb(notification); + } + } + inline bool getE911State(void) { + if (NULL != mIsE911Session) { + return mIsE911Session(); + } + return false; + } + + void updateSystemPowerState(PowerStateType systemPowerState); + void reportSvPolynomial(const GnssSvPolynomial &svPolynomial); + + + std::vector parseDoublesString(char* dString); + void reportGnssAntennaInformation(const antennaInfoCb antennaInfoCallback); + + /*======== GNSSDEBUG ================================================================*/ + bool getDebugReport(GnssDebugReport& report); + /* get AGC information from system status and fill it */ + void getAgcInformation(GnssMeasurementsNotification& measurements, int msInWeek); + /* get Data information from system status and fill it */ + void getDataInformation(GnssDataNotification& data, int msInWeek); + + /*==== SYSTEM STATUS ================================================================*/ + inline SystemStatus* getSystemStatus(void) { return mSystemStatus; } + std::string& getServerUrl(void) { return mServerUrl; } + std::string& getMoServerUrl(void) { return mMoServerUrl; } + + /*==== CONVERSION ===================================================================*/ + static uint32_t convertSuplVersion(const GnssConfigSuplVersion suplVersion); + static uint32_t convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl); + static uint32_t convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices); + static uint32_t convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask); + static uint32_t convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask); + static uint32_t convertAGloProt(const GnssConfigAGlonassPositionProtocolMask); + static uint32_t convertSuplMode(const GnssConfigSuplModeMask suplModeMask); + static void convertSatelliteInfo(std::vector& out, + const GnssSvType& in_constellation, + const SystemStatusReports& in); + static bool convertToGnssSvIdConfig( + const std::vector& blacklistedSvIds, GnssSvIdConfig& config); + static void convertFromGnssSvIdConfig( + const GnssSvIdConfig& svConfig, std::vector& blacklistedSvIds); + static void convertGnssSvIdMaskToList( + uint64_t svIdMask, std::vector& svIds, + GnssSvId initialSvId, GnssSvType svType); + static void computeVRPBasedLla(const UlpLocation& loc, GpsLocationExtended& locExt, + const LeverArmConfigInfo& leverArmConfigInfo); + + void injectLocationCommand(double latitude, double longitude, float accuracy); + void injectLocationExtCommand(const GnssLocationInfoNotification &locationInfo); + + void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty); + void blockCPICommand(double latitude, double longitude, float accuracy, + int blockDurationMsec, double latLonDiffThreshold); + + /* ==== MISCELLANEOUS ================================================================== */ + /* ======== COMMANDS ====(Called from Client Thread)==================================== */ + void getPowerStateChangesCommand(std::function powerStateCb); + /* ======== UTILITIES ================================================================== */ + void reportPowerStateIfChanged(); + void savePowerStateCallback(std::function powerStateCb){ + mPowerStateCb = powerStateCb; } + bool getPowerState() { return mPowerOn; } + inline PowerStateType getSystemPowerState() { return mSystemPowerState; } + + void setAllowFlpNetworkFixes(uint32_t allow) { mAllowFlpNetworkFixes = allow; } + uint32_t getAllowFlpNetworkFixes() { return mAllowFlpNetworkFixes; } + void setSuplHostServer(const char* server, int port, LocServerType type); + void notifyClientOfCachedLocationSystemInfo(LocationAPI* client, + const LocationCallbacks& callbacks); + LocationCapabilitiesMask getCapabilities(); + void updateSystemPowerStateCommand(PowerStateType systemPowerState); + + /*==== DGnss Usable Report Flag ====================================================*/ + inline void setDGnssUsableFLag(bool dGnssNeedReport) { mDGnssNeedReport = dGnssNeedReport;} + inline bool isNMEAPrintEnabled() { + return ((mContext != NULL) && (0 != mContext->mGps_conf.ENABLE_NMEA_PRINT)); + } + + /*==== DGnss Ntrip Source ==========================================================*/ + void updateNTRIPGGAConsentCommand(bool consentAccepted) { mSendNmeaConsent = consentAccepted; } + void enablePPENtripStreamCommand(const GnssNtripConnectionParams& params, bool enableRTKEngine); + void disablePPENtripStreamCommand(); + void handleEnablePPENtrip(const GnssNtripConnectionParams& params); + void handleDisablePPENtrip(); + void reportGGAToNtrip(const char* nmea); + inline bool isDgnssNmeaRequired() { return mSendNmeaConsent && + mStartDgnssNtripParams.ntripParams.requiresNmeaLocation;} +}; + +#endif //GNSS_ADAPTER_H diff --git a/gps/gnss/Makefile.am b/gps/gnss/Makefile.am new file mode 100644 index 0000000..dd313a1 --- /dev/null +++ b/gps/gnss/Makefile.am @@ -0,0 +1,32 @@ +AM_CFLAGS = \ + $(LOCPLA_CFLAGS) \ + $(LOCHAL_CFLAGS) \ + $(GPSUTILS_CFLAGS) \ + $(LOCCORE_CFLAGS) \ + -I./ \ + -I../utils \ + -I$(WORKSPACE)/hardware/qcom/gps/core/data-items \ + -I../location \ + -std=c++1y + +libgnss_la_SOURCES = \ + location_gnss.cpp \ + GnssAdapter.cpp \ + XtraSystemStatusObserver.cpp \ + Agps.cpp \ + NativeAgpsHandler.cpp + +if USE_GLIB +libgnss_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +libgnss_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -avoid-version +libgnss_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +libgnss_la_CFLAGS = $(AM_CFLAGS) +libgnss_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0 +libgnss_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +libgnss_la_LIBADD = -lstdc++ -ldl $(GPSUTILS_LIBS) $(LOCCORE_LIBS) + +#Create and Install libraries +lib_LTLIBRARIES = libgnss.la diff --git a/gps/gnss/NativeAgpsHandler.cpp b/gps/gnss/NativeAgpsHandler.cpp new file mode 100644 index 0000000..ce4c03a --- /dev/null +++ b/gps/gnss/NativeAgpsHandler.cpp @@ -0,0 +1,127 @@ +/* Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "LocSvc_NativeAgpsHandler" + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace loc_core; + +// IDataItemObserver overrides +void NativeAgpsHandler::getName(string& name) { + name = "NativeAgpsHandler"; +} + +void NativeAgpsHandler::notify(const list& dlist) { + for (auto each : dlist) { + switch (each->getId()) { + case NETWORKINFO_DATA_ITEM_ID: { + NetworkInfoDataItemBase* networkInfo = + static_cast(each); + uint64_t mobileBit = (uint64_t )1 << loc_core::TYPE_MOBILE; + uint64_t allTypes = networkInfo->mAllTypes; + mConnected = ((networkInfo->mAllTypes & mobileBit) == mobileBit); + /** + * mApn Telephony preferred Access Point Name to use for + * carrier data connection when connected to a cellular network. + * Empty string, otherwise. + */ + mApn = networkInfo->mApn; + LOC_LOGd("updated mConnected:%d, mApn: %s", mConnected, mApn.c_str()); + break; + } + default: + break; + } + } +} + +NativeAgpsHandler* NativeAgpsHandler::sLocalHandle = nullptr; +NativeAgpsHandler::NativeAgpsHandler(IOsObserver* sysStatObs, GnssAdapter& adapter) : + mSystemStatusObsrvr(sysStatObs), mConnected(false), mAdapter(adapter) { + sLocalHandle = this; + list subItemIdList = {NETWORKINFO_DATA_ITEM_ID}; + mSystemStatusObsrvr->subscribe(subItemIdList, this); +} + +NativeAgpsHandler::~NativeAgpsHandler() { + if (nullptr != mSystemStatusObsrvr) { + LOC_LOGd("Unsubscribe for network info."); + list subItemIdList = {NETWORKINFO_DATA_ITEM_ID}; + mSystemStatusObsrvr->unsubscribe(subItemIdList, this); + } + sLocalHandle = nullptr; + mSystemStatusObsrvr = nullptr; +} + + +AgpsCbInfo NativeAgpsHandler::getAgpsCbInfo() { + AgpsCbInfo nativeCbInfo = {}; + nativeCbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb; + nativeCbInfo.atlType = AGPS_ATL_TYPE_WWAN; + return nativeCbInfo; +} + +void NativeAgpsHandler::agnssStatusIpV4Cb(AGnssExtStatusIpV4 statusInfo) { + if (nullptr != sLocalHandle) { + sLocalHandle->processATLRequestRelease(statusInfo); + } else { + LOC_LOGe("sLocalHandle is null"); + } +} + +void NativeAgpsHandler::processATLRequestRelease(AGnssExtStatusIpV4 statusInfo) { + if (LOC_AGPS_TYPE_WWAN_ANY == statusInfo.type) { + LOC_LOGd("status.type = %d status.apnTypeMask = 0x%X", statusInfo.type, + statusInfo.apnTypeMask); + switch (statusInfo.status) { + case LOC_GPS_REQUEST_AGPS_DATA_CONN: + if (mConnected) { + mAdapter.dataConnOpenCommand(LOC_AGPS_TYPE_WWAN_ANY, mApn.c_str(), mApn.size(), + AGPS_APN_BEARER_IPV4); + } else { + mAdapter.dataConnFailedCommand(LOC_AGPS_TYPE_WWAN_ANY); + } + break; + case LOC_GPS_RELEASE_AGPS_DATA_CONN: + mAdapter.dataConnClosedCommand(LOC_AGPS_TYPE_WWAN_ANY); + break; + default: + LOC_LOGe("Invalid Request: %d", statusInfo.status); + } + } else { + LOC_LOGe("mAgpsManger is null or invalid request type!"); + } +} diff --git a/gps/gnss/NativeAgpsHandler.h b/gps/gnss/NativeAgpsHandler.h new file mode 100644 index 0000000..fb0b46c --- /dev/null +++ b/gps/gnss/NativeAgpsHandler.h @@ -0,0 +1,64 @@ +/* Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef NATIVEAGPSHANDLER_H +#define NATIVEAGPSHANDLER_H + +#include +#include +#include +#include +#include +#include + +using namespace std; +using loc_core::IOsObserver; +using loc_core::IDataItemObserver; +using loc_core::IDataItemCore; + +class GnssAdapter; + +class NativeAgpsHandler : public IDataItemObserver { +public: + NativeAgpsHandler(IOsObserver* sysStatObs, GnssAdapter& adapter); + ~NativeAgpsHandler(); + AgpsCbInfo getAgpsCbInfo(); + // IDataItemObserver overrides + virtual void notify(const list& dlist); + inline virtual void getName(string& name); +private: + static NativeAgpsHandler* sLocalHandle; + static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 statusInfo); + void processATLRequestRelease(AGnssExtStatusIpV4 statusInfo); + IOsObserver* mSystemStatusObsrvr; + bool mConnected; + string mApn; + GnssAdapter& mAdapter; +}; + +#endif // NATIVEAGPSHANDLER_H diff --git a/gps/gnss/XtraSystemStatusObserver.cpp b/gps/gnss/XtraSystemStatusObserver.cpp new file mode 100644 index 0000000..d65622f --- /dev/null +++ b/gps/gnss/XtraSystemStatusObserver.cpp @@ -0,0 +1,384 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "LocSvc_XtraSystemStatusObs" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace loc_util; +using namespace loc_core; + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LocSvc_XSSO" + +class XtraIpcListener : public ILocIpcListener { + IOsObserver* mSystemStatusObsrvr; + const MsgTask* mMsgTask; + XtraSystemStatusObserver& mXSSO; +public: + inline XtraIpcListener(IOsObserver* observer, const MsgTask* msgTask, + XtraSystemStatusObserver& xsso) : + mSystemStatusObsrvr(observer), mMsgTask(msgTask), mXSSO(xsso) {} + virtual void onReceive(const char* data, uint32_t length, + const LocIpcRecver* recver) override { +#define STRNCMP(str, constStr) strncmp(str, constStr, sizeof(constStr)-1) + if (!STRNCMP(data, "ping")) { + LOC_LOGd("ping received"); +#ifdef USE_GLIB + } else if (!STRNCMP(data, "connectBackhaul")) { + char clientName[30] = {0}; + sscanf(data, "%*s %29s", clientName); + mSystemStatusObsrvr->connectBackhaul(string(clientName)); + } else if (!STRNCMP(data, "disconnectBackhaul")) { + char clientName[30] = {0}; + sscanf(data, "%*s %29s", clientName); + mSystemStatusObsrvr->disconnectBackhaul(string(clientName)); +#endif + } else if (!STRNCMP(data, "requestStatus")) { + int32_t xtraStatusUpdated = 0; + sscanf(data, "%*s %d", &xtraStatusUpdated); + + struct HandleStatusRequestMsg : public LocMsg { + XtraSystemStatusObserver& mXSSO; + int32_t mXtraStatusUpdated; + inline HandleStatusRequestMsg(XtraSystemStatusObserver& xsso, + int32_t xtraStatusUpdated) : + mXSSO(xsso), mXtraStatusUpdated(xtraStatusUpdated) {} + inline void proc() const override { + mXSSO.onStatusRequested(mXtraStatusUpdated); + /* SSR for DGnss Ntrip Source*/ + mXSSO.restartDgnssSource(); + } + }; + mMsgTask->sendMsg(new HandleStatusRequestMsg(mXSSO, xtraStatusUpdated)); + } else { + LOC_LOGw("unknown event: %s", data); + } + } +}; + +XtraSystemStatusObserver::XtraSystemStatusObserver(IOsObserver* sysStatObs, + const MsgTask* msgTask) : + mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask), + mGpsLock(-1), mConnections(~0), mXtraThrottle(true), + mReqStatusReceived(false), + mIsConnectivityStatusKnown(false), + mSender(LocIpc::getLocIpcLocalSender(LOC_IPC_XTRA)), + mDelayLocTimer(*mSender) { + subscribe(true); + auto recver = LocIpc::getLocIpcLocalRecver( + make_shared(sysStatObs, msgTask, *this), + LOC_IPC_HAL); + mIpc.startNonBlockingListening(recver); + mDelayLocTimer.start(100 /*.1 sec*/, false); +} + +bool XtraSystemStatusObserver::updateLockStatus(GnssConfigGpsLock lock) { + // mask NI(NFW bit) since from XTRA's standpoint GPS is enabled if + // MO(AFW bit) is enabled and disabled when MO is disabled + mGpsLock = lock & ~GNSS_CONFIG_GPS_LOCK_NI; + + if (!mReqStatusReceived) { + return true; + } + + stringstream ss; + ss << "gpslock"; + ss << " " << mGpsLock; + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +bool XtraSystemStatusObserver::updateConnections(uint64_t allConnections, + NetworkInfoType* networkHandleInfo) { + mIsConnectivityStatusKnown = true; + mConnections = allConnections; + + LOC_LOGd("updateConnections mConnections:%" PRIx64, mConnections); + for (uint8_t i = 0; i < MAX_NETWORK_HANDLES; ++i) { + mNetworkHandle[i] = networkHandleInfo[i]; + LOC_LOGd("updateConnections [%d] networkHandle:%" PRIx64 " networkType:%u", + i, mNetworkHandle[i].networkHandle, mNetworkHandle[i].networkType); + } + + if (!mReqStatusReceived) { + return true; + } + + stringstream ss; + ss << "connection" << endl << mConnections << endl + << mNetworkHandle[0].toString() << endl + << mNetworkHandle[1].toString() << endl + << mNetworkHandle[2].toString() << endl + << mNetworkHandle[3].toString() << endl + << mNetworkHandle[4].toString() << endl + << mNetworkHandle[5].toString() << endl + << mNetworkHandle[6].toString() << endl + << mNetworkHandle[7].toString() << endl + << mNetworkHandle[8].toString() << endl + << mNetworkHandle[MAX_NETWORK_HANDLES-1].toString(); + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +bool XtraSystemStatusObserver::updateTac(const string& tac) { + mTac = tac; + + if (!mReqStatusReceived) { + return true; + } + + stringstream ss; + ss << "tac"; + ss << " " << tac.c_str(); + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) { + mMccmnc = mccmnc; + + if (!mReqStatusReceived) { + return true; + } + + stringstream ss; + ss << "mncmcc"; + ss << " " << mccmnc.c_str(); + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +bool XtraSystemStatusObserver::updateXtraThrottle(const bool enabled) { + mXtraThrottle = enabled; + + if (!mReqStatusReceived) { + return true; + } + + stringstream ss; + ss << "xtrathrottle"; + ss << " " << (enabled ? 1 : 0); + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +inline bool XtraSystemStatusObserver::onStatusRequested(int32_t xtraStatusUpdated) { + mReqStatusReceived = true; + + if (xtraStatusUpdated) { + return true; + } + + stringstream ss; + + ss << "respondStatus" << endl; + (mGpsLock == -1 ? ss : ss << mGpsLock) << endl; + (mConnections == (uint64_t)~0 ? ss : ss << mConnections) << endl + << mNetworkHandle[0].toString() << endl + << mNetworkHandle[1].toString() << endl + << mNetworkHandle[2].toString() << endl + << mNetworkHandle[3].toString() << endl + << mNetworkHandle[4].toString() << endl + << mNetworkHandle[5].toString() << endl + << mNetworkHandle[6].toString() << endl + << mNetworkHandle[7].toString() << endl + << mNetworkHandle[8].toString() << endl + << mNetworkHandle[MAX_NETWORK_HANDLES-1].toString() << endl + << mTac << endl << mMccmnc << endl << mIsConnectivityStatusKnown; + + string s = ss.str(); + return ( LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()) ); +} + +void XtraSystemStatusObserver::startDgnssSource(const StartDgnssNtripParams& params) { + stringstream ss; + const GnssNtripConnectionParams* ntripParams = &(params.ntripParams); + + ss << "startDgnssSource" << endl; + ss << ntripParams->useSSL << endl; + ss << ntripParams->hostNameOrIp.data() << endl; + ss << ntripParams->port << endl; + ss << ntripParams->mountPoint.data() << endl; + ss << ntripParams->username.data() << endl; + ss << ntripParams->password.data() << endl; + if (ntripParams->requiresNmeaLocation && !params.nmea.empty()) { + ss << params.nmea.data() << endl; + } + string s = ss.str(); + + LOC_LOGd("%s", s.data()); + LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()); + // make a local copy of the string for SSR + mNtripParamsString.assign(std::move(s)); +} + +void XtraSystemStatusObserver::restartDgnssSource() { + if (!mNtripParamsString.empty()) { + LocIpc::send(*mSender, + (const uint8_t*)mNtripParamsString.data(), mNtripParamsString.size()); + LOC_LOGv("Xtra SSR %s", mNtripParamsString.data()); + } +} + +void XtraSystemStatusObserver::stopDgnssSource() { + LOC_LOGv(); + mNtripParamsString.clear(); + + const char s[] = "stopDgnssSource"; + LocIpc::send(*mSender, (const uint8_t*)s, strlen(s)); +} + +void XtraSystemStatusObserver::updateNmeaToDgnssServer(const string& nmea) +{ + stringstream ss; + ss << "updateDgnssServerNmea" << endl; + ss << nmea.data() << endl; + + string s = ss.str(); + LOC_LOGd("%s", s.data()); + LocIpc::send(*mSender, (const uint8_t*)s.data(), s.size()); +} + +void XtraSystemStatusObserver::subscribe(bool yes) +{ + // Subscription data list + list subItemIdList; + subItemIdList.push_back(NETWORKINFO_DATA_ITEM_ID); + subItemIdList.push_back(MCCMNC_DATA_ITEM_ID); + + if (yes) { + mSystemStatusObsrvr->subscribe(subItemIdList, this); + + list reqItemIdList; + reqItemIdList.push_back(TAC_DATA_ITEM_ID); + + mSystemStatusObsrvr->requestData(reqItemIdList, this); + + } else { + mSystemStatusObsrvr->unsubscribe(subItemIdList, this); + } +} + +// IDataItemObserver overrides +void XtraSystemStatusObserver::getName(string& name) +{ + name = "XtraSystemStatusObserver"; +} + +void XtraSystemStatusObserver::notify(const list& dlist) +{ + struct HandleOsObserverUpdateMsg : public LocMsg { + XtraSystemStatusObserver* mXtraSysStatObj; + list mDataItemList; + + inline HandleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs, + const list& dataItemList) : + mXtraSysStatObj(xtraSysStatObs) { + for (auto eachItem : dataItemList) { + IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem( + eachItem->getId()); + if (NULL == dataitem) { + break; + } + // Copy the contents of the data item + dataitem->copy(eachItem); + + mDataItemList.push_back(dataitem); + } + } + + inline ~HandleOsObserverUpdateMsg() { + for (auto itor = mDataItemList.begin(); itor != mDataItemList.end(); ++itor) { + if (*itor != nullptr) { + delete *itor; + *itor = nullptr; + } + } + } + + inline void proc() const { + for (auto each : mDataItemList) { + switch (each->getId()) + { + case NETWORKINFO_DATA_ITEM_ID: + { + NetworkInfoDataItemBase* networkInfo = + static_cast(each); + NetworkInfoType* networkHandleInfo = + static_cast(networkInfo->getNetworkHandle()); + mXtraSysStatObj->updateConnections(networkInfo->getAllTypes(), + networkHandleInfo); + } + break; + + case TAC_DATA_ITEM_ID: + { + TacDataItemBase* tac = + static_cast(each); + mXtraSysStatObj->updateTac(tac->mValue); + } + break; + + case MCCMNC_DATA_ITEM_ID: + { + MccmncDataItemBase* mccmnc = + static_cast(each); + mXtraSysStatObj->updateMccMnc(mccmnc->mValue); + } + break; + + default: + break; + } + } + } + }; + mMsgTask->sendMsg(new (nothrow) HandleOsObserverUpdateMsg(this, dlist)); +} diff --git a/gps/gnss/XtraSystemStatusObserver.h b/gps/gnss/XtraSystemStatusObserver.h new file mode 100644 index 0000000..56a3a9c --- /dev/null +++ b/gps/gnss/XtraSystemStatusObserver.h @@ -0,0 +1,112 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef XTRA_SYSTEM_STATUS_OBS_H +#define XTRA_SYSTEM_STATUS_OBS_H + +#include +#include +#include +#include +#include + +using namespace std; +using namespace loc_util; +using loc_core::IOsObserver; +using loc_core::IDataItemObserver; +using loc_core::IDataItemCore; + +struct StartDgnssNtripParams { + GnssNtripConnectionParams ntripParams; + string nmea; + + void clear() { + ntripParams.hostNameOrIp.clear(); + ntripParams.mountPoint.clear(); + ntripParams.username.clear(); + ntripParams.password.clear(); + ntripParams.port = 0; + ntripParams.useSSL = false; + ntripParams.requiresNmeaLocation = false; + nmea.clear(); + } +}; + +class XtraSystemStatusObserver : public IDataItemObserver { +public : + // constructor & destructor + XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask); + inline virtual ~XtraSystemStatusObserver() { + subscribe(false); + mIpc.stopNonBlockingListening(); + } + + // IDataItemObserver overrides + inline virtual void getName(string& name); + virtual void notify(const list& dlist); + + bool updateLockStatus(GnssConfigGpsLock lock); + bool updateConnections(uint64_t allConnections, + loc_core::NetworkInfoType* networkHandleInfo); + bool updateTac(const string& tac); + bool updateMccMnc(const string& mccmnc); + bool updateXtraThrottle(const bool enabled); + inline const MsgTask* getMsgTask() { return mMsgTask; } + void subscribe(bool yes); + bool onStatusRequested(int32_t xtraStatusUpdated); + void startDgnssSource(const StartDgnssNtripParams& params); + void restartDgnssSource(); + void stopDgnssSource(); + void updateNmeaToDgnssServer(const string& nmea); + +private: + IOsObserver* mSystemStatusObsrvr; + const MsgTask* mMsgTask; + GnssConfigGpsLock mGpsLock; + LocIpc mIpc; + uint64_t mConnections; + loc_core::NetworkInfoType mNetworkHandle[MAX_NETWORK_HANDLES]; + string mTac; + string mMccmnc; + bool mXtraThrottle; + bool mReqStatusReceived; + bool mIsConnectivityStatusKnown; + shared_ptr mSender; + string mNtripParamsString; + + class DelayLocTimer : public LocTimer { + LocIpcSender& mSender; + public: + DelayLocTimer(LocIpcSender& sender) : mSender(sender) {} + void timeOutCallback() override { + LocIpc::send(mSender, (const uint8_t*)"halinit", sizeof("halinit")); + } + } mDelayLocTimer; +}; + +#endif diff --git a/gps/gnss/location_gnss.cpp b/gps/gnss/location_gnss.cpp new file mode 100644 index 0000000..0454a13 --- /dev/null +++ b/gps/gnss/location_gnss.cpp @@ -0,0 +1,593 @@ +/* Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "GnssAdapter.h" +#include "location_interface.h" + +static GnssAdapter* gGnssAdapter = NULL; + +static void initialize(); +static void deinitialize(); + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks); +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb); +static void requestCapabilities(LocationAPI* client); + +static uint32_t startTracking(LocationAPI* client, TrackingOptions&); +static void updateTrackingOptions(LocationAPI* client, uint32_t id, TrackingOptions&); +static void stopTracking(LocationAPI* client, uint32_t id); + +static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response); +static uint32_t gnssDeleteAidingData(GnssAidingData& data); +static void gnssUpdateXtraThrottle(const bool enabled); + +static void setControlCallbacks(LocationControlCallbacks& controlCallbacks); +static uint32_t enable(LocationTechnologyType techType); +static void disable(uint32_t id); +static uint32_t* gnssUpdateConfig(const GnssConfig& config); +static uint32_t* gnssGetConfig(GnssConfigFlagsMask mask); + +static void gnssUpdateSvTypeConfig(GnssSvTypeConfig& config); +static void gnssGetSvTypeConfig(GnssSvTypeConfigCallback& callback); +static void gnssResetSvTypeConfig(); + +static void injectLocation(double latitude, double longitude, float accuracy); +static void injectLocationExt(const GnssLocationInfoNotification &locationInfo); +static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty); + +static void agpsInit(const AgpsCbInfo& cbInfo); +static void agpsDataConnOpen(AGpsExtType agpsType, const char* apnName, int apnLen, int ipType); +static void agpsDataConnClosed(AGpsExtType agpsType); +static void agpsDataConnFailed(AGpsExtType agpsType); +static void getDebugReport(GnssDebugReport& report); +static void updateConnectionStatus(bool connected, int8_t type, bool roaming, + NetworkHandle networkHandle, string& apn); +static void getGnssEnergyConsumed(GnssEnergyConsumedCallback energyConsumedCb); +static void enableNfwLocationAccess(bool enable); +static void nfwInit(const NfwCbInfo& cbInfo); +static void getPowerStateChanges(std::function powerStateCb); + +static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); +static void odcpiInject(const Location& location); + +static void blockCPI(double latitude, double longitude, float accuracy, + int blockDurationMsec, double latLonDiffThreshold); +static void updateBatteryStatus(bool charging); +static void updateSystemPowerState(PowerStateType systemPowerState); +static uint32_t setConstrainedTunc (bool enable, float tuncConstraint, + uint32_t energyBudget); +static uint32_t setPositionAssistedClockEstimator(bool enable); +static uint32_t gnssUpdateSvConfig(const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig); +static uint32_t gnssResetSvConfig(); +static uint32_t configLeverArm(const LeverArmConfigInfo& configInfo); +static uint32_t configRobustLocation(bool enable, bool enableForE911); +static uint32_t configMinGpsWeek(uint16_t minGpsWeek); +static uint32_t configDeadReckoningEngineParams(const DeadReckoningEngineConfig& dreConfig); +static uint32_t gnssUpdateSecondaryBandConfig(const GnssSvTypeConfig& secondaryBandConfig); +static uint32_t gnssGetSecondaryBandConfig(); +static void resetNetworkInfo(); + +static void updateNTRIPGGAConsent(bool consentAccepted); +static void enablePPENtripStream(const GnssNtripConnectionParams& params, bool enableRTKEngine); +static void disablePPENtripStream(); + +static bool measCorrInit(const measCorrSetCapabilitiesCb setCapabilitiesCb); +static bool measCorrSetCorrections(const GnssMeasurementCorrections gnssMeasCorr); +static void measCorrClose(); +static uint32_t antennaInfoInit(const antennaInfoCb antennaInfoCallback); +static void antennaInfoClose(); +static uint32_t configEngineRunState(PositioningEngineMask engType, LocEngineRunState engState); + +static const GnssInterface gGnssInterface = { + sizeof(GnssInterface), + initialize, + deinitialize, + addClient, + removeClient, + requestCapabilities, + startTracking, + updateTrackingOptions, + stopTracking, + gnssNiResponse, + setControlCallbacks, + enable, + disable, + gnssUpdateConfig, + gnssGetConfig, + gnssUpdateSvTypeConfig, + gnssGetSvTypeConfig, + gnssResetSvTypeConfig, + gnssDeleteAidingData, + gnssUpdateXtraThrottle, + injectLocation, + injectTime, + agpsInit, + agpsDataConnOpen, + agpsDataConnClosed, + agpsDataConnFailed, + getDebugReport, + updateConnectionStatus, + odcpiInit, + odcpiInject, + blockCPI, + getGnssEnergyConsumed, + enableNfwLocationAccess, + nfwInit, + getPowerStateChanges, + injectLocationExt, + updateBatteryStatus, + updateSystemPowerState, + setConstrainedTunc, + setPositionAssistedClockEstimator, + gnssUpdateSvConfig, + configLeverArm, + measCorrInit, + measCorrSetCorrections, + measCorrClose, + antennaInfoInit, + antennaInfoClose, + configRobustLocation, + configMinGpsWeek, + configDeadReckoningEngineParams, + updateNTRIPGGAConsent, + enablePPENtripStream, + disablePPENtripStream, + gnssUpdateSecondaryBandConfig, + gnssGetSecondaryBandConfig, + resetNetworkInfo, + configEngineRunState +}; + +#ifndef DEBUG_X86 +extern "C" const GnssInterface* getGnssInterface() +#else +const GnssInterface* getGnssInterface() +#endif // DEBUG_X86 +{ + gGnssInterface.initialize(); + return &gGnssInterface; +} + +static void initialize() +{ + if (NULL == gGnssAdapter) { + gGnssAdapter = new GnssAdapter(); + } +} + +static void deinitialize() +{ + if (NULL != gGnssAdapter) { + delete gGnssAdapter; + gGnssAdapter = NULL; + } +} + +static void addClient(LocationAPI* client, const LocationCallbacks& callbacks) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->addClientCommand(client, callbacks); + } +} + +static void removeClient(LocationAPI* client, removeClientCompleteCallback rmClientCb) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->removeClientCommand(client, rmClientCb); + } +} + +static void requestCapabilities(LocationAPI* client) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->requestCapabilitiesCommand(client); + } +} + +static uint32_t startTracking( + LocationAPI* client, TrackingOptions& trackingOptions) +{ + if (NULL != gGnssAdapter) { + return gGnssAdapter->startTrackingCommand(client, trackingOptions); + } else { + return 0; + } +} + +static void updateTrackingOptions( + LocationAPI* client, uint32_t id, TrackingOptions& trackingOptions) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->updateTrackingOptionsCommand( + client, id, trackingOptions); + } +} + +static void stopTracking(LocationAPI* client, uint32_t id) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->stopTrackingCommand(client, id); + } +} + +static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssNiResponseCommand(client, id, response); + } +} + +static void setControlCallbacks(LocationControlCallbacks& controlCallbacks) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->setControlCallbacksCommand(controlCallbacks); + } +} + +static uint32_t enable(LocationTechnologyType techType) +{ + if (NULL != gGnssAdapter) { + return gGnssAdapter->enableCommand(techType); + } else { + return 0; + } +} + +static void disable(uint32_t id) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->disableCommand(id); + } +} + +static uint32_t* gnssUpdateConfig(const GnssConfig& config) +{ + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssUpdateConfigCommand(config); + } else { + return NULL; + } +} + +static uint32_t* gnssGetConfig(GnssConfigFlagsMask mask) +{ + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssGetConfigCommand(mask); + } else { + return NULL; + } +} + +static void gnssUpdateSvTypeConfig(GnssSvTypeConfig& config) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssUpdateSvTypeConfigCommand(config); + } +} + +static void gnssGetSvTypeConfig(GnssSvTypeConfigCallback& callback) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssGetSvTypeConfigCommand(callback); + } +} + +static void gnssResetSvTypeConfig() +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssResetSvTypeConfigCommand(); + } +} + +static uint32_t gnssDeleteAidingData(GnssAidingData& data) +{ + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssDeleteAidingDataCommand(data); + } else { + return 0; + } +} + +static void gnssUpdateXtraThrottle(const bool enabled) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->gnssUpdateXtraThrottleCommand(enabled); + } +} + +static void injectLocation(double latitude, double longitude, float accuracy) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectLocationCommand(latitude, longitude, accuracy); + } +} + +static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectTimeCommand(time, timeReference, uncertainty); + } +} + +static void agpsInit(const AgpsCbInfo& cbInfo) { + + if (NULL != gGnssAdapter) { + gGnssAdapter->initAgpsCommand(cbInfo); + } +} +static void agpsDataConnOpen( + AGpsExtType agpsType, const char* apnName, int apnLen, int ipType) { + + if (NULL != gGnssAdapter) { + gGnssAdapter->dataConnOpenCommand( + agpsType, apnName, apnLen, (AGpsBearerType)ipType); + } +} +static void agpsDataConnClosed(AGpsExtType agpsType) { + + if (NULL != gGnssAdapter) { + gGnssAdapter->dataConnClosedCommand(agpsType); + } +} +static void agpsDataConnFailed(AGpsExtType agpsType) { + + if (NULL != gGnssAdapter) { + gGnssAdapter->dataConnFailedCommand(agpsType); + } +} + +static void getDebugReport(GnssDebugReport& report) { + + if (NULL != gGnssAdapter) { + gGnssAdapter->getDebugReport(report); + } +} + +static void updateConnectionStatus(bool connected, int8_t type, + bool roaming, NetworkHandle networkHandle, + string& apn) { + if (NULL != gGnssAdapter) { + gGnssAdapter->getSystemStatus()->eventConnectionStatus( + connected, type, roaming, networkHandle, apn); + } +} + +static void odcpiInit(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->initOdcpiCommand(callback, priority); + } +} + +static void odcpiInject(const Location& location) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectOdcpiCommand(location); + } +} + +static void blockCPI(double latitude, double longitude, float accuracy, + int blockDurationMsec, double latLonDiffThreshold) { + if (NULL != gGnssAdapter) { + gGnssAdapter->blockCPICommand(latitude, longitude, accuracy, + blockDurationMsec, latLonDiffThreshold); + } +} + +static void getGnssEnergyConsumed(GnssEnergyConsumedCallback energyConsumedCb) { + if (NULL != gGnssAdapter) { + gGnssAdapter->getGnssEnergyConsumedCommand(energyConsumedCb); + } +} + +static void enableNfwLocationAccess(bool enable) { + if (NULL != gGnssAdapter) { + gGnssAdapter->nfwControlCommand(enable); + } +} + +static void nfwInit(const NfwCbInfo& cbInfo) { + if (NULL != gGnssAdapter) { + gGnssAdapter->initNfwCommand(cbInfo); + } +} + +static void getPowerStateChanges(std::function powerStateCb) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->getPowerStateChangesCommand(powerStateCb); + } +} + +static void injectLocationExt(const GnssLocationInfoNotification &locationInfo) +{ + if (NULL != gGnssAdapter) { + gGnssAdapter->injectLocationExtCommand(locationInfo); + } +} + +static void updateBatteryStatus(bool charging) { + if (NULL != gGnssAdapter) { + gGnssAdapter->getSystemStatus()->updatePowerConnectState(charging); + } +} + +static void resetNetworkInfo() { + if (NULL != gGnssAdapter) { + gGnssAdapter->getSystemStatus()->resetNetworkInfo(); + } +} + +static void updateSystemPowerState(PowerStateType systemPowerState) { + if (NULL != gGnssAdapter) { + gGnssAdapter->updateSystemPowerStateCommand(systemPowerState); + } +} + +static uint32_t setConstrainedTunc (bool enable, float tuncConstraint, uint32_t energyBudget) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->setConstrainedTuncCommand(enable, tuncConstraint, energyBudget); + } else { + return 0; + } +} + +static uint32_t setPositionAssistedClockEstimator(bool enable) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->setPositionAssistedClockEstimatorCommand(enable); + } else { + return 0; + } +} + +static uint32_t gnssUpdateSvConfig( + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssUpdateSvConfigCommand( + constellationEnablementConfig, blacklistSvConfig); + } else { + return 0; + } +} + +static uint32_t configLeverArm(const LeverArmConfigInfo& configInfo){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->configLeverArmCommand(configInfo); + } else { + return 0; + } +} + +static bool measCorrInit(const measCorrSetCapabilitiesCb setCapabilitiesCb) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->openMeasCorrCommand(setCapabilitiesCb); + } else { + return false; + } +} + +static bool measCorrSetCorrections(const GnssMeasurementCorrections gnssMeasCorr) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->measCorrSetCorrectionsCommand(gnssMeasCorr); + } else { + return false; + } +} + +static void measCorrClose() { + if (NULL != gGnssAdapter) { + gGnssAdapter->closeMeasCorrCommand(); + } +} + +static uint32_t antennaInfoInit(const antennaInfoCb antennaInfoCallback) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->antennaInfoInitCommand(antennaInfoCallback); + } else { + return ANTENNA_INFO_ERROR_GENERIC; + } +} + +static void antennaInfoClose() { + if (NULL != gGnssAdapter) { + return gGnssAdapter->antennaInfoCloseCommand(); + } +} + +static uint32_t configRobustLocation(bool enable, bool enableForE911){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->configRobustLocationCommand(enable, enableForE911); + } else { + return 0; + } +} + +static uint32_t configMinGpsWeek(uint16_t minGpsWeek){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->configMinGpsWeekCommand(minGpsWeek); + } else { + return 0; + } +} + +static uint32_t configDeadReckoningEngineParams(const DeadReckoningEngineConfig& dreConfig){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->configDeadReckoningEngineParamsCommand(dreConfig); + } else { + return 0; + } +} + +static uint32_t gnssUpdateSecondaryBandConfig( + const GnssSvTypeConfig& secondaryBandConfig) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssUpdateSecondaryBandConfigCommand(secondaryBandConfig); + } else { + return 0; + } +} + +static uint32_t gnssGetSecondaryBandConfig(){ + if (NULL != gGnssAdapter) { + return gGnssAdapter->gnssGetSecondaryBandConfigCommand(); + } else { + return 0; + } +} + +static void updateNTRIPGGAConsent(bool consentAccepted){ + if (NULL != gGnssAdapter) { + // Call will be enabled once GnssAdapter impl. is ready. + gGnssAdapter->updateNTRIPGGAConsentCommand(consentAccepted); + } +} + +static void enablePPENtripStream(const GnssNtripConnectionParams& params, bool enableRTKEngine){ + if (NULL != gGnssAdapter) { + // Call will be enabled once GnssAdapter impl. is ready. + gGnssAdapter->enablePPENtripStreamCommand(params, enableRTKEngine); + } +} + +static void disablePPENtripStream(){ + if (NULL != gGnssAdapter) { + // Call will be enabled once GnssAdapter impl. is ready. + gGnssAdapter->disablePPENtripStreamCommand(); + } +} + +static uint32_t configEngineRunState(PositioningEngineMask engType, LocEngineRunState engState) { + if (NULL != gGnssAdapter) { + return gGnssAdapter->configEngineRunStateCommand(engType, engState); + } else { + return 0; + } +} diff --git a/gps/gps_vendor_board.mk b/gps/gps_vendor_board.mk new file mode 100644 index 0000000..e1915ea --- /dev/null +++ b/gps/gps_vendor_board.mk @@ -0,0 +1,7 @@ +# Flags from BoardConfigVendor.mk +ifneq ($(TARGET_USES_QMAA),true) +BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := default +else ifneq ($(TARGET_USES_QMAA_OVERRIDE_GPS),false) +BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := default +endif + diff --git a/gps/gps_vendor_product.mk b/gps/gps_vendor_product.mk new file mode 100644 index 0000000..0e578e8 --- /dev/null +++ b/gps/gps_vendor_product.mk @@ -0,0 +1,44 @@ +# HAL packages +ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),) + +# GPS-HIDL +LOC_BOARD_PLATFORM_LIST += msm8937 +LOC_BOARD_PLATFORM_LIST += msm8953 +LOC_BOARD_PLATFORM_LIST += msm8998 +LOC_BOARD_PLATFORM_LIST += apq8098_latv +LOC_BOARD_PLATFORM_LIST += sdm710 +LOC_BOARD_PLATFORM_LIST += qcs605 +LOC_BOARD_PLATFORM_LIST += sdm845 +LOC_BOARD_PLATFORM_LIST += sdm660 +LOC_BOARD_PLATFORM_LIST += msmnile +LOC_BOARD_PLATFORM_LIST += sdmshrike +LOC_BOARD_PLATFORM_LIST += $(MSMSTEPPE) +LOC_BOARD_PLATFORM_LIST += $(TRINKET) +LOC_BOARD_PLATFORM_LIST += kona +LOC_BOARD_PLATFORM_LIST += atoll +LOC_BOARD_PLATFORM_LIST += lito +LOC_BOARD_PLATFORM_LIST += bengal +LOC_BOARD_PLATFORM_LIST += lahaina +LOC_BOARD_PLATFORM_LIST += holi + +# Add product packages +ifneq (,$(filter $(LOC_BOARD_PLATFORM_LIST),$(TARGET_BOARD_PLATFORM))) + +PRODUCT_PACKAGES += gps.conf +PRODUCT_PACKAGES += flp.conf +PRODUCT_PACKAGES += gnss_antenna_info.conf +PRODUCT_PACKAGES += libloc_pla_headers +PRODUCT_PACKAGES += liblocation_api_headers +PRODUCT_PACKAGES += libgps.utils_headers +PRODUCT_PACKAGES += liblocation_api +PRODUCT_PACKAGES += libgps.utils +PRODUCT_PACKAGES += libbatching +PRODUCT_PACKAGES += libgeofencing +PRODUCT_PACKAGES += libloc_core +PRODUCT_PACKAGES += libgnss + +PRODUCT_PACKAGES += android.hardware.gnss@2.1-impl-qti +PRODUCT_PACKAGES += android.hardware.gnss@2.1-service-qti + +endif # ifneq (,$(filter $(LOC_BOARD_PLATFORM_LIST),$(TARGET_BOARD_PLATFORM))) +endif # ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),) diff --git a/gps/loc-hal.pc.in b/gps/loc-hal.pc.in new file mode 100644 index 0000000..22d174b --- /dev/null +++ b/gps/loc-hal.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: loc-hal +Description: QTI GPS Loc HAL +Version: @VERSION +Libs: -L${libdir} -lgnss +Cflags: -I${includedir} -I${includedir}/utils -I${includedir}/core -I${includedir}/loc-hal diff --git a/gps/location/Android.bp b/gps/location/Android.bp new file mode 100644 index 0000000..8532a08 --- /dev/null +++ b/gps/location/Android.bp @@ -0,0 +1,36 @@ + +cc_library_shared { + + name: "liblocation_api", + vendor: true, + + sanitize: GNSS_SANITIZE, + + shared_libs: [ + "libutils", + "libcutils", + "libgps.utils", + "libdl", + "liblog", + ], + + srcs: [ + "LocationAPI.cpp", + "LocationAPIClientBase.cpp", + ], + + cflags: ["-fno-short-enums"] + GNSS_CFLAGS, + + header_libs: [ + "libloc_pla_headers", + "libgps.utils_headers", + ], + +} + +cc_library_headers { + + name: "liblocation_api_headers", + export_include_dirs: ["."], + vendor: true, +} diff --git a/gps/location/ILocationAPI.h b/gps/location/ILocationAPI.h new file mode 100644 index 0000000..29846ac --- /dev/null +++ b/gps/location/ILocationAPI.h @@ -0,0 +1,406 @@ +/* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ILOCATIONAPI_H +#define ILOCATIONAPI_H + +#include "LocationDataTypes.h" + +class ILocationAPI +{ +public: + virtual ~ILocationAPI(){}; + + /** @brief Updates/changes the callbacks that will be called. + mandatory callbacks must be present for callbacks to be successfully updated + no return value */ + virtual void updateCallbacks(LocationCallbacks&) = 0; + + /* ================================== TRACKING ================================== */ + + /** @brief Starts a tracking session, which returns a session id that will be + used by the other tracking APIs and also in the responseCallback to match command + with response. locations are reported on the registered trackingCallback + periodically according to LocationOptions. + @return session id + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successfully started + LOCATION_ERROR_ALREADY_STARTED if a startTracking session is already in progress + LOCATION_ERROR_CALLBACK_MISSING if no trackingCallback was passed + LOCATION_ERROR_INVALID_PARAMETER if LocationOptions parameter is invalid */ + virtual uint32_t startTracking(TrackingOptions&) = 0; + + /** @brief Stops a tracking session associated with id parameter. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a tracking session */ + virtual void stopTracking(uint32_t id) = 0; + + /** @brief Changes the LocationOptions of a tracking session associated with id. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if LocationOptions parameters are invalid + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a tracking session */ + virtual void updateTrackingOptions(uint32_t id, TrackingOptions&) = 0; + + /* ================================== BATCHING ================================== */ + + /** @brief starts a batching session, which returns a session id that will be + used by the other batching APIs and also in the responseCallback to match command + with response. locations are reported on the batchingCallback passed in createInstance + periodically according to LocationOptions. A batching session starts tracking on + the low power processor and delivers them in batches by the batchingCallback when + the batch is full or when getBatchedLocations is called. This allows for the processor + that calls this API to sleep when the low power processor can batch locations in the + backgroup and wake up the processor calling the API only when the batch is full, thus + saving power. + @return session id + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_ALREADY_STARTED if a startBatching session is already in progress + LOCATION_ERROR_CALLBACK_MISSING if no batchingCallback + LOCATION_ERROR_INVALID_PARAMETER if a parameter is invalid + LOCATION_ERROR_NOT_SUPPORTED if batching is not supported */ + virtual uint32_t startBatching(BatchingOptions&) = 0; + + /** @brief Stops a batching session associated with id parameter. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with batching session */ + virtual void stopBatching(uint32_t id) = 0; + + /** @brief Changes the LocationOptions of a batching session associated with id. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if LocationOptions parameters are invalid + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a batching session */ + virtual void updateBatchingOptions(uint32_t id, BatchingOptions&) = 0; + + /** @brief Gets a number of locations that are currently stored/batched + on the low power processor, delivered by the batchingCallback passed in createInstance. + Location are then deleted from the batch stored on the low power processor. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful, will be followed by batchingCallback call + LOCATION_ERROR_CALLBACK_MISSING if no batchingCallback + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a batching session */ + virtual void getBatchedLocations(uint32_t id, size_t count) = 0; + + /* ================================== GEOFENCE ================================== */ + + /** @brief Adds any number of geofences and returns an array of geofence ids that + will be used by the other geofence APIs and also in the collectiveResponseCallback to + match command with response. The geofenceBreachCallback will deliver the status of each + geofence according to the GeofenceOption for each. The geofence id array returned will + be valid until the collectiveResponseCallback is called and has returned. + @return id array + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_CALLBACK_MISSING if no geofenceBreachCallback + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + LOCATION_ERROR_NOT_SUPPORTED if geofence is not supported */ + virtual uint32_t* addGeofences(size_t count, GeofenceOption*, GeofenceInfo*) = 0; + + /** @brief Removes any number of geofences. Caller should delete ids array after + removeGeofences returneds. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void removeGeofences(size_t count, uint32_t* ids) = 0; + + /** @brief Modifies any number of geofences. Caller should delete ids array after + modifyGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid */ + virtual void modifyGeofences(size_t count, uint32_t* ids, GeofenceOption* options) = 0; + + /** @brief Pauses any number of geofences, which is similar to removeGeofences, + only that they can be resumed at any time. Caller should delete ids array after + pauseGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void pauseGeofences(size_t count, uint32_t* ids) = 0; + + /** @brief Resumes any number of geofences that are currently paused. Caller should + delete ids array after resumeGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void resumeGeofences(size_t count, uint32_t* ids) = 0; + + /* ================================== GNSS ====================================== */ + + /** @brief gnssNiResponse is called in response to a gnssNiCallback. + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters in GnssNiResponse are invalid + LOCATION_ERROR_ID_UNKNOWN if id does not match a gnssNiCallback */ + virtual void gnssNiResponse(uint32_t id, GnssNiResponse response) = 0; +}; + +class ILocationControlAPI +{ +public: + virtual ~ILocationControlAPI(){}; + + /** @brief Updates the gnss specific configuration, which returns a session id array + with an id for each of the bits set in GnssConfig.flags, order from low bits to high bits. + The response for each config that is set will be returned in collectiveResponseCallback. + The session id array returned will be valid until the collectiveResponseCallback is called + and has returned. This effect is global for all clients of ILocationAPI. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_INVALID_PARAMETER if any other parameters are invalid + LOCATION_ERROR_GENERAL_FAILURE if failure for any other reason */ + virtual uint32_t* gnssUpdateConfig(const GnssConfig& config) = 0; + + /** @brief Delete specific gnss aiding data for testing, which returns a session id + that will be returned in responseCallback to match command with response. + Only allowed in userdebug builds. This effect is global for all clients of ILocationAPI. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + LOCATION_ERROR_NOT_SUPPORTED if build is not userdebug */ + virtual uint32_t gnssDeleteAidingData(GnssAidingData& data) = 0; + + /** @brief + Configure the constellation and SVs to be used by the GNSS engine on + modem. + + @param + constellationEnablementConfig: configuration to enable/disable SV + constellation to be used by SPE engine. When size in + constellationEnablementConfig is set to 0, this indicates to reset SV + constellation configuration to modem NV default. + + blacklistSvConfig: configuration to blacklist or unblacklist SVs + used by SPE engine + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellations( + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) = 0; + + /** @brief + Configure the secondary band of constellations to be used by + the GNSS engine on modem. + + @param + secondaryBandConfig: configuration the secondary band usage + for SPE engine + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellationSecondaryBand( + const GnssSvTypeConfig& secondaryBandConfig) = 0; + + /** @brief + Enable or disable the constrained time uncertainty feature. + + @param + enable: true to enable the constrained time uncertainty + feature and false to disable the constrainted time + uncertainty feature. + + @param + tuncThreshold: this specifies the time uncertainty threshold + that gps engine need to maintain, in units of milli-seconds. + Default is 0.0 meaning that modem default value of time + uncertainty threshold will be used. This parameter is + ignored when requesting to disable this feature. + + @param + energyBudget: this specifies the power budget that gps + engine is allowed to spend to maintain the time uncertainty. + Default is 0 meaning that GPS engine is not constained by + power budget and can spend as much power as needed. The + parameter need to be specified in units of 0.1 milli watt + second. This parameter is ignored requesting to disable this + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters + are invalid + */ + virtual uint32_t configConstrainedTimeUncertainty( + bool enable, float tuncThreshold = 0.0, + uint32_t energyBudget = 0) = 0; + + /** @brief + Enable or disable position assisted clock estimator feature. + + @param + enable: true to enable position assisted clock estimator and + false to disable the position assisted clock estimator + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configPositionAssistedClockEstimator(bool enable) = 0; + + /** @brief + Sets the lever arm parameters for the vehicle. + + @param + configInfo: lever arm configuration info regarding below two + types of lever arm info: + a: GNSS Antenna w.r.t the origin at the IMU e.g.: inertial + measurement unit. + b: lever arm parameters regarding the OPF (output frame) + w.r.t the origin (at the GPS Antenna). Vehicle manufacturers + prefer the position output to be tied to a specific point in + the vehicle rather than where the antenna is placed + (midpoint of the rear axle is typical). + + Caller can choose types of lever arm info to configure via the + leverMarkTypeMask. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configLeverArm(const LeverArmConfigInfo& configInfo) = 0; + + /** @brief + Configure the robust location setting. + + @param + enable: true to enable robust location and false to disable + robust location. + + @param + enableForE911: true to enable robust location when device is on + E911 session and false to disable on E911 session. + This parameter is only valid if robust location is enabled. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configRobustLocation(bool enable, bool enableForE911) = 0; + + /** @brief + Config the minimum GPS week used by modem GNSS engine. + + @param + minGpsWeek: minimum GPS week to be used by modem GNSS engine. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configMinGpsWeek(uint16_t minGpsWeek) = 0; + + /** @brief + Configure the vehicle body-to-Sensor mount parameters and + other parameters for dead reckoning position engine. + + @param + dreConfig: vehicle body-to-Sensor mount angles and other + parameters. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configDeadReckoningEngineParams(const DeadReckoningEngineConfig& dreConfig)=0; + + /** @brief + This API is used to instruct the specified engine to be in + the pause/resume state.
+ + When the engine is placed in paused state, the engine will + stop. If there is an on-going session, engine will no longer + produce fixes. In the paused state, calling API to delete + aiding data from the paused engine may not have effect. + Request to delete Aiding data shall be issued after + engine resume.
+ + Currently, only DRE engine will support pause/resume + request. responseCb() will return not supported when request + is made to pause/resume none-DRE engine.
+ + Request to pause/resume DRE engine can be made with or + without an on-going session. With QDR engine, on resume, + GNSS position & heading re-acquisition is needed for DR + engine to engage. If DR engine is already in the requested + state, the request will be no-op.
+ + @param + engType: the engine that is instructed to change its run + state.
+ + engState: the new engine run state that the engine is + instructed to be in.
+ + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configEngineRunState(PositioningEngineMask engType, + LocEngineRunState engState) = 0; +}; + +#endif /* ILOCATIONAPI_H */ diff --git a/gps/location/LocationAPI.cpp b/gps/location/LocationAPI.cpp new file mode 100644 index 0000000..3a50c46 --- /dev/null +++ b/gps/location/LocationAPI.cpp @@ -0,0 +1,976 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_LocationAPI" + +#include +#include +#include +#include +#include +#include +#include + +typedef const GnssInterface* (getGnssInterface)(); +typedef const GeofenceInterface* (getGeofenceInterface)(); +typedef const BatchingInterface* (getBatchingInterface)(); +typedef void (createOSFramework)(); +typedef void (destroyOSFramework)(); + +// GTP services +typedef uint32_t (setOptInStatusGetter)(bool userConsent, responseCallback* callback); +typedef void (enableProviderGetter)(); +typedef void (disableProviderGetter)(); +typedef void (getSingleNetworkLocationGetter)(trackingCallback* callback); +typedef void (stopNetworkLocationGetter)(trackingCallback* callback); + +typedef struct { + // bit mask of the adpaters that we need to wait for the removeClientCompleteCallback + // before we invoke the registered locationApiDestroyCompleteCallback + LocationAdapterTypeMask waitAdapterMask; + locationApiDestroyCompleteCallback destroyCompleteCb; +} LocationAPIDestroyCbData; + +// This is the map for the client that has requested destroy with +// destroy callback provided. +typedef std::map + LocationClientDestroyCbMap; + +typedef std::map LocationClientMap; +typedef struct { + LocationClientMap clientData; + LocationClientDestroyCbMap destroyClientData; + LocationControlAPI* controlAPI; + LocationControlCallbacks controlCallbacks; + GnssInterface* gnssInterface; + GeofenceInterface* geofenceInterface; + BatchingInterface* batchingInterface; +} LocationAPIData; + +static LocationAPIData gData = {}; +static pthread_mutex_t gDataMutex = PTHREAD_MUTEX_INITIALIZER; +static bool gGnssLoadFailed = false; +static bool gBatchingLoadFailed = false; +static bool gGeofenceLoadFailed = false; +static uint32_t gOSFrameworkRefCount = 0; + +template +static const T1* loadLocationInterface(const char* library, const char* name) { + void* libhandle = nullptr; + T2* getter = (T2*)dlGetSymFromLib(libhandle, library, name); + if (nullptr == getter) { + return (const T1*) getter; + }else { + return (*getter)(); + } +} + +static void createOSFrameworkInstance() { + void* libHandle = nullptr; + createOSFramework* getter = (createOSFramework*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "createOSFramework"); + if (getter != nullptr) { + (*getter)(); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +static void destroyOSFrameworkInstance() { + void* libHandle = nullptr; + destroyOSFramework* getter = (destroyOSFramework*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "destroyOSFramework"); + if (getter != nullptr) { + (*getter)(); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +static bool needsGnssTrackingInfo(LocationCallbacks& locationCallbacks) +{ + return (locationCallbacks.gnssLocationInfoCb != nullptr || + locationCallbacks.engineLocationsInfoCb != nullptr || + locationCallbacks.gnssSvCb != nullptr || + locationCallbacks.gnssNmeaCb != nullptr || + locationCallbacks.gnssDataCb != nullptr || + locationCallbacks.gnssMeasurementsCb != nullptr); +} + +static bool isGnssClient(LocationCallbacks& locationCallbacks) +{ + return (locationCallbacks.gnssNiCb != nullptr || + locationCallbacks.trackingCb != nullptr || + locationCallbacks.gnssLocationInfoCb != nullptr || + locationCallbacks.engineLocationsInfoCb != nullptr || + locationCallbacks.gnssSvCb != nullptr || + locationCallbacks.gnssNmeaCb != nullptr || + locationCallbacks.gnssDataCb != nullptr || + locationCallbacks.gnssMeasurementsCb != nullptr || + locationCallbacks.locationSystemInfoCb != nullptr); +} + +static bool isBatchingClient(LocationCallbacks& locationCallbacks) +{ + return (locationCallbacks.batchingCb != nullptr); +} + +static bool isGeofenceClient(LocationCallbacks& locationCallbacks) +{ + return (locationCallbacks.geofenceBreachCb != nullptr || + locationCallbacks.geofenceStatusCb != nullptr); +} + + +void LocationAPI::onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType) +{ + bool invokeCallback = false; + locationApiDestroyCompleteCallback destroyCompleteCb; + LOC_LOGd("adatper type %x", adapterType); + pthread_mutex_lock(&gDataMutex); + auto it = gData.destroyClientData.find(this); + if (it != gData.destroyClientData.end()) { + it->second.waitAdapterMask &= ~adapterType; + if (it->second.waitAdapterMask == 0) { + invokeCallback = true; + destroyCompleteCb = it->second.destroyCompleteCb; + gData.destroyClientData.erase(it); + } + } + pthread_mutex_unlock(&gDataMutex); + + if (invokeCallback) { + LOC_LOGd("invoke client destroy cb"); + if (!destroyCompleteCb) { + (destroyCompleteCb) (); + } + + delete this; + } +} + +void onGnssRemoveClientCompleteCb (LocationAPI* client) +{ + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GNSS_TYPE_BIT); +} + +void onBatchingRemoveClientCompleteCb (LocationAPI* client) +{ + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_BATCHING_TYPE_BIT); +} + +void onGeofenceRemoveClientCompleteCb (LocationAPI* client) +{ + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GEOFENCE_TYPE_BIT); +} + +LocationAPI* +LocationAPI::createInstance (LocationCallbacks& locationCallbacks) +{ + if (nullptr == locationCallbacks.capabilitiesCb || + nullptr == locationCallbacks.responseCb || + nullptr == locationCallbacks.collectiveResponseCb) { + LOC_LOGe("missing mandatory callback, return null"); + return NULL; + } + + LocationAPI* newLocationAPI = new LocationAPI(); + bool requestedCapabilities = false; + + pthread_mutex_lock(&gDataMutex); + + gOSFrameworkRefCount++; + if (1 == gOSFrameworkRefCount) { + createOSFrameworkInstance(); + } + + if (isGnssClient(locationCallbacks)) { + if (NULL == gData.gnssInterface && !gGnssLoadFailed) { + gData.gnssInterface = + (GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface"); + if (NULL == gData.gnssInterface) { + gGnssLoadFailed = true; + LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__); + } else { + gData.gnssInterface->initialize(); + } + } + if (NULL != gData.gnssInterface) { + gData.gnssInterface->addClient(newLocationAPI, locationCallbacks); + if (!requestedCapabilities) { + gData.gnssInterface->requestCapabilities(newLocationAPI); + requestedCapabilities = true; + } + } + } + + if (isBatchingClient(locationCallbacks)) { + if (NULL == gData.batchingInterface && !gBatchingLoadFailed) { + gData.batchingInterface = + (BatchingInterface*)loadLocationInterface("libbatching.so", "getBatchingInterface"); + if (NULL == gData.batchingInterface) { + gBatchingLoadFailed = true; + LOC_LOGW("%s:%d]: No batching interface available", __func__, __LINE__); + } else { + gData.batchingInterface->initialize(); + } + } + if (NULL != gData.batchingInterface) { + gData.batchingInterface->addClient(newLocationAPI, locationCallbacks); + if (!requestedCapabilities) { + gData.batchingInterface->requestCapabilities(newLocationAPI); + requestedCapabilities = true; + } + } + } + + if (isGeofenceClient(locationCallbacks)) { + if (NULL == gData.geofenceInterface && !gGeofenceLoadFailed) { + gData.geofenceInterface = + (GeofenceInterface*)loadLocationInterface("libgeofencing.so", "getGeofenceInterface"); + if (NULL == gData.geofenceInterface) { + gGeofenceLoadFailed = true; + LOC_LOGW("%s:%d]: No geofence interface available", __func__, __LINE__); + } else { + gData.geofenceInterface->initialize(); + } + } + if (NULL != gData.geofenceInterface) { + gData.geofenceInterface->addClient(newLocationAPI, locationCallbacks); + if (!requestedCapabilities) { + gData.geofenceInterface->requestCapabilities(newLocationAPI); + requestedCapabilities = true; + } + } + } + + gData.clientData[newLocationAPI] = locationCallbacks; + + pthread_mutex_unlock(&gDataMutex); + + return newLocationAPI; +} + +void +LocationAPI::destroy(locationApiDestroyCompleteCallback destroyCompleteCb) +{ + bool invokeDestroyCb = false; + + pthread_mutex_lock(&gDataMutex); + auto it = gData.clientData.find(this); + if (it != gData.clientData.end()) { + bool removeFromGnssInf = (NULL != gData.gnssInterface); + bool removeFromBatchingInf = (NULL != gData.batchingInterface); + bool removeFromGeofenceInf = (NULL != gData.geofenceInterface); + bool needToWait = (removeFromGnssInf || removeFromBatchingInf || removeFromGeofenceInf); + LOC_LOGe("removeFromGnssInf: %d, removeFromBatchingInf: %d, removeFromGeofenceInf: %d," + "needToWait: %d", removeFromGnssInf, removeFromBatchingInf, removeFromGeofenceInf, + needToWait); + + if ((NULL != destroyCompleteCb) && (true == needToWait)) { + LocationAPIDestroyCbData destroyCbData = {}; + destroyCbData.destroyCompleteCb = destroyCompleteCb; + // record down from which adapter we need to wait for the destroy complete callback + // only when we have received all the needed callbacks from all the associated stacks, + // we shall notify the client. + destroyCbData.waitAdapterMask = + (removeFromGnssInf ? LOCATION_ADAPTER_GNSS_TYPE_BIT : 0); + destroyCbData.waitAdapterMask |= + (removeFromBatchingInf ? LOCATION_ADAPTER_BATCHING_TYPE_BIT : 0); + destroyCbData.waitAdapterMask |= + (removeFromGeofenceInf ? LOCATION_ADAPTER_GEOFENCE_TYPE_BIT : 0); + gData.destroyClientData[this] = destroyCbData; + LOC_LOGi("destroy data stored in the map: 0x%x", destroyCbData.waitAdapterMask); + } + + if (removeFromGnssInf) { + gData.gnssInterface->removeClient(it->first, + onGnssRemoveClientCompleteCb); + } + if (removeFromBatchingInf) { + gData.batchingInterface->removeClient(it->first, + onBatchingRemoveClientCompleteCb); + } + if (removeFromGeofenceInf) { + gData.geofenceInterface->removeClient(it->first, + onGeofenceRemoveClientCompleteCb); + } + + gData.clientData.erase(it); + + if (!needToWait) { + invokeDestroyCb = true; + } + } else { + LOC_LOGE("%s:%d]: Location API client %p not found in client data", + __func__, __LINE__, this); + } + + if (1 == gOSFrameworkRefCount) { + destroyOSFrameworkInstance(); + } + gOSFrameworkRefCount--; + + pthread_mutex_unlock(&gDataMutex); + if (invokeDestroyCb) { + if (!destroyCompleteCb) { + (destroyCompleteCb) (); + } + delete this; + } +} + +LocationAPI::LocationAPI() +{ + LOC_LOGD("LOCATION API CONSTRUCTOR"); +} + +// private destructor +LocationAPI::~LocationAPI() +{ + LOC_LOGD("LOCATION API DESTRUCTOR"); +} + +void +LocationAPI::updateCallbacks(LocationCallbacks& locationCallbacks) +{ + if (nullptr == locationCallbacks.capabilitiesCb || + nullptr == locationCallbacks.responseCb || + nullptr == locationCallbacks.collectiveResponseCb) { + return; + } + + pthread_mutex_lock(&gDataMutex); + + if (isGnssClient(locationCallbacks)) { + if (NULL == gData.gnssInterface && !gGnssLoadFailed) { + gData.gnssInterface = + (GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface"); + if (NULL == gData.gnssInterface) { + gGnssLoadFailed = true; + LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__); + } else { + gData.gnssInterface->initialize(); + } + } + if (NULL != gData.gnssInterface) { + // either adds new Client or updates existing Client + gData.gnssInterface->addClient(this, locationCallbacks); + } + } + + if (isBatchingClient(locationCallbacks)) { + if (NULL == gData.batchingInterface && !gBatchingLoadFailed) { + gData.batchingInterface = + (BatchingInterface*)loadLocationInterface("libbatching.so", "getBatchingInterface"); + if (NULL == gData.batchingInterface) { + gBatchingLoadFailed = true; + LOC_LOGW("%s:%d]: No batching interface available", __func__, __LINE__); + } else { + gData.batchingInterface->initialize(); + } + } + if (NULL != gData.batchingInterface) { + // either adds new Client or updates existing Client + gData.batchingInterface->addClient(this, locationCallbacks); + } + } + + if (isGeofenceClient(locationCallbacks)) { + if (NULL == gData.geofenceInterface && !gGeofenceLoadFailed) { + gData.geofenceInterface = + (GeofenceInterface*)loadLocationInterface("libgeofencing.so", "getGeofenceInterface"); + if (NULL == gData.geofenceInterface) { + gGeofenceLoadFailed = true; + LOC_LOGW("%s:%d]: No geofence interface available", __func__, __LINE__); + } else { + gData.geofenceInterface->initialize(); + } + } + if (NULL != gData.geofenceInterface) { + // either adds new Client or updates existing Client + gData.geofenceInterface->addClient(this, locationCallbacks); + } + } + + gData.clientData[this] = locationCallbacks; + + pthread_mutex_unlock(&gDataMutex); +} + +uint32_t +LocationAPI::startTracking(TrackingOptions& trackingOptions) +{ + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + auto it = gData.clientData.find(this); + if (it != gData.clientData.end()) { + if (NULL != gData.gnssInterface) { + id = gData.gnssInterface->startTracking(this, trackingOptions); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location API client %p ", + __func__, __LINE__, this); + } + } else { + LOC_LOGE("%s:%d]: Location API client %p not found in client data", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +void +LocationAPI::stopTracking(uint32_t id) +{ + pthread_mutex_lock(&gDataMutex); + + auto it = gData.clientData.find(this); + if (it != gData.clientData.end()) { + if (gData.gnssInterface != NULL) { + gData.gnssInterface->stopTracking(this, id); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location API client %p ", + __func__, __LINE__, this); + } + } else { + LOC_LOGE("%s:%d]: Location API client %p not found in client data", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::updateTrackingOptions( + uint32_t id, TrackingOptions& trackingOptions) +{ + pthread_mutex_lock(&gDataMutex); + + auto it = gData.clientData.find(this); + if (it != gData.clientData.end()) { + if (gData.gnssInterface != NULL) { + gData.gnssInterface->updateTrackingOptions(this, id, trackingOptions); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location API client %p ", + __func__, __LINE__, this); + } + } else { + LOC_LOGE("%s:%d]: Location API client %p not found in client data", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +uint32_t +LocationAPI::startBatching(BatchingOptions &batchingOptions) +{ + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (NULL != gData.batchingInterface) { + id = gData.batchingInterface->startBatching(this, batchingOptions); + } else { + LOC_LOGE("%s:%d]: No batching interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +void +LocationAPI::stopBatching(uint32_t id) +{ + pthread_mutex_lock(&gDataMutex); + + if (NULL != gData.batchingInterface) { + gData.batchingInterface->stopBatching(this, id); + } else { + LOC_LOGE("%s:%d]: No batching interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::updateBatchingOptions(uint32_t id, BatchingOptions& batchOptions) +{ + pthread_mutex_lock(&gDataMutex); + + if (NULL != gData.batchingInterface) { + gData.batchingInterface->updateBatchingOptions(this, id, batchOptions); + } else { + LOC_LOGE("%s:%d]: No batching interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::getBatchedLocations(uint32_t id, size_t count) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.batchingInterface != NULL) { + gData.batchingInterface->getBatchedLocations(this, id, count); + } else { + LOC_LOGE("%s:%d]: No batching interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +uint32_t* +LocationAPI::addGeofences(size_t count, GeofenceOption* options, GeofenceInfo* info) +{ + uint32_t* ids = NULL; + pthread_mutex_lock(&gDataMutex); + + if (gData.geofenceInterface != NULL) { + ids = gData.geofenceInterface->addGeofences(this, count, options, info); + } else { + LOC_LOGE("%s:%d]: No geofence interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return ids; +} + +void +LocationAPI::removeGeofences(size_t count, uint32_t* ids) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.geofenceInterface != NULL) { + gData.geofenceInterface->removeGeofences(this, count, ids); + } else { + LOC_LOGE("%s:%d]: No geofence interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::modifyGeofences(size_t count, uint32_t* ids, GeofenceOption* options) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.geofenceInterface != NULL) { + gData.geofenceInterface->modifyGeofences(this, count, ids, options); + } else { + LOC_LOGE("%s:%d]: No geofence interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::pauseGeofences(size_t count, uint32_t* ids) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.geofenceInterface != NULL) { + gData.geofenceInterface->pauseGeofences(this, count, ids); + } else { + LOC_LOGE("%s:%d]: No geofence interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::resumeGeofences(size_t count, uint32_t* ids) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.geofenceInterface != NULL) { + gData.geofenceInterface->resumeGeofences(this, count, ids); + } else { + LOC_LOGE("%s:%d]: No geofence interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void +LocationAPI::gnssNiResponse(uint32_t id, GnssNiResponse response) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + gData.gnssInterface->gnssNiResponse(this, id, response); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +void LocationAPI::enableNetworkProvider() { + void* libHandle = nullptr; + enableProviderGetter* setter = (enableProviderGetter*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "enableNetworkProvider"); + if (setter != nullptr) { + (*setter)(); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +void LocationAPI::disableNetworkProvider() { + void* libHandle = nullptr; + disableProviderGetter* setter = (disableProviderGetter*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "disableNetworkProvider"); + if (setter != nullptr) { + (*setter)(); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +void LocationAPI::startNetworkLocation(trackingCallback* callback) { + void* libHandle = nullptr; + getSingleNetworkLocationGetter* setter = + (getSingleNetworkLocationGetter*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "startNetworkLocation"); + if (setter != nullptr) { + (*setter)(callback); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +void LocationAPI::stopNetworkLocation(trackingCallback* callback) { + void* libHandle = nullptr; + stopNetworkLocationGetter* setter = (stopNetworkLocationGetter*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "stopNetworkLocation"); + if (setter != nullptr) { + LOC_LOGe("called"); + (*setter)(callback); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } +} + +LocationControlAPI* +LocationControlAPI::createInstance(LocationControlCallbacks& locationControlCallbacks) +{ + LocationControlAPI* controlAPI = NULL; + pthread_mutex_lock(&gDataMutex); + + if (nullptr != locationControlCallbacks.responseCb && NULL == gData.controlAPI) { + if (NULL == gData.gnssInterface && !gGnssLoadFailed) { + gData.gnssInterface = + (GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface"); + if (NULL == gData.gnssInterface) { + gGnssLoadFailed = true; + LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__); + } else { + gData.gnssInterface->initialize(); + } + } + if (NULL != gData.gnssInterface) { + gData.controlAPI = new LocationControlAPI(); + gData.controlCallbacks = locationControlCallbacks; + gData.gnssInterface->setControlCallbacks(locationControlCallbacks); + controlAPI = gData.controlAPI; + } + } + + pthread_mutex_unlock(&gDataMutex); + return controlAPI; +} + +void +LocationControlAPI::destroy() +{ + delete this; +} + +LocationControlAPI::LocationControlAPI() +{ + LOC_LOGD("LOCATION CONTROL API CONSTRUCTOR"); +} + +LocationControlAPI::~LocationControlAPI() +{ + LOC_LOGD("LOCATION CONTROL API DESTRUCTOR"); + pthread_mutex_lock(&gDataMutex); + + gData.controlAPI = NULL; + + pthread_mutex_unlock(&gDataMutex); +} + +uint32_t +LocationControlAPI::enable(LocationTechnologyType techType) +{ + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->enable(techType); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location Control API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +void +LocationControlAPI::disable(uint32_t id) +{ + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + gData.gnssInterface->disable(id); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location Control API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); +} + +uint32_t* +LocationControlAPI::gnssUpdateConfig(const GnssConfig& config) +{ + uint32_t* ids = NULL; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + ids = gData.gnssInterface->gnssUpdateConfig(config); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location Control API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return ids; +} + +uint32_t* LocationControlAPI::gnssGetConfig(GnssConfigFlagsMask mask) { + + uint32_t* ids = NULL; + pthread_mutex_lock(&gDataMutex); + + if (NULL != gData.gnssInterface) { + ids = gData.gnssInterface->gnssGetConfig(mask); + } else { + LOC_LOGe("No gnss interface available for Control API client %p", this); + } + + pthread_mutex_unlock(&gDataMutex); + return ids; +} + +uint32_t +LocationControlAPI::gnssDeleteAidingData(GnssAidingData& data) +{ + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->gnssDeleteAidingData(data); + } else { + LOC_LOGE("%s:%d]: No gnss interface available for Location Control API client %p ", + __func__, __LINE__, this); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configConstellations( + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->gnssUpdateSvConfig( + constellationEnablementConfig, blacklistSvConfig); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configConstellationSecondaryBand( + const GnssSvTypeConfig& secondaryBandConfig) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->gnssUpdateSecondaryBandConfig(secondaryBandConfig); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configConstrainedTimeUncertainty( + bool enable, float tuncThreshold, uint32_t energyBudget) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->setConstrainedTunc(enable, + tuncThreshold, + energyBudget); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configPositionAssistedClockEstimator(bool enable) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->setPositionAssistedClockEstimator(enable); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configLeverArm(const LeverArmConfigInfo& configInfo) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configLeverArm(configInfo); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configRobustLocation(bool enable, bool enableForE911) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configRobustLocation(enable, enableForE911); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configMinGpsWeek(uint16_t minGpsWeek) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configMinGpsWeek(minGpsWeek); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configDeadReckoningEngineParams( + const DeadReckoningEngineConfig& dreConfig) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configDeadReckoningEngineParams(dreConfig); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::configEngineRunState( + PositioningEngineMask engType, LocEngineRunState engState) { + uint32_t id = 0; + pthread_mutex_lock(&gDataMutex); + + if (gData.gnssInterface != NULL) { + id = gData.gnssInterface->configEngineRunState(engType, engState); + } else { + LOC_LOGe("No gnss interface available for Location Control API"); + } + + pthread_mutex_unlock(&gDataMutex); + return id; +} + +uint32_t LocationControlAPI::setOptInStatus(bool userConsent) { + void* libHandle = nullptr; + uint32_t sessionId = 0; + setOptInStatusGetter* setter = (setOptInStatusGetter*)dlGetSymFromLib(libHandle, + "liblocationservice_glue.so", "setOptInStatus"); + if (setter != nullptr) { + sessionId = (*setter)(userConsent, &gData.controlCallbacks.responseCb); + } else { + LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so"); + } + return sessionId; +} diff --git a/gps/location/LocationAPI.h b/gps/location/LocationAPI.h new file mode 100644 index 0000000..7c70506 --- /dev/null +++ b/gps/location/LocationAPI.h @@ -0,0 +1,512 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOCATIONAPI_H +#define LOCATIONAPI_H + +#include "ILocationAPI.h" + +class LocationAPI : public ILocationAPI +{ +private: + LocationAPI(); + ~LocationAPI(); + +public: + /* creates an instance to LocationAPI object. + Will return NULL if mandatory parameters are invalid or if the maximum number + of instances have been reached */ + static LocationAPI* createInstance(LocationCallbacks&); + + /* destroy/cleans up the instance, which should be called when LocationControlAPI object is + no longer needed. LocationControlAPI* returned from createInstance will no longer valid + after destroy is called. + If the caller allocates the memory for LocationControlCallbacks used in + LocationControlAPI::createInstance, then the caller must ensure that the memory still remains + valid until destroyCompleteCb is invoked. + */ + void destroy(locationApiDestroyCompleteCallback destroyCompleteCb=nullptr); + + void onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType); + + /* updates/changes the callbacks that will be called. + mandatory callbacks must be present for callbacks to be successfully updated + no return value */ + virtual void updateCallbacks(LocationCallbacks&) override; + + /* ================================== TRACKING ================================== */ + + /* startTracking starts a tracking session, which returns a session id that will be + used by the other tracking APIs and also in the responseCallback to match command + with response. locations are reported on the trackingCallback passed in createInstance + periodically according to LocationOptions. + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successfully started + LOCATION_ERROR_ALREADY_STARTED if a startTracking session is already in progress + LOCATION_ERROR_CALLBACK_MISSING if no trackingCallback was passed in createInstance + LOCATION_ERROR_INVALID_PARAMETER if TrackingOptions parameter is invalid */ + virtual uint32_t startTracking(TrackingOptions&) override; + + /* stopTracking stops a tracking session associated with id parameter. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a tracking session */ + virtual void stopTracking(uint32_t id) override; + + /* updateTrackingOptions changes the TrackingOptions of a tracking session associated with id + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if TrackingOptions parameters are invalid + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a tracking session */ + virtual void updateTrackingOptions(uint32_t id, TrackingOptions&) override; + + /* ================================== BATCHING ================================== */ + + /* startBatching starts a batching session, which returns a session id that will be + used by the other batching APIs and also in the responseCallback to match command + with response. locations are reported on the batchingCallback passed in createInstance + periodically according to LocationOptions. A batching session starts tracking on + the low power processor and delivers them in batches by the batchingCallback when + the batch is full or when getBatchedLocations is called. This allows for the processor + that calls this API to sleep when the low power processor can batch locations in the + backgroup and wake up the processor calling the API only when the batch is full, thus + saving power + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_ALREADY_STARTED if a startBatching session is already in progress + LOCATION_ERROR_CALLBACK_MISSING if no batchingCallback was passed in createInstance + LOCATION_ERROR_INVALID_PARAMETER if a parameter is invalid + LOCATION_ERROR_NOT_SUPPORTED if batching is not supported */ + virtual uint32_t startBatching(BatchingOptions&) override; + + /* stopBatching stops a batching session associated with id parameter. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with batching session */ + virtual void stopBatching(uint32_t id) override; + + /* updateBatchingOptions changes the BatchingOptions of a batching session associated with id + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if BatchingOptions parameters are invalid + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a batching session */ + virtual void updateBatchingOptions(uint32_t id, BatchingOptions&) override; + + /* getBatchedLocations gets a number of locations that are currently stored/batched + on the low power processor, delivered by the batchingCallback passed in createInstance. + Location are then deleted from the batch stored on the low power processor. + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful, will be followed by batchingCallback call + LOCATION_ERROR_CALLBACK_MISSING if no batchingCallback was passed in createInstance + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a batching session */ + virtual void getBatchedLocations(uint32_t id, size_t count) override; + + /* ================================== GEOFENCE ================================== */ + + /* addGeofences adds any number of geofences and returns an array of geofence ids that + will be used by the other geofence APIs and also in the collectiveResponseCallback to + match command with response. The geofenceBreachCallback will deliver the status of each + geofence according to the GeofenceOption for each. The geofence id array returned will + be valid until the collectiveResponseCallback is called and has returned. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_CALLBACK_MISSING if no geofenceBreachCallback + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + LOCATION_ERROR_NOT_SUPPORTED if geofence is not supported */ + virtual uint32_t* addGeofences(size_t count, GeofenceOption*, GeofenceInfo*) override; + + /* removeGeofences removes any number of geofences. Caller should delete ids array after + removeGeofences returneds. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void removeGeofences(size_t count, uint32_t* ids) override; + + /* modifyGeofences modifies any number of geofences. Caller should delete ids array after + modifyGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid */ + virtual void modifyGeofences(size_t count, uint32_t* ids, GeofenceOption* options) override; + + /* pauseGeofences pauses any number of geofences, which is similar to removeGeofences, + only that they can be resumed at any time. Caller should delete ids array after + pauseGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void pauseGeofences(size_t count, uint32_t* ids) override; + + /* resumeGeofences resumes any number of geofences that are currently paused. Caller should + delete ids array after resumeGeofences returns. + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id is not associated with a geofence session */ + virtual void resumeGeofences(size_t count, uint32_t* ids) override; + + /* ================================== GNSS ====================================== */ + + /* gnssNiResponse is called in response to a gnssNiCallback. + responseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters in GnssNiResponse are invalid + LOCATION_ERROR_ID_UNKNOWN if id does not match a gnssNiCallback */ + virtual void gnssNiResponse(uint32_t id, GnssNiResponse response) override; + + /* ================================== NETWORK PROVIDER =========================== */ + + /* enableNetworkProvider enables Network Provider */ + virtual void enableNetworkProvider(); + + /* disableNetworkProvider disables Network Provider */ + virtual void disableNetworkProvider(); + + /* startNetworkLocation start a single shot network location request */ + virtual void startNetworkLocation(trackingCallback* callback); + + /* stopNetworkLocation stop any ongoing network location request */ + virtual void stopNetworkLocation(trackingCallback* callback); +}; + +typedef struct { + size_t size; // set to sizeof(LocationControlCallbacks) + responseCallback responseCb; // mandatory + collectiveResponseCallback collectiveResponseCb; // mandatory + gnssConfigCallback gnssConfigCb; // optional +} LocationControlCallbacks; + +class LocationControlAPI : public ILocationControlAPI +{ +private: + LocationControlAPI(); + ~LocationControlAPI(); + +public: + /* creates an instance to LocationControlAPI object. + Will return NULL if mandatory parameters are invalid or if the maximum number + of instances have been reached. Only once instance allowed */ + static LocationControlAPI* createInstance(LocationControlCallbacks&); + + /* destroy/cleans up the instance, which should be called when LocationControlAPI object is + no longer needed. LocationControlAPI* returned from createInstance will no longer valid + after destroy is called */ + void destroy(); + + /* enable will enable specific location technology to be used for calculation locations and + will effectively start a control session if call is successful, which returns a session id + that will be returned in responseCallback to match command with response. The session id is + also needed to call the disable command. + This effect is global for all clients of LocationAPI + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ALREADY_STARTED if an enable was already called for this techType + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + LOCATION_ERROR_GENERAL_FAILURE if failure for any other reason */ + uint32_t enable(LocationTechnologyType techType); + + /* disable will disable specific location technology to be used for calculation locations and + effectively ends the control session if call is successful. + id parameter is the session id that was returned in enable responseCallback for techType. + The session id is no longer valid after disable's responseCallback returns success. + This effect is global for all clients of LocationAPI + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_ID_UNKNOWN if id was not returned from responseCallback from enable + LOCATION_ERROR_GENERAL_FAILURE if failure for any other reason */ + void disable(uint32_t id); + + /* gnssUpdateConfig updates the gnss specific configuration, which returns a session id array + with an id for each of the bits set in GnssConfig.flags, order from low bits to high bits. + The response for each config that is set will be returned in collectiveResponseCallback. + The session id array returned will be valid until the collectiveResponseCallback is called + and has returned. This effect is global for all clients of LocationAPI + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_INVALID_PARAMETER if any other parameters are invalid + LOCATION_ERROR_GENERAL_FAILURE if failure for any other reason + + PLEASE NOTE: It is caller's resposibility to FREE the memory of the return value. + The memory must be freed by delete [].*/ + virtual uint32_t* gnssUpdateConfig(const GnssConfig& config) override; + + /* gnssGetConfig fetches the current constellation and SV configuration + on the GNSS engine. + Returns a session id array with an id for each of the bits set in + the mask parameter, order from low bits to high bits. + Response is sent via the registered gnssConfigCallback. + This effect is global for all clients of LocationAPI + collectiveResponseCallback returns: + LOCATION_ERROR_SUCCESS if session was successful + LOCATION_ERROR_INVALID_PARAMETER if any parameter is invalid + LOCATION_ERROR_CALLBACK_MISSING If no gnssConfigCallback + was passed in createInstance + LOCATION_ERROR_NOT_SUPPORTED If read of requested configuration + is not supported + + PLEASE NOTE: It is caller's resposibility to FREE the memory of the return value. + The memory must be freed by delete [].*/ + uint32_t* gnssGetConfig(GnssConfigFlagsMask mask); + + /* delete specific gnss aiding data for testing, which returns a session id + that will be returned in responseCallback to match command with response. + Only allowed in userdebug builds. This effect is global for all clients of LocationAPI + responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + LOCATION_ERROR_NOT_SUPPORTED if build is not userdebug */ + virtual uint32_t gnssDeleteAidingData(GnssAidingData& data) override; + + /** @brief + Configure the constellation and SVs to be used by the GNSS engine on + modem. + + @param + constellationEnablementConfig: configuration to enable/disable SV + constellation to be used by SPE engine. When size in + constellationEnablementConfig is set to 0, this indicates to reset SV + constellation configuration to modem NV default. + + blacklistSvConfig: configuration to blacklist or unblacklist SVs + used by SPE engine + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellations( + const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig) override; + + /** @brief + Configure the secondary band of constellations to be used by + the GNSS engine on modem. + + @param + secondaryBandConfig: configuration the secondary band usage + for SPE engine + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configConstellationSecondaryBand( + const GnssSvTypeConfig& secondaryBandConfig) override; + + /** @brief + Enable or disable the constrained time uncertainty feature. + + @param + enable: true to enable the constrained time uncertainty + feature and false to disable the constrainted time + uncertainty feature. + + @param + tuncThreshold: this specifies the time uncertainty threshold + that gps engine need to maintain, in units of milli-seconds. + Default is 0.0 meaning that modem default value of time + uncertainty threshold will be used. This parameter is + ignored when requesting to disable this feature. + + @param + energyBudget: this specifies the power budget that gps + engine is allowed to spend to maintain the time uncertainty. + Default is 0 meaning that GPS engine is not constained by + power budget and can spend as much power as needed. The + parameter need to be specified in units of 0.1 milli watt + second. This parameter is ignored requesting to disable this + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters + are invalid + */ + virtual uint32_t configConstrainedTimeUncertainty( + bool enable, float tuncThreshold = 0.0, + uint32_t energyBudget = 0) override; + + /** @brief + Enable or disable position assisted clock estimator feature. + + @param + enable: true to enable position assisted clock estimator and + false to disable the position assisted clock estimator + feature. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configPositionAssistedClockEstimator(bool enable) override; + + /** @brief + Sets the lever arm parameters for the vehicle. + + @param + configInfo: lever arm configuration info regarding below two + types of lever arm info: + a: GNSS Antenna w.r.t the origin at the IMU e.g.: inertial + measurement unit. + b: lever arm parameters regarding the OPF (output frame) + w.r.t the origin (at the GPS Antenna). Vehicle manufacturers + prefer the position output to be tied to a specific point in + the vehicle rather than where the antenna is placed + (midpoint of the rear axle is typical). + + Caller can choose types of lever arm info to configure via the + leverMarkTypeMask. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configLeverArm(const LeverArmConfigInfo& configInfo) override; + + /** @brief + Configure the robust location setting. + + @param + enable: true to enable robust location and false to disable + robust location. + + @param + enableForE911: true to enable robust location when device is + on E911 session and false to disable on E911 session. + This parameter is only valid if robust location is enabled. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configRobustLocation(bool enable, bool enableForE911) override; + + /** @brief + Config the minimal GPS week used by modem GNSS engine. + + @param + minGpsWeek: minimal GPS week to be used by modem GNSS engine. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configMinGpsWeek(uint16_t minGpsWeek) override; + + /** @brief + Configure the vehicle body-to-Sensor mount parameters and + other parameters for dead reckoning position engine. + + @param + dreConfig: vehicle body-to-Sensor mount angles and other + parameters. + + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configDeadReckoningEngineParams( + const DeadReckoningEngineConfig& dreConfig) override; + + /** @brief + This API is used to instruct the specified engine to be in + the pause/resume state.
+ + When the engine is placed in paused state, the engine will + stop. If there is an on-going session, engine will no longer + produce fixes. In the paused state, calling API to delete + aiding data from the paused engine may not have effect. + Request to delete Aiding data shall be issued after + engine resume.
+ + Currently, only DRE engine will support pause/resume + request. responseCb() will return not supported when request + is made to pause/resume none-DRE engine.
+ + Request to pause/resume DRE engine can be made with or + without an on-going session. With QDR engine, on resume, GNSS + position & heading re-acquisition is needed for DR engine to + engage. If DR engine is already in the requested state, the + request will be no-op.
+ + @param + engType: the engine that is instructed to change its run + state.
+ + engState: the new engine run state that the engine is + instructed to be in.
+ + @return + A session id that will be returned in responseCallback to + match command with response. This effect is global for all + clients of LocationAPI responseCallback returns: + LOCATION_ERROR_SUCCESS if successful + LOCATION_ERROR_INVALID_PARAMETER if any parameters are invalid + */ + virtual uint32_t configEngineRunState(PositioningEngineMask engType, + LocEngineRunState engState) override; + + /** @brief + Set the EULA opt-in status from system user. This is used as consent to + use network-based positioning. + + @param + userConsnt: user agrees to use GTP service or not. + + @return + A session id that will be returned in responseCallback to + match command with response. + */ + virtual uint32_t setOptInStatus(bool userConsent); +}; + +#endif /* LOCATIONAPI_H */ diff --git a/gps/location/LocationAPIClientBase.cpp b/gps/location/LocationAPIClientBase.cpp new file mode 100644 index 0000000..4865a16 --- /dev/null +++ b/gps/location/LocationAPIClientBase.cpp @@ -0,0 +1,977 @@ +/* Copyright (c) 2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_APIClientBase" + +#include +#include +#include +#include +#include "LocationAPIClientBase.h" + +#define GEOFENCE_SESSION_ID 0xFFFFFFFF +#define CONFIG_SESSION_ID 0xFFFFFFFF + +// LocationAPIControlClient +LocationAPIControlClient::LocationAPIControlClient() : + mEnabled(false) +{ + pthread_mutex_init(&mMutex, nullptr); + + for (int i = 0; i < CTRL_REQUEST_MAX; i++) { + mRequestQueues[i].reset((uint32_t)0); + } + + memset(&mConfig, 0, sizeof(GnssConfig)); + + LocationControlCallbacks locationControlCallbacks; + locationControlCallbacks.size = sizeof(LocationControlCallbacks); + + locationControlCallbacks.responseCb = + [this](LocationError error, uint32_t id) { + onCtrlResponseCb(error, id); + }; + locationControlCallbacks.collectiveResponseCb = + [this](size_t count, LocationError* errors, uint32_t* ids) { + onCtrlCollectiveResponseCb(count, errors, ids); + }; + + mLocationControlAPI = LocationControlAPI::createInstance(locationControlCallbacks); +} + +LocationAPIControlClient::~LocationAPIControlClient() +{ + pthread_mutex_lock(&mMutex); + + if (mLocationControlAPI) { + mLocationControlAPI->destroy(); + mLocationControlAPI = nullptr; + } + + for (int i = 0; i < CTRL_REQUEST_MAX; i++) { + mRequestQueues[i].reset((uint32_t)0); + } + + pthread_mutex_unlock(&mMutex); + + pthread_mutex_destroy(&mMutex); +} + +uint32_t LocationAPIControlClient::locAPIGnssDeleteAidingData(GnssAidingData& data) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationControlAPI) { + uint32_t session = mLocationControlAPI->gnssDeleteAidingData(data); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); + mRequestQueues[CTRL_REQUEST_DELETEAIDINGDATA].reset(session); + mRequestQueues[CTRL_REQUEST_DELETEAIDINGDATA].push(new GnssDeleteAidingDataRequest(*this)); + + retVal = LOCATION_ERROR_SUCCESS; + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +uint32_t LocationAPIControlClient::locAPIEnable(LocationTechnologyType techType) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mEnabled) { + // just return success if already enabled + retVal = LOCATION_ERROR_SUCCESS; + } else if (mLocationControlAPI) { + uint32_t session = mLocationControlAPI->enable(techType); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); + mRequestQueues[CTRL_REQUEST_CONTROL].reset(session); + mRequestQueues[CTRL_REQUEST_CONTROL].push(new EnableRequest(*this)); + retVal = LOCATION_ERROR_SUCCESS; + mEnabled = true; + } else { + LOC_LOGE("%s:%d] failed.", __FUNCTION__, __LINE__); + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +void LocationAPIControlClient::locAPIDisable() +{ + pthread_mutex_lock(&mMutex); + if (mEnabled && mLocationControlAPI) { + uint32_t session = 0; + session = mRequestQueues[CTRL_REQUEST_CONTROL].getSession(); + if (session > 0) { + mRequestQueues[CTRL_REQUEST_CONTROL].push(new DisableRequest(*this)); + mLocationControlAPI->disable(session); + mEnabled = false; + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session); + } + } + pthread_mutex_unlock(&mMutex); +} + +uint32_t LocationAPIControlClient::locAPIGnssUpdateConfig(GnssConfig config) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + + pthread_mutex_lock(&mMutex); + if (mLocationControlAPI) { + if (mConfig.equals(config)) { + LOC_LOGv("GnssConfig is identical to previous call"); + retVal = LOCATION_ERROR_SUCCESS; + } else { + mConfig = config; + uint32_t* idArray = mLocationControlAPI->gnssUpdateConfig(config); + LOC_LOGv("gnssUpdateConfig return array: %p", idArray); + if (nullptr != idArray) { + if (nullptr != mRequestQueues[CTRL_REQUEST_CONFIG_UPDATE].getSessionArrayPtr()) { + mRequestQueues[CTRL_REQUEST_CONFIG_UPDATE].reset(idArray); + } + mRequestQueues[CTRL_REQUEST_CONFIG_UPDATE].push(new GnssUpdateConfigRequest(*this)); + retVal = LOCATION_ERROR_SUCCESS; + delete [] idArray; + } + } + } + pthread_mutex_unlock(&mMutex); + return retVal; +} + +uint32_t LocationAPIControlClient::locAPIGnssGetConfig(GnssConfigFlagsMask mask) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + + pthread_mutex_lock(&mMutex); + if (mLocationControlAPI) { + + uint32_t* idArray = mLocationControlAPI->gnssGetConfig(mask); + LOC_LOGv("gnssGetConfig return array: %p", idArray); + if (nullptr != idArray) { + if (nullptr != mRequestQueues[CTRL_REQUEST_CONFIG_GET].getSessionArrayPtr()) { + mRequestQueues[CTRL_REQUEST_CONFIG_GET].reset(idArray); + } + mRequestQueues[CTRL_REQUEST_CONFIG_GET].push(new GnssGetConfigRequest(*this)); + retVal = LOCATION_ERROR_SUCCESS; + delete [] idArray; + } + } + pthread_mutex_unlock(&mMutex); + return retVal; +} + +void LocationAPIControlClient::onCtrlResponseCb(LocationError error, uint32_t id) +{ + if (error != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s:%d] ERROR: %d ID: %d", __FUNCTION__, __LINE__, error, id); + } else { + LOC_LOGV("%s:%d] SUCCESS: %d id: %d", __FUNCTION__, __LINE__, error, id); + } + LocationAPIRequest* request = getRequestBySession(id); + if (request) { + request->onResponse(error, id); + delete request; + } +} + +void LocationAPIControlClient::onCtrlCollectiveResponseCb( + size_t count, LocationError* errors, uint32_t* ids) +{ + for (size_t i = 0; i < count; i++) { + if (errors[i] != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s:%d] ERROR: %d ID: %d", __FUNCTION__, __LINE__, errors[i], ids[i]); + } else { + LOC_LOGV("%s:%d] SUCCESS: %d id: %d", __FUNCTION__, __LINE__, errors[i], ids[i]); + } + } + LocationAPIRequest* request = getRequestBySessionArrayPtr(ids); + if (request) { + request->onCollectiveResponse(count, errors, ids); + delete request; + } +} + +LocationAPIRequest* LocationAPIControlClient::getRequestBySession(uint32_t session) +{ + pthread_mutex_lock(&mMutex); + LocationAPIRequest* request = nullptr; + + if (mRequestQueues[CTRL_REQUEST_DELETEAIDINGDATA].getSession() == session) { + request = mRequestQueues[CTRL_REQUEST_DELETEAIDINGDATA].pop(); + } else if (mRequestQueues[CTRL_REQUEST_CONTROL].getSession() == session) { + request = mRequestQueues[CTRL_REQUEST_CONTROL].pop(); + } + + pthread_mutex_unlock(&mMutex); + return request; +} + +LocationAPIRequest* +LocationAPIControlClient::getRequestBySessionArrayPtr( + uint32_t* sessionArrayPtr) +{ + pthread_mutex_lock(&mMutex); + LocationAPIRequest* request = nullptr; + + if (mRequestQueues[CTRL_REQUEST_CONFIG_UPDATE].getSessionArrayPtr() == sessionArrayPtr) { + request = mRequestQueues[CTRL_REQUEST_CONFIG_UPDATE].pop(); + } else if (mRequestQueues[CTRL_REQUEST_CONFIG_GET].getSessionArrayPtr() == sessionArrayPtr) { + request = mRequestQueues[CTRL_REQUEST_CONFIG_GET].pop(); + } + + pthread_mutex_unlock(&mMutex); + return request; +} + +// LocationAPIClientBase +LocationAPIClientBase::LocationAPIClientBase() : + mGeofenceBreachCallback(nullptr), + mBatchingStatusCallback(nullptr), + mLocationAPI(nullptr), + mBatchSize(-1), + mTracking(false) +{ + + // use recursive mutex, in case callback come from the same thread + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&mMutex, &attr); + + for (int i = 0; i < REQUEST_MAX; i++) { + mRequestQueues[i].reset((uint32_t)0); + } +} + +void LocationAPIClientBase::locAPISetCallbacks(LocationCallbacks& locationCallbacks) +{ + pthread_mutex_lock(&mMutex); + + if (locationCallbacks.geofenceBreachCb != nullptr) { + mGeofenceBreachCallback = locationCallbacks.geofenceBreachCb; + locationCallbacks.geofenceBreachCb = + [this](GeofenceBreachNotification geofenceBreachNotification) { + beforeGeofenceBreachCb(geofenceBreachNotification); + }; + } + + locationCallbacks.capabilitiesCb = + [this](LocationCapabilitiesMask capabilitiesMask) { + onCapabilitiesCb(capabilitiesMask); + }; + locationCallbacks.responseCb = [this](LocationError error, uint32_t id) { + onResponseCb(error, id); + }; + locationCallbacks.collectiveResponseCb = + [this](size_t count, LocationError* errors, uint32_t* ids) { + onCollectiveResponseCb(count, errors, ids); + }; + + if (locationCallbacks.batchingStatusCb != nullptr) { + mBatchingStatusCallback = locationCallbacks.batchingStatusCb; + locationCallbacks.batchingStatusCb = + [this](BatchingStatusInfo batchStatus, std::list & tripCompletedList) { + beforeBatchingStatusCb(batchStatus, tripCompletedList); + }; + } + + if (mLocationAPI == nullptr ) { + mLocationAPI = LocationAPI::createInstance(locationCallbacks); + } else { + mLocationAPI->updateCallbacks(locationCallbacks); + } + + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::destroy() +{ + LOC_LOGD("LocationAPIClientBase::destroy()"); + + pthread_mutex_lock(&mMutex); + + mGeofenceBreachCallback = nullptr; + + for (int i = 0; i < REQUEST_MAX; i++) { + mRequestQueues[i].reset((uint32_t)0); + } + + LocationAPI* localHandle = nullptr; + if (nullptr != mLocationAPI) { + localHandle = mLocationAPI; + mLocationAPI = nullptr; + } + + pthread_mutex_unlock(&mMutex); + + // Invoking destroy has the possibility of destroy complete callback + // being invoked right away in the same context, hence no instance + // member must be accessed after the destroy call. + if (nullptr != localHandle) { + localHandle->destroy([this]() {onLocationApiDestroyCompleteCb();}); + } +} + +LocationAPIClientBase::~LocationAPIClientBase() +{ + pthread_mutex_destroy(&mMutex); +} + +void LocationAPIClientBase::onLocationApiDestroyCompleteCb() +{ + LOC_LOGD("LocationAPIClientBase::onLocationApiDestroyCompleteCb()"); + delete this; +} + +uint32_t LocationAPIClientBase::locAPIStartTracking(TrackingOptions& options) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + if (mTracking) { + LOC_LOGW("%s:%d] Existing tracking session present", __FUNCTION__, __LINE__); + } else { + uint32_t session = mLocationAPI->startTracking(options); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); + // onResponseCb might be called from other thread immediately after + // startTracking returns, so we are not going to unlock mutex + // until StartTrackingRequest is pushed into mRequestQueues[REQUEST_TRACKING] + mRequestQueues[REQUEST_TRACKING].reset(session); + mRequestQueues[REQUEST_TRACKING].push(new StartTrackingRequest(*this)); + mTracking = true; + } + + retVal = LOCATION_ERROR_SUCCESS; + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +void LocationAPIClientBase::locAPIStopTracking() +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t session = 0; + session = mRequestQueues[REQUEST_TRACKING].getSession(); + if (session > 0) { + mRequestQueues[REQUEST_TRACKING].push(new StopTrackingRequest(*this)); + mLocationAPI->stopTracking(session); + mTracking = false; + } else { + LOC_LOGD("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session); + } + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::locAPIUpdateTrackingOptions(TrackingOptions& options) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t session = 0; + session = mRequestQueues[REQUEST_TRACKING].getSession(); + if (session > 0) { + mRequestQueues[REQUEST_TRACKING].push(new UpdateTrackingOptionsRequest(*this)); + mLocationAPI->updateTrackingOptions(session, options); + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session); + } + } + pthread_mutex_unlock(&mMutex); +} + +int32_t LocationAPIClientBase::locAPIGetBatchSize() +{ + if (mBatchSize == -1) { + const loc_param_s_type flp_conf_param_table[] = + { + {"BATCH_SIZE", &mBatchSize, nullptr, 'n'}, + }; + UTIL_READ_CONF(LOC_PATH_FLP_CONF, flp_conf_param_table); + if (mBatchSize < 0) { + // set mBatchSize to 0 if we got an illegal value from config file + mBatchSize = 0; + } + } + return mBatchSize; +} + +uint32_t LocationAPIClientBase::locAPIStartSession( + uint32_t id, uint32_t sessionMode, TrackingOptions&& options) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + + if (mSessionBiDict.hasId(id)) { + LOC_LOGE("%s:%d] session %d has already started.", __FUNCTION__, __LINE__, id); + retVal = LOCATION_ERROR_ALREADY_STARTED; + } else { + uint32_t trackingSession = 0; + uint32_t batchingSession = 0; + + if (sessionMode == SESSION_MODE_ON_FIX) { + trackingSession = mLocationAPI->startTracking(options); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, trackingSession); + mRequestQueues[REQUEST_SESSION].push(new StartTrackingRequest(*this)); + } else { + // Fill in the batch mode + BatchingOptions batchOptions = {}; + batchOptions.size = sizeof(BatchingOptions); + switch (sessionMode) { + case SESSION_MODE_ON_FULL: + batchOptions.batchingMode = BATCHING_MODE_ROUTINE; + break; + case SESSION_MODE_ON_TRIP_COMPLETED: + batchOptions.batchingMode = BATCHING_MODE_TRIP; + break; + default: + batchOptions.batchingMode = BATCHING_MODE_NO_AUTO_REPORT; + break; + } + + // Populate location option values + batchOptions.minDistance = options.minDistance; + batchOptions.minInterval = options.minInterval; + batchOptions.mode = options.mode; + + batchingSession = mLocationAPI->startBatching(batchOptions); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, batchingSession); + mRequestQueues[REQUEST_SESSION].setSession(batchingSession); + mRequestQueues[REQUEST_SESSION].push(new StartBatchingRequest(*this)); + } + + uint32_t session = ((sessionMode != SESSION_MODE_ON_FIX) ? + batchingSession : trackingSession); + + SessionEntity entity; + entity.id = id; + entity.trackingSession = trackingSession; + entity.batchingSession = batchingSession; + entity.sessionMode = sessionMode; + mSessionBiDict.set(id, session, entity); + + retVal = LOCATION_ERROR_SUCCESS; + } + + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +uint32_t LocationAPIClientBase::locAPIStopSession(uint32_t id) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + + if (mSessionBiDict.hasId(id)) { + SessionEntity entity = mSessionBiDict.getExtById(id); + + uint32_t trackingSession = entity.trackingSession; + uint32_t batchingSession = entity.batchingSession; + uint32_t sMode = entity.sessionMode; + + if (sMode == SESSION_MODE_ON_FIX) { + mRequestQueues[REQUEST_SESSION].push(new StopTrackingRequest(*this)); + mLocationAPI->stopTracking(trackingSession); + } else { + mRequestQueues[REQUEST_SESSION].push(new StopBatchingRequest(*this)); + mLocationAPI->stopBatching(batchingSession); + } + + retVal = LOCATION_ERROR_SUCCESS; + } else { + retVal = LOCATION_ERROR_ID_UNKNOWN; + LOC_LOGE("%s:%d] session %d is not exist.", __FUNCTION__, __LINE__, id); + } + + } + pthread_mutex_unlock(&mMutex); + return retVal; +} + +uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions( + uint32_t id, uint32_t sessionMode, TrackingOptions&& options) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + + if (mSessionBiDict.hasId(id)) { + SessionEntity entity = mSessionBiDict.getExtById(id); + + uint32_t trackingSession = entity.trackingSession; + uint32_t batchingSession = entity.batchingSession; + uint32_t sMode = entity.sessionMode; + + if (sessionMode == SESSION_MODE_ON_FIX) { + // we only add an UpdateTrackingOptionsRequest to mRequestQueues[REQUEST_SESSION], + // even if this update request will stop batching and then start tracking. + mRequestQueues[REQUEST_SESSION].push(new UpdateTrackingOptionsRequest(*this)); + if (sMode == SESSION_MODE_ON_FIX) { + mLocationAPI->updateTrackingOptions(trackingSession, options); + } else { + // stop batching + // batchingSession will be removed from mSessionBiDict soon, + // so we don't need to add a new request to mRequestQueues[REQUEST_SESSION]. + mLocationAPI->stopBatching(batchingSession); + batchingSession = 0; + mRequestQueues[REQUEST_SESSION].setSession(batchingSession); + + // start tracking + trackingSession = mLocationAPI->startTracking(options); + LOC_LOGI("%s:%d] start new session: %d", + __FUNCTION__, __LINE__, trackingSession); + } + } else { + // we only add an UpdateBatchingOptionsRequest to mRequestQueues[REQUEST_SESSION], + // even if this update request will stop tracking and then start batching. + mRequestQueues[REQUEST_SESSION].push(new UpdateBatchingOptionsRequest(*this)); + BatchingOptions batchOptions = {}; + batchOptions.size = sizeof(BatchingOptions); + switch (sessionMode) { + case SESSION_MODE_ON_FULL: + batchOptions.batchingMode = BATCHING_MODE_ROUTINE; + break; + case SESSION_MODE_ON_TRIP_COMPLETED: + batchOptions.batchingMode = BATCHING_MODE_TRIP; + break; + default: + batchOptions.batchingMode = BATCHING_MODE_NO_AUTO_REPORT; + break; + } + + if (sMode == SESSION_MODE_ON_FIX) { + // stop tracking + // trackingSession will be removed from mSessionBiDict soon, + // so we don't need to add a new request to mRequestQueues[REQUEST_SESSION]. + mLocationAPI->stopTracking(trackingSession); + trackingSession = 0; + + // Populate location option values + batchOptions.minDistance = options.minDistance; + batchOptions.minInterval = options.minInterval; + batchOptions.mode = options.mode; + + // start batching + batchingSession = mLocationAPI->startBatching(batchOptions); + LOC_LOGI("%s:%d] start new session: %d", + __FUNCTION__, __LINE__, batchingSession); + mRequestQueues[REQUEST_SESSION].setSession(batchingSession); + } else { + mLocationAPI->updateBatchingOptions(batchingSession, batchOptions); + } + + } + + uint32_t session = ((sessionMode != SESSION_MODE_ON_FIX) ? + batchingSession : trackingSession); + + entity.trackingSession = trackingSession; + entity.batchingSession = batchingSession; + entity.sessionMode = sessionMode; + // remove the old values from mSessionBiDict before we add a new one. + mSessionBiDict.rmById(id); + mSessionBiDict.set(id, session, entity); + + retVal = LOCATION_ERROR_SUCCESS; + } else { + retVal = LOCATION_ERROR_ID_UNKNOWN; + LOC_LOGE("%s:%d] session %d is not exist.", __FUNCTION__, __LINE__, id); + } + } + pthread_mutex_unlock(&mMutex); + return retVal; +} + +uint32_t LocationAPIClientBase::locAPIGetBatchedLocations(uint32_t id, size_t count) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + if (mSessionBiDict.hasId(id)) { + SessionEntity entity = mSessionBiDict.getExtById(id); + if (entity.sessionMode != SESSION_MODE_ON_FIX) { + uint32_t batchingSession = entity.batchingSession; + mRequestQueues[REQUEST_SESSION].push(new GetBatchedLocationsRequest(*this)); + mLocationAPI->getBatchedLocations(batchingSession, count); + retVal = LOCATION_ERROR_SUCCESS; + } else { + LOC_LOGE("%s:%d] Unsupported for session id: %d, mode is SESSION_MODE_ON_FIX", + __FUNCTION__, __LINE__, id); + retVal = LOCATION_ERROR_NOT_SUPPORTED; + } + } else { + retVal = LOCATION_ERROR_ID_UNKNOWN; + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, id); + } + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +uint32_t LocationAPIClientBase::locAPIAddGeofences( + size_t count, uint32_t* ids, GeofenceOption* options, GeofenceInfo* data) +{ + uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE; + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + if (mRequestQueues[REQUEST_GEOFENCE].getSession() != GEOFENCE_SESSION_ID) { + mRequestQueues[REQUEST_GEOFENCE].reset(GEOFENCE_SESSION_ID); + } + uint32_t* sessions = mLocationAPI->addGeofences(count, options, data); + if (sessions) { + LOC_LOGI("%s:%d] start new sessions: %p", __FUNCTION__, __LINE__, sessions); + mRequestQueues[REQUEST_GEOFENCE].push(new AddGeofencesRequest(*this)); + + for (size_t i = 0; i < count; i++) { + mGeofenceBiDict.set(ids[i], sessions[i], options[i].breachTypeMask); + } + retVal = LOCATION_ERROR_SUCCESS; + } + } + pthread_mutex_unlock(&mMutex); + + return retVal; +} + +void LocationAPIClientBase::locAPIRemoveGeofences(size_t count, uint32_t* ids) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t* sessions = (uint32_t*)malloc(sizeof(uint32_t) * count); + if (sessions == NULL) { + LOC_LOGE("%s:%d] Failed to allocate %zu bytes !", + __FUNCTION__, __LINE__, sizeof(uint32_t) * count); + pthread_mutex_unlock(&mMutex); + return; + } + + if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) { + BiDict* removedGeofenceBiDict = + new BiDict(); + size_t j = 0; + for (size_t i = 0; i < count; i++) { + sessions[j] = mGeofenceBiDict.getSession(ids[i]); + if (sessions[j] > 0) { + GeofenceBreachTypeMask type = mGeofenceBiDict.getExtBySession(sessions[j]); + mGeofenceBiDict.rmBySession(sessions[j]); + removedGeofenceBiDict->set(ids[i], sessions[j], type); + j++; + } + } + if (j > 0) { + mRequestQueues[REQUEST_GEOFENCE].push(new RemoveGeofencesRequest(*this, + removedGeofenceBiDict)); + mLocationAPI->removeGeofences(j, sessions); + } else { + delete(removedGeofenceBiDict); + } + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, + mRequestQueues[REQUEST_GEOFENCE].getSession()); + } + + free(sessions); + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::locAPIModifyGeofences( + size_t count, uint32_t* ids, GeofenceOption* options) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t* sessions = (uint32_t*)malloc(sizeof(uint32_t) * count); + if (sessions == NULL) { + LOC_LOGE("%s:%d] Failed to allocate %zu bytes !", + __FUNCTION__, __LINE__, sizeof(uint32_t) * count); + pthread_mutex_unlock(&mMutex); + return; + } + + if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) { + size_t j = 0; + for (size_t i = 0; i < count; i++) { + sessions[j] = mGeofenceBiDict.getSession(ids[i]); + if (sessions[j] > 0) { + mGeofenceBiDict.set(ids[i], sessions[j], options[i].breachTypeMask); + j++; + } + } + if (j > 0) { + mRequestQueues[REQUEST_GEOFENCE].push(new ModifyGeofencesRequest(*this)); + mLocationAPI->modifyGeofences(j, sessions, options); + } + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, + mRequestQueues[REQUEST_GEOFENCE].getSession()); + } + + free(sessions); + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::locAPIPauseGeofences(size_t count, uint32_t* ids) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t* sessions = (uint32_t*)malloc(sizeof(uint32_t) * count); + if (sessions == NULL) { + LOC_LOGE("%s:%d] Failed to allocate %zu bytes !", + __FUNCTION__, __LINE__, sizeof(uint32_t) * count); + pthread_mutex_unlock(&mMutex); + return; + } + + if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) { + size_t j = 0; + for (size_t i = 0; i < count; i++) { + sessions[j] = mGeofenceBiDict.getSession(ids[i]); + if (sessions[j] > 0) { + j++; + } + } + if (j > 0) { + mRequestQueues[REQUEST_GEOFENCE].push(new PauseGeofencesRequest(*this)); + mLocationAPI->pauseGeofences(j, sessions); + } + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, + mRequestQueues[REQUEST_GEOFENCE].getSession()); + } + + free(sessions); + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::locAPIResumeGeofences( + size_t count, uint32_t* ids, GeofenceBreachTypeMask* mask) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t* sessions = (uint32_t*)malloc(sizeof(uint32_t) * count); + if (sessions == NULL) { + LOC_LOGE("%s:%d] Failed to allocate %zu bytes !", + __FUNCTION__, __LINE__, sizeof(uint32_t) * count); + pthread_mutex_unlock(&mMutex); + return; + } + + if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) { + size_t j = 0; + for (size_t i = 0; i < count; i++) { + sessions[j] = mGeofenceBiDict.getSession(ids[i]); + if (sessions[j] > 0) { + if (mask) { + mGeofenceBiDict.set(ids[i], sessions[j], mask[i]); + } + j++; + } + } + if (j > 0) { + mRequestQueues[REQUEST_GEOFENCE].push(new ResumeGeofencesRequest(*this)); + mLocationAPI->resumeGeofences(j, sessions); + } + } else { + LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, + mRequestQueues[REQUEST_GEOFENCE].getSession()); + } + + free(sessions); + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::locAPIRemoveAllGeofences() +{ + std::vector sessionsVec = mGeofenceBiDict.getAllSessions(); + if (sessionsVec.size() > 0) { + locAPIRemoveGeofences(sessionsVec.size(), &sessionsVec[0]); + } +} + +void LocationAPIClientBase::locAPIGnssNiResponse(uint32_t id, GnssNiResponse response) +{ + pthread_mutex_lock(&mMutex); + if (mLocationAPI) { + uint32_t session = id; + mLocationAPI->gnssNiResponse(id, response); + LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, session); + mRequestQueues[REQUEST_NIRESPONSE].reset(session); + mRequestQueues[REQUEST_NIRESPONSE].push(new GnssNiResponseRequest(*this)); + } + pthread_mutex_unlock(&mMutex); +} + +void LocationAPIClientBase::beforeGeofenceBreachCb( + GeofenceBreachNotification geofenceBreachNotification) +{ + uint32_t* ids = (uint32_t*)malloc(sizeof(uint32_t) * geofenceBreachNotification.count); + uint32_t* backup = geofenceBreachNotification.ids; + size_t n = geofenceBreachNotification.count; + geofenceBreachCallback genfenceCallback = nullptr; + + if (ids == NULL) { + LOC_LOGE("%s:%d] Failed to alloc %zu bytes", + __FUNCTION__, __LINE__, + sizeof(uint32_t) * geofenceBreachNotification.count); + return; + } + + pthread_mutex_lock(&mMutex); + if (mGeofenceBreachCallback != nullptr) { + size_t count = 0; + for (size_t i = 0; i < n; i++) { + uint32_t id = mGeofenceBiDict.getId(geofenceBreachNotification.ids[i]); + GeofenceBreachTypeMask type = + mGeofenceBiDict.getExtBySession(geofenceBreachNotification.ids[i]); + // if type == 0, we will not head into the fllowing block anyway. + // so we don't need to check id and type + if ((geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER && + (type & GEOFENCE_BREACH_ENTER_BIT)) || + (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT && + (type & GEOFENCE_BREACH_EXIT_BIT)) + ) { + ids[count] = id; + count++; + } + } + geofenceBreachNotification.count = count; + geofenceBreachNotification.ids = ids; + + genfenceCallback = mGeofenceBreachCallback; + } + pthread_mutex_unlock(&mMutex); + + if (genfenceCallback != nullptr) { + genfenceCallback(geofenceBreachNotification); + } + + // restore ids + geofenceBreachNotification.ids = backup; + geofenceBreachNotification.count = n; + free(ids); +} + +void LocationAPIClientBase::beforeBatchingStatusCb(BatchingStatusInfo batchStatus, + std::list & tripCompletedList) { + + // map the trip ids to the client ids + std::list tripCompletedClientIdList; + tripCompletedClientIdList.clear(); + + if (batchStatus.batchingStatus == BATCHING_STATUS_TRIP_COMPLETED) { + for (auto itt = tripCompletedList.begin(); itt != tripCompletedList.end(); itt++) { + if (mSessionBiDict.hasSession(*itt)) { + SessionEntity sessEntity = mSessionBiDict.getExtBySession(*itt); + + if (sessEntity.sessionMode == SESSION_MODE_ON_TRIP_COMPLETED) { + tripCompletedClientIdList.push_back(sessEntity.id); + mSessionBiDict.rmBySession(*itt); + } + } + } + } + + mBatchingStatusCallback(batchStatus, tripCompletedClientIdList); +} + +void LocationAPIClientBase::onResponseCb(LocationError error, uint32_t id) +{ + if (error != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s:%d] ERROR: %d ID: %d", __FUNCTION__, __LINE__, error, id); + } else { + LOC_LOGV("%s:%d] SUCCESS: %d id: %d", __FUNCTION__, __LINE__, error, id); + } + LocationAPIRequest* request = getRequestBySession(id); + if (request) { + request->onResponse(error, id); + delete request; + } +} + +void LocationAPIClientBase::onCollectiveResponseCb( + size_t count, LocationError* errors, uint32_t* ids) +{ + for (size_t i = 0; i < count; i++) { + if (errors[i] != LOCATION_ERROR_SUCCESS) { + LOC_LOGE("%s:%d] ERROR: %d ID: %d", __FUNCTION__, __LINE__, errors[i], ids[i]); + } else { + LOC_LOGV("%s:%d] SUCCESS: %d id: %d", __FUNCTION__, __LINE__, errors[i], ids[i]); + } + } + LocationAPIRequest* request = nullptr; + pthread_mutex_lock(&mMutex); + if (mRequestQueues[REQUEST_GEOFENCE].getSession() == GEOFENCE_SESSION_ID) { + request = mRequestQueues[REQUEST_GEOFENCE].pop(); + } + pthread_mutex_unlock(&mMutex); + if (request) { + request->onCollectiveResponse(count, errors, ids); + delete request; + } +} + +void LocationAPIClientBase::removeSession(uint32_t session) { + if (mSessionBiDict.hasSession(session)) { + mSessionBiDict.rmBySession(session); + } +} + +LocationAPIRequest* LocationAPIClientBase::getRequestBySession(uint32_t session) +{ + pthread_mutex_lock(&mMutex); + LocationAPIRequest* request = nullptr; + for (int i = 0; i < REQUEST_MAX; i++) { + if (i != REQUEST_GEOFENCE && + i != REQUEST_SESSION && + mRequestQueues[i].getSession() == session) { + request = mRequestQueues[i].pop(); + break; + } + } + if (request == nullptr) { + // Can't find a request with correct session, + // try to find it from mSessionBiDict + if (mSessionBiDict.hasSession(session)) { + request = mRequestQueues[REQUEST_SESSION].pop(); + } + } + pthread_mutex_unlock(&mMutex); + return request; +} diff --git a/gps/location/LocationAPIClientBase.h b/gps/location/LocationAPIClientBase.h new file mode 100644 index 0000000..ac1ebe6 --- /dev/null +++ b/gps/location/LocationAPIClientBase.h @@ -0,0 +1,592 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOCATION_API_CLINET_BASE_H +#define LOCATION_API_CLINET_BASE_H + +#include +#include +#include +#include +#include + +#include "LocationAPI.h" +#include +#include + +enum SESSION_MODE { + SESSION_MODE_NONE = 0, + SESSION_MODE_ON_FULL, + SESSION_MODE_ON_FIX, + SESSION_MODE_ON_TRIP_COMPLETED +}; + +enum REQUEST_TYPE { + REQUEST_TRACKING = 0, + REQUEST_SESSION, + REQUEST_GEOFENCE, + REQUEST_NIRESPONSE, + REQUEST_MAX, +}; + +enum CTRL_REQUEST_TYPE { + CTRL_REQUEST_DELETEAIDINGDATA = 0, + CTRL_REQUEST_CONTROL, + CTRL_REQUEST_CONFIG_UPDATE, + CTRL_REQUEST_CONFIG_GET, + CTRL_REQUEST_MAX, +}; + +class LocationAPIClientBase; + +class LocationAPIRequest { +public: + LocationAPIRequest() {} + virtual ~LocationAPIRequest() {} + virtual void onResponse(LocationError /*error*/, uint32_t /*id*/) {} + virtual void onCollectiveResponse( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} +}; + +class RequestQueue { +public: + RequestQueue(): mSession(0), mSessionArrayPtr(nullptr) { + } + virtual ~RequestQueue() { + reset((uint32_t)0); + } + void inline setSession(uint32_t session) { mSession = session; } + void inline setSessionArrayPtr(uint32_t* ptr) { mSessionArrayPtr = ptr; } + void reset(uint32_t session) { + LocationAPIRequest* request = nullptr; + while (!mQueue.empty()) { + request = mQueue.front(); + mQueue.pop(); + delete request; + } + mSession = session; + } + void reset(uint32_t* sessionArrayPtr) { + reset((uint32_t)0); + mSessionArrayPtr = sessionArrayPtr; + } + void push(LocationAPIRequest* request) { + mQueue.push(request); + } + LocationAPIRequest* pop() { + LocationAPIRequest* request = nullptr; + if (!mQueue.empty()) { + request = mQueue.front(); + mQueue.pop(); + } + return request; + } + uint32_t getSession() { return mSession; } + uint32_t* getSessionArrayPtr() { return mSessionArrayPtr; } +private: + uint32_t mSession; + uint32_t* mSessionArrayPtr; + std::queue mQueue; +}; + +class LocationAPIControlClient { +public: + LocationAPIControlClient(); + virtual ~LocationAPIControlClient(); + LocationAPIControlClient(const LocationAPIControlClient&) = delete; + LocationAPIControlClient& operator=(const LocationAPIControlClient&) = delete; + + LocationAPIRequest* getRequestBySession(uint32_t session); + LocationAPIRequest* getRequestBySessionArrayPtr(uint32_t* sessionArrayPtr); + + // LocationControlAPI + uint32_t locAPIGnssDeleteAidingData(GnssAidingData& data); + uint32_t locAPIEnable(LocationTechnologyType techType); + void locAPIDisable(); + uint32_t locAPIGnssUpdateConfig(GnssConfig config); + uint32_t locAPIGnssGetConfig(GnssConfigFlagsMask config); + inline LocationControlAPI* getControlAPI() { return mLocationControlAPI; } + + // callbacks + void onCtrlResponseCb(LocationError error, uint32_t id); + void onCtrlCollectiveResponseCb(size_t count, LocationError* errors, uint32_t* ids); + + inline virtual void onGnssDeleteAidingDataCb(LocationError /*error*/) {} + inline virtual void onEnableCb(LocationError /*error*/) {} + inline virtual void onDisableCb(LocationError /*error*/) {} + inline virtual void onGnssUpdateConfigCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + inline virtual void onGnssGetConfigCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + + class GnssDeleteAidingDataRequest : public LocationAPIRequest { + public: + GnssDeleteAidingDataRequest(LocationAPIControlClient& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onGnssDeleteAidingDataCb(error); + } + LocationAPIControlClient& mAPI; + }; + + class EnableRequest : public LocationAPIRequest { + public: + EnableRequest(LocationAPIControlClient& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onEnableCb(error); + } + LocationAPIControlClient& mAPI; + }; + + class DisableRequest : public LocationAPIRequest { + public: + DisableRequest(LocationAPIControlClient& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onDisableCb(error); + } + LocationAPIControlClient& mAPI; + }; + + class GnssUpdateConfigRequest : public LocationAPIRequest { + public: + GnssUpdateConfigRequest(LocationAPIControlClient& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* ids) { + mAPI.onGnssUpdateConfigCb(count, errors, ids); + } + LocationAPIControlClient& mAPI; + }; + + class GnssGetConfigRequest : public LocationAPIRequest { + public: + GnssGetConfigRequest(LocationAPIControlClient& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* ids) { + mAPI.onGnssGetConfigCb(count, errors, ids); + } + LocationAPIControlClient& mAPI; + }; + +private: + pthread_mutex_t mMutex; + LocationControlAPI* mLocationControlAPI; + RequestQueue mRequestQueues[CTRL_REQUEST_MAX]; + bool mEnabled; + GnssConfig mConfig; +}; + +class LocationAPIClientBase { +public: + LocationAPIClientBase(); + LocationAPIClientBase(const LocationAPIClientBase&) = delete; + LocationAPIClientBase& operator=(const LocationAPIClientBase&) = delete; + + void destroy(); + void onLocationApiDestroyCompleteCb(); + + void locAPISetCallbacks(LocationCallbacks& locationCallbacks); + void removeSession(uint32_t session); + LocationAPIRequest* getRequestBySession(uint32_t session); + + // LocationAPI + uint32_t locAPIStartTracking(TrackingOptions& trackingOptions); + void locAPIStopTracking(); + void locAPIUpdateTrackingOptions(TrackingOptions& trackingOptions); + + int32_t locAPIGetBatchSize(); + uint32_t locAPIStartSession( + uint32_t id, uint32_t sessionMode, TrackingOptions&& trackingOptions); + uint32_t locAPIStopSession(uint32_t id); + uint32_t locAPIUpdateSessionOptions( + uint32_t id, uint32_t sessionMode, TrackingOptions&& trackingOptions); + uint32_t locAPIGetBatchedLocations(uint32_t id, size_t count); + + uint32_t locAPIAddGeofences(size_t count, uint32_t* ids, + GeofenceOption* options, GeofenceInfo* data); + void locAPIRemoveGeofences(size_t count, uint32_t* ids); + void locAPIModifyGeofences(size_t count, uint32_t* ids, GeofenceOption* options); + void locAPIPauseGeofences(size_t count, uint32_t* ids); + void locAPIResumeGeofences(size_t count, uint32_t* ids, GeofenceBreachTypeMask* mask); + void locAPIRemoveAllGeofences(); + + void locAPIGnssNiResponse(uint32_t id, GnssNiResponse response); + + // callbacks + void onResponseCb(LocationError error, uint32_t id); + void onCollectiveResponseCb(size_t count, LocationError* errors, uint32_t* ids); + + void beforeGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification); + + inline virtual void onCapabilitiesCb(LocationCapabilitiesMask /*capabilitiesMask*/) {} + inline virtual void onGnssNmeaCb(GnssNmeaNotification /*gnssNmeaNotification*/) {} + inline virtual void onGnssDataCb(GnssDataNotification /*gnssDataNotification*/) {} + inline virtual void onGnssMeasurementsCb( + GnssMeasurementsNotification /*gnssMeasurementsNotification*/) {} + + inline virtual void onTrackingCb(Location /*location*/) {} + inline virtual void onGnssSvCb(GnssSvNotification /*gnssSvNotification*/) {} + inline virtual void onStartTrackingCb(LocationError /*error*/) {} + inline virtual void onStopTrackingCb(LocationError /*error*/) {} + inline virtual void onUpdateTrackingOptionsCb(LocationError /*error*/) {} + + inline virtual void onGnssLocationInfoCb( + GnssLocationInfoNotification /*gnssLocationInfoNotification*/) {} + + inline virtual void onBatchingCb(size_t /*count*/, Location* /*location*/, + BatchingOptions /*batchingOptions*/) {} + inline virtual void onBatchingStatusCb(BatchingStatusInfo /*batchingStatus*/, + std::list &/*listOfCompletedTrips*/) {} + void beforeBatchingStatusCb(BatchingStatusInfo batchStatus, + std::list & tripCompletedList); + inline virtual void onStartBatchingCb(LocationError /*error*/) {} + inline virtual void onStopBatchingCb(LocationError /*error*/) {} + inline virtual void onUpdateBatchingOptionsCb(LocationError /*error*/) {} + inline virtual void onGetBatchedLocationsCb(LocationError /*error*/) {} + + inline virtual void onGeofenceBreachCb( + GeofenceBreachNotification /*geofenceBreachNotification*/) {} + inline virtual void onGeofenceStatusCb( + GeofenceStatusNotification /*geofenceStatusNotification*/) {} + inline virtual void onAddGeofencesCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + inline virtual void onRemoveGeofencesCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + inline virtual void onModifyGeofencesCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + inline virtual void onPauseGeofencesCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + inline virtual void onResumeGeofencesCb( + size_t /*count*/, LocationError* /*errors*/, uint32_t* /*ids*/) {} + + inline virtual void onGnssNiCb(uint32_t /*id*/, GnssNiNotification /*gnssNiNotification*/) {} + inline virtual void onGnssNiResponseCb(LocationError /*error*/) {} + + inline virtual void onLocationSystemInfoCb(LocationSystemInfo /*locationSystemInfo*/) {} + +protected: + virtual ~LocationAPIClientBase(); + +private: + // private inner classes + typedef struct { + uint32_t id; + uint32_t trackingSession; + uint32_t batchingSession; + uint32_t sessionMode; + } SessionEntity; + + template + class BiDict { + public: + BiDict() { + pthread_mutex_init(&mBiDictMutex, nullptr); + } + virtual ~BiDict() { + pthread_mutex_destroy(&mBiDictMutex); + } + bool hasId(uint32_t id) { + pthread_mutex_lock(&mBiDictMutex); + bool ret = (mForwardMap.find(id) != mForwardMap.end()); + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + bool hasSession(uint32_t session) { + pthread_mutex_lock(&mBiDictMutex); + bool ret = (mBackwardMap.find(session) != mBackwardMap.end()); + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + void set(uint32_t id, uint32_t session, T& ext) { + pthread_mutex_lock(&mBiDictMutex); + mForwardMap[id] = session; + mBackwardMap[session] = id; + mExtMap[session] = ext; + pthread_mutex_unlock(&mBiDictMutex); + } + void clear() { + pthread_mutex_lock(&mBiDictMutex); + mForwardMap.clear(); + mBackwardMap.clear(); + mExtMap.clear(); + pthread_mutex_unlock(&mBiDictMutex); + } + void rmById(uint32_t id) { + pthread_mutex_lock(&mBiDictMutex); + mBackwardMap.erase(mForwardMap[id]); + mExtMap.erase(mForwardMap[id]); + mForwardMap.erase(id); + pthread_mutex_unlock(&mBiDictMutex); + } + void rmBySession(uint32_t session) { + pthread_mutex_lock(&mBiDictMutex); + mForwardMap.erase(mBackwardMap[session]); + mBackwardMap.erase(session); + mExtMap.erase(session); + pthread_mutex_unlock(&mBiDictMutex); + } + uint32_t getId(uint32_t session) { + pthread_mutex_lock(&mBiDictMutex); + uint32_t ret = 0; + auto it = mBackwardMap.find(session); + if (it != mBackwardMap.end()) { + ret = it->second; + } + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + uint32_t getSession(uint32_t id) { + pthread_mutex_lock(&mBiDictMutex); + uint32_t ret = 0; + auto it = mForwardMap.find(id); + if (it != mForwardMap.end()) { + ret = it->second; + } + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + T getExtById(uint32_t id) { + pthread_mutex_lock(&mBiDictMutex); + T ret; + memset(&ret, 0, sizeof(T)); + uint32_t session = mForwardMap[id]; + if (session > 0) { + auto it = mExtMap.find(session); + if (it != mExtMap.end()) { + ret = it->second; + } + } + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + T getExtBySession(uint32_t session) { + pthread_mutex_lock(&mBiDictMutex); + T ret; + memset(&ret, 0, sizeof(T)); + auto it = mExtMap.find(session); + if (it != mExtMap.end()) { + ret = it->second; + } + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + std::vector getAllSessions() { + std::vector ret; + pthread_mutex_lock(&mBiDictMutex); + for (auto it = mBackwardMap.begin(); it != mBackwardMap.end(); it++) { + ret.push_back(it->first); + } + pthread_mutex_unlock(&mBiDictMutex); + return ret; + } + private: + pthread_mutex_t mBiDictMutex; + // mForwarMap mapping id->session + std::map mForwardMap; + // mBackwardMap mapping session->id + std::map mBackwardMap; + // mExtMap mapping session->ext + std::map mExtMap; + }; + + class StartTrackingRequest : public LocationAPIRequest { + public: + StartTrackingRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t id) { + if (error != LOCATION_ERROR_SUCCESS) { + mAPI.removeSession(id); + } + mAPI.onStartTrackingCb(error); + } + LocationAPIClientBase& mAPI; + }; + + class StopTrackingRequest : public LocationAPIRequest { + public: + StopTrackingRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t id) { + mAPI.onStopTrackingCb(error); + if (error == LOCATION_ERROR_SUCCESS) { + mAPI.removeSession(id); + } + } + LocationAPIClientBase& mAPI; + }; + + class UpdateTrackingOptionsRequest : public LocationAPIRequest { + public: + UpdateTrackingOptionsRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onUpdateTrackingOptionsCb(error); + } + LocationAPIClientBase& mAPI; + }; + + class StartBatchingRequest : public LocationAPIRequest { + public: + StartBatchingRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t id) { + if (error != LOCATION_ERROR_SUCCESS) { + mAPI.removeSession(id); + } + mAPI.onStartBatchingCb(error); + } + LocationAPIClientBase& mAPI; + }; + + class StopBatchingRequest : public LocationAPIRequest { + public: + StopBatchingRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t id) { + mAPI.onStopBatchingCb(error); + if (error == LOCATION_ERROR_SUCCESS) { + mAPI.removeSession(id); + } + } + LocationAPIClientBase& mAPI; + }; + + class UpdateBatchingOptionsRequest : public LocationAPIRequest { + public: + UpdateBatchingOptionsRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onUpdateBatchingOptionsCb(error); + } + LocationAPIClientBase& mAPI; + }; + + class GetBatchedLocationsRequest : public LocationAPIRequest { + public: + GetBatchedLocationsRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onGetBatchedLocationsCb(error); + } + LocationAPIClientBase& mAPI; + }; + + class AddGeofencesRequest : public LocationAPIRequest { + public: + AddGeofencesRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) { + uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count); + for (size_t i = 0; i < count; i++) { + ids[i] = mAPI.mGeofenceBiDict.getId(sessions[i]); + } + LOC_LOGD("%s:]Returned geofence-id: %d in add geofence", __FUNCTION__, *ids); + mAPI.onAddGeofencesCb(count, errors, ids); + free(ids); + } + LocationAPIClientBase& mAPI; + }; + + class RemoveGeofencesRequest : public LocationAPIRequest { + public: + RemoveGeofencesRequest(LocationAPIClientBase& API, + BiDict* removedGeofenceBiDict) : + mAPI(API), mRemovedGeofenceBiDict(removedGeofenceBiDict) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) { + if (nullptr != mRemovedGeofenceBiDict) { + uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count); + for (size_t i = 0; i < count; i++) { + ids[i] = mRemovedGeofenceBiDict->getId(sessions[i]); + } + LOC_LOGD("%s:]Returned geofence-id: %d in remove geofence", __FUNCTION__, *ids); + mAPI.onRemoveGeofencesCb(count, errors, ids); + free(ids); + delete(mRemovedGeofenceBiDict); + } else { + LOC_LOGE("%s:%d] Unable to access removed geofences data.", __FUNCTION__, __LINE__); + } + } + LocationAPIClientBase& mAPI; + BiDict* mRemovedGeofenceBiDict; + }; + + class ModifyGeofencesRequest : public LocationAPIRequest { + public: + ModifyGeofencesRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) { + uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count); + for (size_t i = 0; i < count; i++) { + ids[i] = mAPI.mGeofenceBiDict.getId(sessions[i]); + } + mAPI.onModifyGeofencesCb(count, errors, ids); + free(ids); + } + LocationAPIClientBase& mAPI; + }; + + class PauseGeofencesRequest : public LocationAPIRequest { + public: + PauseGeofencesRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) { + uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count); + for (size_t i = 0; i < count; i++) { + ids[i] = mAPI.mGeofenceBiDict.getId(sessions[i]); + } + mAPI.onPauseGeofencesCb(count, errors, ids); + free(ids); + } + LocationAPIClientBase& mAPI; + }; + + class ResumeGeofencesRequest : public LocationAPIRequest { + public: + ResumeGeofencesRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onCollectiveResponse(size_t count, LocationError* errors, uint32_t* sessions) { + uint32_t *ids = (uint32_t*)malloc(sizeof(uint32_t) * count); + for (size_t i = 0; i < count; i++) { + ids[i] = mAPI.mGeofenceBiDict.getId(sessions[i]); + } + mAPI.onResumeGeofencesCb(count, errors, ids); + free(ids); + } + LocationAPIClientBase& mAPI; + }; + + class GnssNiResponseRequest : public LocationAPIRequest { + public: + GnssNiResponseRequest(LocationAPIClientBase& API) : mAPI(API) {} + inline void onResponse(LocationError error, uint32_t /*id*/) { + mAPI.onGnssNiResponseCb(error); + } + LocationAPIClientBase& mAPI; + }; + +private: + pthread_mutex_t mMutex; + + geofenceBreachCallback mGeofenceBreachCallback; + batchingStatusCallback mBatchingStatusCallback; + + LocationAPI* mLocationAPI; + + RequestQueue mRequestQueues[REQUEST_MAX]; + BiDict mGeofenceBiDict; + BiDict mSessionBiDict; + int32_t mBatchSize; + bool mTracking; +}; + +#endif /* LOCATION_API_CLINET_BASE_H */ diff --git a/gps/location/LocationDataTypes.h b/gps/location/LocationDataTypes.h new file mode 100644 index 0000000..b85464a --- /dev/null +++ b/gps/location/LocationDataTypes.h @@ -0,0 +1,2070 @@ +/* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOCATIONDATATYPES_H +#define LOCATIONDATATYPES_H + +#include +#include +#include +#include +#include +#include + +#define GNSS_NI_REQUESTOR_MAX (256) +#define GNSS_NI_MESSAGE_ID_MAX (2048) +#define GNSS_SV_MAX (128) +#define GNSS_MEASUREMENTS_MAX (128) +#define GNSS_UTC_TIME_OFFSET (3657) + +#define GNSS_BUGREPORT_GPS_MIN (1) +#define GNSS_BUGREPORT_SBAS_MIN (120) +#define GNSS_BUGREPORT_GLO_MIN (1) +#define GNSS_BUGREPORT_QZSS_MIN (193) +#define GNSS_BUGREPORT_BDS_MIN (1) +#define GNSS_BUGREPORT_GAL_MIN (1) +#define GNSS_BUGREPORT_NAVIC_MIN (1) + +#define GNSS_MAX_NAME_LENGTH (8) + +typedef enum { + LOCATION_ERROR_SUCCESS = 0, + LOCATION_ERROR_GENERAL_FAILURE, + LOCATION_ERROR_CALLBACK_MISSING, + LOCATION_ERROR_INVALID_PARAMETER, + LOCATION_ERROR_ID_EXISTS, + LOCATION_ERROR_ID_UNKNOWN, + LOCATION_ERROR_ALREADY_STARTED, + LOCATION_ERROR_GEOFENCES_AT_MAX, + LOCATION_ERROR_NOT_SUPPORTED, + LOCATION_ERROR_TIMEOUT, +} LocationError; + +// Flags to indicate which values are valid in a Location +typedef uint16_t LocationFlagsMask; +typedef enum { + LOCATION_HAS_LAT_LONG_BIT = (1<<0), // location has valid latitude and longitude + LOCATION_HAS_ALTITUDE_BIT = (1<<1), // location has valid altitude + LOCATION_HAS_SPEED_BIT = (1<<2), // location has valid speed + LOCATION_HAS_BEARING_BIT = (1<<3), // location has valid bearing + LOCATION_HAS_ACCURACY_BIT = (1<<4), // location has valid accuracy + LOCATION_HAS_VERTICAL_ACCURACY_BIT = (1<<5), // location has valid vertical accuracy + LOCATION_HAS_SPEED_ACCURACY_BIT = (1<<6), // location has valid speed accuracy + LOCATION_HAS_BEARING_ACCURACY_BIT = (1<<7), // location has valid bearing accuracy + LOCATION_HAS_SPOOF_MASK = (1<<8), // location has valid spoof mask + LOCATION_HAS_ELAPSED_REAL_TIME = (1<<9), // location has valid elapsed real time + LOCATION_HAS_CONFORMITY_INDEX_BIT = (1<<10), // location has valid conformity index +} LocationFlagsBits; + +typedef uint16_t LocationTechnologyMask; +// mask indicating location calculations including... +typedef enum { + LOCATION_TECHNOLOGY_GNSS_BIT = (1<<0), // using GNSS + LOCATION_TECHNOLOGY_CELL_BIT = (1<<1), // using Cell + LOCATION_TECHNOLOGY_WIFI_BIT = (1<<2), // using WiFi + LOCATION_TECHNOLOGY_SENSORS_BIT = (1<<3), // using Sensors + LOCATION_TECHNOLOGY_REFERENCE_LOCATION_BIT = (1<<4), // using reference location + LOCATION_TECHNOLOGY_INJECTED_COARSE_POSITION_BIT = (1<<5), // using CPI + LOCATION_TECHNOLOGY_AFLT_BIT = (1<<6), // AFLT + LOCATION_TECHNOLOGY_HYBRID_BIT = (1<<7), // HYBRID + LOCATION_TECHNOLOGY_PPE_BIT = (1<<8), // PPE + LOCATION_TECHNOLOGY_VEH_BIT = (1<<9), // using vehicular data + LOCATION_TECHNOLOGY_VIS_BIT = (1<<10), // using visual data + LOCATION_TECHNOLOGY_DGNSS_BIT = (1<<11), // DGNSS +} LocationTechnologyBits; + +typedef uint32_t LocationSpoofMask; +typedef enum { + LOCATION_POSTION_SPOOFED = (1<<0), // location position spoofed + LOCATION_TIME_SPOOFED = (1<<1), // location time spoofed + LOCATION_NAVIGATION_DATA_SPOOFED = (1<<2), // location navigation data spoofed +} LocationSpoofBits; + +typedef enum { + LOCATION_RELIABILITY_NOT_SET = 0, + LOCATION_RELIABILITY_VERY_LOW, + LOCATION_RELIABILITY_LOW, + LOCATION_RELIABILITY_MEDIUM, + LOCATION_RELIABILITY_HIGH, +} LocationReliability; + +typedef uint32_t GnssLocationNavSolutionMask; +typedef enum { + // SBAS ionospheric correction is used + LOCATION_SBAS_CORRECTION_IONO_BIT = (1<<0), + // SBAS fast correction is used + LOCATION_SBAS_CORRECTION_FAST_BIT = (1<<1), + // SBAS long-tem correction is used + LOCATION_SBAS_CORRECTION_LONG_BIT = (1<<2), + // SBAS integrity information is used + LOCATION_SBAS_INTEGRITY_BIT = (1<<3), + // Position Report is DGNSS corrected + LOCATION_NAV_CORRECTION_DGNSS_BIT = (1<<4), + // Position Report is RTK corrected + LOCATION_NAV_CORRECTION_RTK_BIT = (1<<5), + // Position Report is PPP corrected + LOCATION_NAV_CORRECTION_PPP_BIT = (1<<6), + // Posiiton Report is RTF fixed corrected + LOCATION_NAV_CORRECTION_RTK_FIXED_BIT = (1<<7), + // Position report is computed with only SBAS corrected SVs. + LOCATION_NAV_CORRECTION_ONLY_SBAS_CORRECTED_SV_USED_BIT = (1<<8) +} GnssLocationNavSolutionBits; + +typedef uint32_t GnssLocationPosDataMask; +typedef enum { + LOCATION_NAV_DATA_HAS_LONG_ACCEL_BIT = (1<<0), // Navigation data has Forward Acceleration + LOCATION_NAV_DATA_HAS_LAT_ACCEL_BIT = (1<<1), // Navigation data has Sideward Acceleration + LOCATION_NAV_DATA_HAS_VERT_ACCEL_BIT = (1<<2), // Navigation data has Vertical Acceleration + LOCATION_NAV_DATA_HAS_YAW_RATE_BIT = (1<<3), // Navigation data has Heading Rate + LOCATION_NAV_DATA_HAS_PITCH_BIT = (1<<4), // Navigation data has Body pitch + // Navigation data has Forward Acceleration uncertainty + LOCATION_NAV_DATA_HAS_LONG_ACCEL_UNC_BIT = (1<<5), + // Navigation data has Sideward Acceleration uncertainty + LOCATION_NAV_DATA_HAS_LAT_ACCEL_UNC_BIT = (1<<6), + // Navigation data has Vertical Acceleration uncertainty + LOCATION_NAV_DATA_HAS_VERT_ACCEL_UNC_BIT = (1<<7), + // Navigation data has Heading Rate uncertainty + LOCATION_NAV_DATA_HAS_YAW_RATE_UNC_BIT = (1<<8), + // Navigation data has Body pitch uncertainty + LOCATION_NAV_DATA_HAS_PITCH_UNC_BIT = (1<<9) +} GnssLocationPosDataBits; + +typedef uint32_t GnssLocationPosDataMaskExt; +typedef enum { + // Navigation data has pitch rate + LOCATION_NAV_DATA_HAS_PITCH_RATE_BIT = (1<<0), + // Navigation data has body pitch rate uncertainty + LOCATION_NAV_DATA_HAS_PITCH_RATE_UNC_BIT = (1<<1), + // Navigation data has body roll + LOCATION_NAV_DATA_HAS_ROLL_BIT = (1<<2), + // Navigation data has body roll uncertainty + LOCATION_NAV_DATA_HAS_ROLL_UNC_BIT = (1<<3), + // Navigation data has body rate roll + LOCATION_NAV_DATA_HAS_ROLL_RATE_BIT = (1<<4), + // Navigation data has body roll rate uncertainty + LOCATION_NAV_DATA_HAS_ROLL_RATE_UNC_BIT = (1<<5), + // Navigation data has body yaw + LOCATION_NAV_DATA_HAS_YAW_BIT = (1<<6), + // Navigation data has body roll uncertainty + LOCATION_NAV_DATA_HAS_YAW_UNC_BIT = (1<<7) +} GnssLocationPosDataBitsExt; + +typedef uint64_t GnssLocationInfoFlagMask; +typedef enum { + GNSS_LOCATION_INFO_ALTITUDE_MEAN_SEA_LEVEL_BIT = (1<<0), // altitude mean sea level + GNSS_LOCATION_INFO_DOP_BIT = (1<<1), // pdop, hdop, and vdop + GNSS_LOCATION_INFO_MAGNETIC_DEVIATION_BIT = (1<<2), // magnetic deviation + GNSS_LOCATION_INFO_HOR_RELIABILITY_BIT = (1<<3), // horizontal reliability + GNSS_LOCATION_INFO_VER_RELIABILITY_BIT = (1<<4), // vertical reliability + GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MAJOR_BIT = (1<<5), // elipsode semi major + GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_SEMI_MINOR_BIT = (1<<6), // elipsode semi minor + GNSS_LOCATION_INFO_HOR_ACCURACY_ELIP_AZIMUTH_BIT = (1<<7), // accuracy elipsode azimuth + GNSS_LOCATION_INFO_GNSS_SV_USED_DATA_BIT = (1<<8), // svUsedInPosition, + // numOfMeasReceived + // and measUsageInfo + GNSS_LOCATION_INFO_NAV_SOLUTION_MASK_BIT = (1<<9), // navSolutionMask + GNSS_LOCATION_INFO_SV_SOURCE_INFO_BIT = (1<<10), // LocSvInfoSource + GNSS_LOCATION_INFO_POS_DYNAMICS_DATA_BIT = (1<<11), // position dynamics data & + // Position Dynamics Ext + GNSS_LOCATION_INFO_EXT_DOP_BIT = (1<<12), // gdop, tdop + GNSS_LOCATION_INFO_NORTH_STD_DEV_BIT = (1<<13), // North standard deviation + GNSS_LOCATION_INFO_EAST_STD_DEV_BIT = (1<<14), // East standard deviation + GNSS_LOCATION_INFO_NORTH_VEL_BIT = (1<<15), // North Velocity + GNSS_LOCATION_INFO_EAST_VEL_BIT = (1<<16), // East Velocity + GNSS_LOCATION_INFO_UP_VEL_BIT = (1<<17), // Up Velocity + GNSS_LOCATION_INFO_NORTH_VEL_UNC_BIT = (1<<18), // North Velocity Uncertainty + GNSS_LOCATION_INFO_EAST_VEL_UNC_BIT = (1<<19), // East Velocity Uncertainty + GNSS_LOCATION_INFO_UP_VEL_UNC_BIT = (1<<20), // Up Velocity Uncertainty + GNSS_LOCATION_INFO_LEAP_SECONDS_BIT = (1<<21), // leap seconds + GNSS_LOCATION_INFO_TIME_UNC_BIT = (1<<22), // time uncertainty + GNSS_LOCATION_INFO_NUM_SV_USED_IN_POSITION_BIT = (1<<23), // number of SV used in position + GNSS_LOCATION_INFO_CALIBRATION_CONFIDENCE_BIT = (1<<24), // sensor cal confidence + GNSS_LOCATION_INFO_CALIBRATION_STATUS_BIT = (1<<25), // sensor cal status + GNSS_LOCATION_INFO_OUTPUT_ENG_TYPE_BIT = (1<<26), // output engine type + GNSS_LOCATION_INFO_OUTPUT_ENG_MASK_BIT = (1<<27), // output engine mask + GNSS_LOCATION_INFO_CONFORMITY_INDEX_BIT = (1<<28), // conformity index + GNSS_LOCATION_INFO_LLA_VRP_BASED_BIT = (1<<29), // VRP-based lat/long/alt + GNSS_LOCATION_INFO_ENU_VELOCITY_VRP_BASED_BIT = (1<<30), // VRP-based east/north/up vel + GNSS_LOCATION_INFO_DR_SOLUTION_STATUS_MASK_BIT = (1ULL<<31), // Valid DR solution status + GNSS_LOCATION_INFO_ALTITUDE_ASSUMED_BIT = (1ULL<<32), // Valid altitude assumed + GNSS_LOCATION_INFO_SESSION_STATUS_BIT = (1ULL<<33), // session status +} GnssLocationInfoFlagBits; + +typedef enum { + GEOFENCE_BREACH_ENTER = 0, + GEOFENCE_BREACH_EXIT, + GEOFENCE_BREACH_DWELL_IN, + GEOFENCE_BREACH_DWELL_OUT, + GEOFENCE_BREACH_UNKNOWN, +} GeofenceBreachType; + +typedef uint16_t GeofenceBreachTypeMask; +typedef enum { + GEOFENCE_BREACH_ENTER_BIT = (1<<0), + GEOFENCE_BREACH_EXIT_BIT = (1<<1), + GEOFENCE_BREACH_DWELL_IN_BIT = (1<<2), + GEOFENCE_BREACH_DWELL_OUT_BIT = (1<<3), +} GeofenceBreachTypeBits; + +typedef enum { + GEOFENCE_STATUS_AVAILABILE_NO = 0, + GEOFENCE_STATUS_AVAILABILE_YES, +} GeofenceStatusAvailable; + +// Set of masks for Modem and QWES capabilities. +typedef uint64_t LocationCapabilitiesMask; +typedef enum { + // supports startTracking API with minInterval param + LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT = (1<<0), + // supports startBatching API with minInterval param + LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT = (1<<1), + // supports startTracking API with minDistance param + LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT = (1<<2), + // supports startBatching API with minDistance param + LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT = (1<<3), + // supports addGeofences API + LOCATION_CAPABILITIES_GEOFENCE_BIT = (1<<4), + // supports GnssMeasurementsCallback + LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT = (1<<5), + // supports startTracking/startBatching API with LocationOptions.mode of MSB (Ms Based) + LOCATION_CAPABILITIES_GNSS_MSB_BIT = (1<<6), + // supports startTracking/startBatching API with LocationOptions.mode of MSA (MS Assisted) + LOCATION_CAPABILITIES_GNSS_MSA_BIT = (1<<7), + // supports debug nmea sentences in the debugNmeaCallback + LOCATION_CAPABILITIES_DEBUG_NMEA_BIT = (1<<8), + // support outdoor trip batching + LOCATION_CAPABILITIES_OUTDOOR_TRIP_BATCHING_BIT = (1<<9), + // support constellation enablement + LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT = (1<<10), + // support agpm + LOCATION_CAPABILITIES_AGPM_BIT = (1<<11), + // support location privacy + LOCATION_CAPABILITIES_PRIVACY_BIT = (1<<12), + // support measurement corrections + LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT = (1<<13), + // support Robust Location + LOCATION_CAPABILITIES_CONFORMITY_INDEX_BIT = (1<<14), + // support precise location edgnss + LOCATION_CAPABILITIES_EDGNSS_BIT = (1<<15), + // Modem supports Carrier Phase for Precise Positioning + // Measurement Engine (PPME). + LOCATION_CAPABILITIES_QWES_CARRIER_PHASE_BIT = (1<<16), + // Modem supports SV Polynomial for tightly coupled external + // DR support. This is a Standalone Feature. + LOCATION_CAPABILITIES_QWES_SV_POLYNOMIAL_BIT = (1<<17), + // Modem supports SV Ephemeris for tightly coupled external + // PPE engines. This is a Standalone Feature. + LOCATION_CAPABILITIES_QWES_SV_EPHEMERIS_BIT = (1<<18), + // Modem supports GNSS Single Frequency feature. This is a + // Standalone Feature. + LOCATION_CAPABILITIES_QWES_GNSS_SINGLE_FREQUENCY = (1<<19), + // Modem supports GNSS Multi Frequency feature. Multi Frequency + // enables Single frequency also. + LOCATION_CAPABILITIES_QWES_GNSS_MULTI_FREQUENCY = (1<<20), + // This mask indicates VPe license bundle is enabled. VEPP + // bundle include Carrier Phase and SV Polynomial features. + LOCATION_CAPABILITIES_QWES_VPE = (1<<21), + // This mask indicates support for CV2X Location basic features. + // This bundle includes features for GTS Time & Freq, C-TUNC + // (Constrained Time uncertainity. + LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_BASIC = (1<<22), + // This mask indicates support for CV2X Location premium features. + // This bundle includes features for CV2X Location Basic features, + // QDR3 feature, and PACE. (Position Assisted Clock Estimator. + LOCATION_CAPABILITIES_QWES_CV2X_LOCATION_PREMIUM = (1<<23), + // This mask indicates that PPE (Precise Positioning Engine) + // library is enabled or Precise Positioning Framework (PPF) + // is available. This bundle includes features for Carrier + // Phase and SV Ephermeris. + LOCATION_CAPABILITIES_QWES_PPE = (1<<24), + // This mask indicates QDR2_C license bundle is enabled. This + // bundle includes features for SV Polynomial. + LOCATION_CAPABILITIES_QWES_QDR2 = (1<<25), + // This mask indicates QDR3_C license bundle is enabled. This + // bundle includes features for SV Polynomial. + LOCATION_CAPABILITIES_QWES_QDR3 = (1<<26), +} LocationCapabilitiesBits; + +typedef uint8_t LocationQwesFeatureType; +typedef enum { + // Modem supports Carrier Phase for Precise Positioning + // Measurement Engine (PPME). + LOCATION_QWES_FEATURE_TYPE_CARRIER_PHASE = 1, + // Modem supports SV Polynomial for tightly coupled external + // DR support. This is a Standalone Feature. + LOCATION_QWES_FEATURE_TYPE_SV_POLYNOMIAL, + // Modem supports SV Ephemeris for tightly coupled external + // PPE support. This is a Standalone Feature. + LOCATION_QWES_FEATURE_TYPE_SV_EPH, + // Modem supports GNSS Single Frequency feature. This is a + // Standalone Feature. + LOCATION_QWES_FEATURE_TYPE_GNSS_SINGLE_FREQUENCY, + // Modem supports GNSS Multi Frequency feature. Multi Frequency + // enables Single frequency also. + LOCATION_QWES_FEATURE_TYPE_GNSS_MULTI_FREQUENCY, + // This indicates Time and Frequency status. + LOCATION_QWES_FEATURE_TYPE_TIME_FREQUENCY, + // This indicates Time Uncertainty status. + LOCATION_QWES_FEATURE_TYPE_TIME_UNCERTAINTY, + // This indicates Clock Estimate status. + LOCATION_QWES_FEATURE_TYPE_CLOCK_ESTIMATE, + // This mask indicates that PPE (Precise Positioning Engine) + // library is enabled or Precise Positioning Framework (PPF) + // is available. This bundle includes features for Carrier + // Phase and SV Ephermeris. + LOCATION_QWES_FEATURE_TYPE_PPE, + // This indicates QDR2_C license bundle is enabled. This + // bundle includes features for SV Polynomial. + LOCATION_QWES_FEATURE_TYPE_QDR2, + // This indicates QDR3_C license bundle is enabled. This + // bundle includes features for SV Polynomial. + LOCATION_QWES_FEATURE_TYPE_QDR3, + // This indicates VEPP license bundle is enabled. VEPP + // bundle include Carrier Phase and SV Polynomial features. + LOCATION_QWES_FEATURE_TYPE_VPE, + // Max value + LOCATION_QWES_FEATURE_TYPE_MAX +} LocationQwesFeatureTypes; + +typedef enum { + LOCATION_TECHNOLOGY_TYPE_GNSS = 0, +} LocationTechnologyType; + +// Configures how GPS is locked when GPS is disabled (through GnssDisable) +enum { + GNSS_CONFIG_GPS_LOCK_NONE = 0, // gps is not locked when GPS is disabled (GnssDisable) + GNSS_CONFIG_GPS_LOCK_MO, // gps mobile originated (MO) is locked when GPS is disabled + GNSS_CONFIG_GPS_LOCK_NI, // gps network initiated (NI) is locked when GPS is disabled + GNSS_CONFIG_GPS_LOCK_MO_AND_NI,// gps MO and NI is locked when GPS is disabled +}; +typedef int32_t GnssConfigGpsLock; + +// SUPL version +typedef enum { + GNSS_CONFIG_SUPL_VERSION_1_0_0 = 1, + GNSS_CONFIG_SUPL_VERSION_2_0_0, + GNSS_CONFIG_SUPL_VERSION_2_0_2, + GNSS_CONFIG_SUPL_VERSION_2_0_4, +} GnssConfigSuplVersion; + +// LTE Positioning Profile +typedef uint16_t GnssConfigLppProfileMask; +typedef enum { + GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE = 0, // RRLP on LTE (Default) + GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT = (1<<0), // LPP User Plane (UP) on LTE + GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT = (1<<1), // LPP_Control_Plane (CP) + GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT = (1<<2), // LPP User Plane (UP) on LTE + GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT = (1<<3), // LPP_Control_Plane (CP) +} GnssConfigLppProfileBits; + +// Technology for LPPe Control Plane +typedef uint16_t GnssConfigLppeControlPlaneMask; +typedef enum { + GNSS_CONFIG_LPPE_CONTROL_PLANE_DBH_BIT = (1<<0), // DBH + GNSS_CONFIG_LPPE_CONTROL_PLANE_WLAN_AP_MEASUREMENTS_BIT = (1<<1), // WLAN_AP_MEASUREMENTS + GNSS_CONFIG_LPPE_CONTROL_PLANE_SRN_AP_MEASUREMENTS_BIT = (1<<2), // SRN_AP_MEASUREMENTS + GNSS_CONFIG_LPPE_CONTROL_PLANE_SENSOR_BARO_MEASUREMENTS_BIT = (1<<3), + // SENSOR_BARO_MEASUREMENTS +} GnssConfigLppeControlPlaneBits; + +// Technology for LPPe User Plane +typedef uint16_t GnssConfigLppeUserPlaneMask; +typedef enum { + GNSS_CONFIG_LPPE_USER_PLANE_DBH_BIT = (1<<0), // DBH + GNSS_CONFIG_LPPE_USER_PLANE_WLAN_AP_MEASUREMENTS_BIT = (1<<1), // WLAN_AP_MEASUREMENTS + GNSS_CONFIG_LPPE_USER_PLANE_SRN_AP_MEASUREMENTS_BIT = (1<<2), // SRN_AP_MEASUREMENTS + GNSS_CONFIG_LPPE_USER_PLANE_SENSOR_BARO_MEASUREMENTS_BIT = (1<<3), + // SENSOR_BARO_MEASUREMENTS +} GnssConfigLppeUserPlaneBits; + +// Positioning Protocol on A-GLONASS system +typedef uint16_t GnssConfigAGlonassPositionProtocolMask; +typedef enum { + GNSS_CONFIG_RRC_CONTROL_PLANE_BIT = (1<<0), // RRC Control Plane + GNSS_CONFIG_RRLP_USER_PLANE_BIT = (1<<1), // RRLP User Plane + GNSS_CONFIG_LLP_USER_PLANE_BIT = (1<<2), // LPP User Plane + GNSS_CONFIG_LLP_CONTROL_PLANE_BIT = (1<<3), // LPP Control Plane +} GnssConfigAGlonassPositionProtocolBits; + +typedef enum { + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO = 0, + GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES, +} GnssConfigEmergencyPdnForEmergencySupl; + +typedef enum { + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO = 0, + GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES, +} GnssConfigSuplEmergencyServices; + +typedef uint16_t GnssConfigSuplModeMask; +typedef enum { + GNSS_CONFIG_SUPL_MODE_MSB_BIT = (1<<0), + GNSS_CONFIG_SUPL_MODE_MSA_BIT = (1<<1), +} GnssConfigSuplModeBits; + +typedef uint32_t GnssConfigFlagsMask; +typedef enum { + GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT = (1<<0), + GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT = (1<<1), + GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT = (1<<2), + GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT = (1<<3), + GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT = (1<<4), + GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT = (1<<5), + GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT = (1<<6), + GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT = (1<<7), + GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT = (1<<8), + GNSS_CONFIG_FLAGS_SUPL_MODE_BIT = (1<<9), + GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT = (1<<10), + GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT = (1<<11), + GNSS_CONFIG_FLAGS_ROBUST_LOCATION_BIT = (1<<12), + GNSS_CONFIG_FLAGS_MIN_GPS_WEEK_BIT = (1<<13), + GNSS_CONFIG_FLAGS_MIN_SV_ELEVATION_BIT = (1<<14), + GNSS_CONFIG_FLAGS_CONSTELLATION_SECONDARY_BAND_BIT = (1<<15), +} GnssConfigFlagsBits; + +typedef enum { + GNSS_NI_ENCODING_TYPE_NONE = 0, + GNSS_NI_ENCODING_TYPE_GSM_DEFAULT, + GNSS_NI_ENCODING_TYPE_UTF8, + GNSS_NI_ENCODING_TYPE_UCS2, +} GnssNiEncodingType; + +typedef enum { + GNSS_NI_TYPE_VOICE = 0, + GNSS_NI_TYPE_SUPL, + GNSS_NI_TYPE_CONTROL_PLANE, + GNSS_NI_TYPE_EMERGENCY_SUPL +} GnssNiType; + +typedef uint16_t GnssNiOptionsMask; +typedef enum { + GNSS_NI_OPTIONS_NOTIFICATION_BIT = (1<<0), + GNSS_NI_OPTIONS_VERIFICATION_BIT = (1<<1), + GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT = (1<<2), +} GnssNiOptionsBits; + +typedef enum { + GNSS_NI_RESPONSE_ACCEPT = 1, + GNSS_NI_RESPONSE_DENY, + GNSS_NI_RESPONSE_NO_RESPONSE, + GNSS_NI_RESPONSE_IGNORE, +} GnssNiResponse; + +typedef enum { + GNSS_SV_TYPE_UNKNOWN = 0, + GNSS_SV_TYPE_GPS, + GNSS_SV_TYPE_SBAS, + GNSS_SV_TYPE_GLONASS, + GNSS_SV_TYPE_QZSS, + GNSS_SV_TYPE_BEIDOU, + GNSS_SV_TYPE_GALILEO, + GNSS_SV_TYPE_NAVIC, +} GnssSvType; + +typedef enum { + GNSS_EPH_TYPE_UNKNOWN = 0, + GNSS_EPH_TYPE_EPHEMERIS, + GNSS_EPH_TYPE_ALMANAC, +} GnssEphemerisType; + +typedef enum { + GNSS_EPH_SOURCE_UNKNOWN = 0, + GNSS_EPH_SOURCE_DEMODULATED, + GNSS_EPH_SOURCE_SUPL_PROVIDED, + GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED, + GNSS_EPH_SOURCE_LOCAL, +} GnssEphemerisSource; + +typedef enum { + GNSS_EPH_HEALTH_UNKNOWN = 0, + GNSS_EPH_HEALTH_GOOD, + GNSS_EPH_HEALTH_BAD, +} GnssEphemerisHealth; + +typedef uint16_t GnssSvOptionsMask; +typedef enum { + GNSS_SV_OPTIONS_HAS_EPHEMER_BIT = (1<<0), + GNSS_SV_OPTIONS_HAS_ALMANAC_BIT = (1<<1), + GNSS_SV_OPTIONS_USED_IN_FIX_BIT = (1<<2), + GNSS_SV_OPTIONS_HAS_CARRIER_FREQUENCY_BIT = (1<<3), + GNSS_SV_OPTIONS_HAS_GNSS_SIGNAL_TYPE_BIT = (1<<4) +} GnssSvOptionsBits; + +typedef enum { + GNSS_ASSISTANCE_TYPE_SUPL = 0, + GNSS_ASSISTANCE_TYPE_C2K, + GNSS_ASSISTANCE_TYPE_SUPL_EIMS, + GNSS_ASSISTANCE_TYPE_SUPL_IMS, +} GnssAssistanceType; + +typedef enum { + GNSS_SUPL_MODE_STANDALONE = 0, + GNSS_SUPL_MODE_MSB, + GNSS_SUPL_MODE_MSA, +} GnssSuplMode; + +typedef enum { + BATCHING_MODE_ROUTINE = 0, // positions are reported when batched positions memory is full + BATCHING_MODE_TRIP, // positions are reported when a certain distance is covered + BATCHING_MODE_NO_AUTO_REPORT // no report of positions automatically, instead queried on demand +} BatchingMode; + +typedef enum { + BATCHING_STATUS_TRIP_COMPLETED = 0, + BATCHING_STATUS_POSITION_AVAILABE, + BATCHING_STATUS_POSITION_UNAVAILABLE +} BatchingStatus; + +typedef uint16_t GnssMeasurementsAdrStateMask; +typedef enum { + GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_UNKNOWN = 0, + GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT = (1<<0), + GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT = (1<<1), + GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT = (1<<2), + GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT = (1<<3), +} GnssMeasurementsAdrStateBits; + +typedef enum { + GNSS_MEASUREMENTS_CODE_TYPE_A = 0, + GNSS_MEASUREMENTS_CODE_TYPE_B = 1, + GNSS_MEASUREMENTS_CODE_TYPE_C = 2, + GNSS_MEASUREMENTS_CODE_TYPE_I = 3, + GNSS_MEASUREMENTS_CODE_TYPE_L = 4, + GNSS_MEASUREMENTS_CODE_TYPE_M = 5, + GNSS_MEASUREMENTS_CODE_TYPE_P = 6, + GNSS_MEASUREMENTS_CODE_TYPE_Q = 7, + GNSS_MEASUREMENTS_CODE_TYPE_S = 8, + GNSS_MEASUREMENTS_CODE_TYPE_W = 9, + GNSS_MEASUREMENTS_CODE_TYPE_X = 10, + GNSS_MEASUREMENTS_CODE_TYPE_Y = 11, + GNSS_MEASUREMENTS_CODE_TYPE_Z = 12, + GNSS_MEASUREMENTS_CODE_TYPE_N = 13, + GNSS_MEASUREMENTS_CODE_TYPE_OTHER = 255, +} GnssMeasurementsCodeType; + +typedef uint32_t GnssMeasurementsDataFlagsMask; +typedef enum { + GNSS_MEASUREMENTS_DATA_SV_ID_BIT = (1<<0), + GNSS_MEASUREMENTS_DATA_SV_TYPE_BIT = (1<<1), + GNSS_MEASUREMENTS_DATA_STATE_BIT = (1<<2), + GNSS_MEASUREMENTS_DATA_RECEIVED_SV_TIME_BIT = (1<<3), + GNSS_MEASUREMENTS_DATA_RECEIVED_SV_TIME_UNCERTAINTY_BIT = (1<<4), + GNSS_MEASUREMENTS_DATA_CARRIER_TO_NOISE_BIT = (1<<5), + GNSS_MEASUREMENTS_DATA_PSEUDORANGE_RATE_BIT = (1<<6), + GNSS_MEASUREMENTS_DATA_PSEUDORANGE_RATE_UNCERTAINTY_BIT = (1<<7), + GNSS_MEASUREMENTS_DATA_ADR_STATE_BIT = (1<<8), + GNSS_MEASUREMENTS_DATA_ADR_BIT = (1<<9), + GNSS_MEASUREMENTS_DATA_ADR_UNCERTAINTY_BIT = (1<<10), + GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT = (1<<11), + GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT = (1<<12), + GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT = (1<<13), + GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT = (1<<14), + GNSS_MEASUREMENTS_DATA_MULTIPATH_INDICATOR_BIT = (1<<15), + GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT = (1<<16), + GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT = (1<<17), + GNSS_MEASUREMENTS_DATA_FULL_ISB_BIT = (1<<18), + GNSS_MEASUREMENTS_DATA_FULL_ISB_UNCERTAINTY_BIT = (1<<19), + GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_BIT = (1<<20), + GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_UNCERTAINTY_BIT = (1<<21), + GNSS_MEASUREMENTS_DATA_CYCLE_SLIP_COUNT_BIT = (1<<22), +} GnssMeasurementsDataFlagsBits; + +typedef uint32_t GnssMeasurementsStateMask; +typedef enum { + GNSS_MEASUREMENTS_STATE_UNKNOWN_BIT = 0, + GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT = (1<<0), + GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT = (1<<1), + GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT = (1<<2), + GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT = (1<<3), + GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT = (1<<4), + GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT = (1<<5), + GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT = (1<<6), + GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT = (1<<7), + GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT = (1<<8), + GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT = (1<<9), + GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT = (1<<10), + GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT = (1<<11), + GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT = (1<<12), + GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT = (1<<13), + GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT = (1<<14), + GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT = (1<<15), + GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT = (1<<16), +} GnssMeasurementsStateBits; + +typedef uint16_t GnssSingleSatCorrectionMask; +typedef enum { + GNSS_MEAS_CORR_UNKNOWN_BIT = 0, + GNSS_MEAS_CORR_HAS_SAT_IS_LOS_PROBABILITY_BIT = (1 << 0), + GNSS_MEAS_CORR_HAS_EXCESS_PATH_LENGTH_BIT = (1 << 1), + GNSS_MEAS_CORR_HAS_EXCESS_PATH_LENGTH_UNC_BIT = (1 << 2), + GNSS_MEAS_CORR_HAS_REFLECTING_PLANE_BIT = (1 << 3), +} GnssSingleSatCorrectionBits; + +typedef enum { + GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_UNKNOWN = 0, + GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT, + GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT, +} GnssMeasurementsMultipathIndicator; + +typedef uint32_t GnssMeasurementsClockFlagsMask; +typedef enum { + GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT = (1<<0), + GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_BIT = (1<<1), + GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT = (1<<2), + GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT = (1<<3), + GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT = (1<<4), + GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT = (1<<5), + GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT = (1<<6), + GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT = (1<<7), + GNSS_MEASUREMENTS_CLOCK_FLAGS_HW_CLOCK_DISCONTINUITY_COUNT_BIT = (1<<8), + GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT = (1<<9), +} GnssMeasurementsClockFlagsBits; + +typedef uint32_t GnssAidingDataSvMask; +typedef enum { + GNSS_AIDING_DATA_SV_EPHEMERIS_BIT = (1<<0), // ephemeris + GNSS_AIDING_DATA_SV_ALMANAC_BIT = (1<<1), // almanac + GNSS_AIDING_DATA_SV_HEALTH_BIT = (1<<2), // health + GNSS_AIDING_DATA_SV_DIRECTION_BIT = (1<<3), // direction + GNSS_AIDING_DATA_SV_STEER_BIT = (1<<4), // steer + GNSS_AIDING_DATA_SV_ALMANAC_CORR_BIT = (1<<5), // almanac correction + GNSS_AIDING_DATA_SV_BLACKLIST_BIT = (1<<6), // blacklist SVs + GNSS_AIDING_DATA_SV_SA_DATA_BIT = (1<<7), // sensitivity assistance data + GNSS_AIDING_DATA_SV_NO_EXIST_BIT = (1<<8), // SV does not exist + GNSS_AIDING_DATA_SV_IONOSPHERE_BIT = (1<<9), // ionosphere correction + GNSS_AIDING_DATA_SV_TIME_BIT = (1<<10),// reset satellite time + GNSS_AIDING_DATA_SV_MB_DATA = (1<<11),// delete multiband data + GNSS_AIDING_DATA_SV_POLY_BIT = (1<<12),// poly +} GnssAidingDataSvBits; + +typedef uint32_t GnssAidingDataSvTypeMask; +typedef enum { + GNSS_AIDING_DATA_SV_TYPE_GPS_BIT = (1<<0), + GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT = (1<<1), + GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT = (1<<2), + GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT = (1<<3), + GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT = (1<<4), + GNSS_AIDING_DATA_SV_TYPE_NAVIC_BIT = (1<<5), + GNSS_AIDING_DATA_SV_TYPE_MAX = (1<<6), +} GnssAidingDataSvTypeBits; +#define GNSS_AIDING_DATA_SV_TYPE_MASK_ALL (GNSS_AIDING_DATA_SV_TYPE_MAX-1) + +/* Gnss constellation type mask */ +typedef uint16_t GnssConstellationTypeMask; +typedef enum { + GNSS_CONSTELLATION_TYPE_GPS_BIT = (1<<0), + GNSS_CONSTELLATION_TYPE_GLONASS_BIT = (1<<1), + GNSS_CONSTELLATION_TYPE_QZSS_BIT = (1<<2), + GNSS_CONSTELLATION_TYPE_BEIDOU_BIT = (1<<3), + GNSS_CONSTELLATION_TYPE_GALILEO_BIT = (1<<4), + GNSS_CONSTELLATION_TYPE_SBAS_BIT = (1<<5), + GNSS_CONSTELLATION_TYPE_NAVIC_BIT = (1<<6), +} GnssConstellationTypeBits; + +#define GNSS_CONSTELLATION_TYPE_MASK_ALL\ + (GNSS_CONSTELLATION_TYPE_GPS_BIT | GNSS_CONSTELLATION_TYPE_GLONASS_BIT |\ + GNSS_CONSTELLATION_TYPE_QZSS_BIT | GNSS_CONSTELLATION_TYPE_BEIDOU_BIT |\ + GNSS_CONSTELLATION_TYPE_GALILEO_BIT | GNSS_CONSTELLATION_TYPE_SBAS_BIT |\ + GNSS_CONSTELLATION_TYPE_NAVIC_BIT) + +/** GNSS Signal Type and RF Band */ +typedef uint32_t GnssSignalTypeMask; +typedef enum { + /** GPS L1CA Signal */ + GNSS_SIGNAL_GPS_L1CA = (1<<0), + /** GPS L1C Signal */ + GNSS_SIGNAL_GPS_L1C = (1<<1), + /** GPS L2 RF Band */ + GNSS_SIGNAL_GPS_L2 = (1<<2), + /** GPS L5 RF Band */ + GNSS_SIGNAL_GPS_L5 = (1<<3), + /** GLONASS G1 (L1OF) RF Band */ + GNSS_SIGNAL_GLONASS_G1 = (1<<4), + /** GLONASS G2 (L2OF) RF Band */ + GNSS_SIGNAL_GLONASS_G2 = (1<<5), + /** GALILEO E1 RF Band */ + GNSS_SIGNAL_GALILEO_E1 = (1<<6), + /** GALILEO E5A RF Band */ + GNSS_SIGNAL_GALILEO_E5A = (1<<7), + /** GALILEO E5B RF Band */ + GNSS_SIGNAL_GALILEO_E5B = (1<<8), + /** BEIDOU B1 RF Band */ + GNSS_SIGNAL_BEIDOU_B1 = (1<<9), + /** BEIDOU B2 RF Band */ + GNSS_SIGNAL_BEIDOU_B2 = (1<<10), + /** QZSS L1CA RF Band */ + GNSS_SIGNAL_QZSS_L1CA = (1<<11), + /** QZSS L1S RF Band */ + GNSS_SIGNAL_QZSS_L1S = (1<<12), + /** QZSS L2 RF Band */ + GNSS_SIGNAL_QZSS_L2 = (1<<13), + /** QZSS L5 RF Band */ + GNSS_SIGNAL_QZSS_L5 = (1<<14), + /** SBAS L1 RF Band */ + GNSS_SIGNAL_SBAS_L1 = (1<<15), + /** BEIDOU B1I RF Band */ + GNSS_SIGNAL_BEIDOU_B1I = (1<<16), + /** BEIDOU B1C RF Band */ + GNSS_SIGNAL_BEIDOU_B1C = (1<<17), + /** BEIDOU B2I RF Band */ + GNSS_SIGNAL_BEIDOU_B2I = (1<<18), + /** BEIDOU B2AI RF Band */ + GNSS_SIGNAL_BEIDOU_B2AI = (1<<19), + /** NAVIC L5 RF Band */ + GNSS_SIGNAL_NAVIC_L5 = (1<<20), + /** BEIDOU B2A_Q RF Band */ + GNSS_SIGNAL_BEIDOU_B2AQ = (1<<21), +} GnssSignalTypeBits; + +#define GNSS_SIGNAL_TYPE_MASK_ALL\ + (GNSS_SIGNAL_GPS_L1CA | GNSS_SIGNAL_GPS_L1C | GNSS_SIGNAL_GPS_L2 |\ + GNSS_SIGNAL_GPS_L5| GNSS_SIGNAL_GLONASS_G1 | GNSS_SIGNAL_GLONASS_G2 |\ + GNSS_SIGNAL_GALILEO_E1 | GNSS_SIGNAL_GALILEO_E5A | GNSS_SIGNAL_GALILEO_E5B |\ + GNSS_SIGNAL_BEIDOU_B1I | GNSS_SIGNAL_BEIDOU_B1C | GNSS_SIGNAL_BEIDOU_B2I|\ + GNSS_SIGNAL_BEIDOU_B2AI | GNSS_SIGNAL_QZSS_L1CA | GNSS_SIGNAL_QZSS_L1S |\ + GNSS_SIGNAL_QZSS_L2| GNSS_SIGNAL_QZSS_L5 | GNSS_SIGNAL_SBAS_L1 |\ + GNSS_SIGNAL_NAVIC_L5 | GNSS_SIGNAL_BEIDOU_B2AQ) + +typedef enum +{ + GNSS_LOC_SV_SYSTEM_UNKNOWN = 0, + /** unknown sv system. */ + GNSS_LOC_SV_SYSTEM_MIN = 1, + /**< Min enum of valid SV system. */ + GNSS_LOC_SV_SYSTEM_GPS = 1, + /**< GPS satellite. */ + GNSS_LOC_SV_SYSTEM_GALILEO = 2, + /**< GALILEO satellite. */ + GNSS_LOC_SV_SYSTEM_SBAS = 3, + /**< SBAS satellite. */ + GNSS_LOC_SV_SYSTEM_GLONASS = 4, + /**< GLONASS satellite. */ + GNSS_LOC_SV_SYSTEM_BDS = 5, + /**< BDS satellite. */ + GNSS_LOC_SV_SYSTEM_QZSS = 6, + /**< QZSS satellite. */ + GNSS_LOC_SV_SYSTEM_NAVIC = 7, + /**< NAVIC satellite. */ + GNSS_LOC_SV_SYSTEM_MAX = 7, + /**< Max enum of valid SV system. */ +} Gnss_LocSvSystemEnumType; + +typedef enum { + GNSS_LOC_SIGNAL_TYPE_GPS_L1CA = 0, /**< GPS L1CA Signal */ + GNSS_LOC_SIGNAL_TYPE_GPS_L1C = 1, /**< GPS L1C Signal */ + GNSS_LOC_SIGNAL_TYPE_GPS_L2C_L = 2, /**< GPS L2C_L RF Band */ + GNSS_LOC_SIGNAL_TYPE_GPS_L5_Q = 3, /**< GPS L5_Q RF Band */ + GNSS_LOC_SIGNAL_TYPE_GLONASS_G1 = 4, /**< GLONASS G1 (L1OF) RF Band */ + GNSS_LOC_SIGNAL_TYPE_GLONASS_G2 = 5, /**< GLONASS G2 (L2OF) RF Band */ + GNSS_LOC_SIGNAL_TYPE_GALILEO_E1_C = 6, /**< GALILEO E1_C RF Band */ + GNSS_LOC_SIGNAL_TYPE_GALILEO_E5A_Q = 7, /**< GALILEO E5A_Q RF Band */ + GNSS_LOC_SIGNAL_TYPE_GALILEO_E5B_Q = 8, /**< GALILEO E5B_Q RF Band */ + GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1_I = 9, /**< BEIDOU B1_I RF Band */ + GNSS_LOC_SIGNAL_TYPE_BEIDOU_B1C = 10, /**< BEIDOU B1C RF Band */ + GNSS_LOC_SIGNAL_TYPE_BEIDOU_B2_I = 11, /**< BEIDOU B2_I RF Band */ + GNSS_LOC_SIGNAL_TYPE_BEIDOU_B2A_I = 12, /**< BEIDOU B2A_I RF Band */ + GNSS_LOC_SIGNAL_TYPE_QZSS_L1CA = 13, /**< QZSS L1CA RF Band */ + GNSS_LOC_SIGNAL_TYPE_QZSS_L1S = 14, /**< QZSS L1S RF Band */ + GNSS_LOC_SIGNAL_TYPE_QZSS_L2C_L = 15, /**< QZSS L2C_L RF Band */ + GNSS_LOC_SIGNAL_TYPE_QZSS_L5_Q = 16, /**< QZSS L5_Q RF Band */ + GNSS_LOC_SIGNAL_TYPE_SBAS_L1_CA = 17, /**< SBAS L1_CA RF Band */ + GNSS_LOC_SIGNAL_TYPE_NAVIC_L5 = 18, /**< NAVIC L5 RF Band */ + GNSS_LOC_SIGNAL_TYPE_BEIDOU_B2A_Q = 19, /**< BEIDOU B2A_Q RF Band */ + GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES = 20 /**< Maximum number of signal types */ +} Gnss_LocSignalEnumType; + +typedef uint32_t PositioningEngineMask; +typedef enum { + STANDARD_POSITIONING_ENGINE = (1 << 0), + DEAD_RECKONING_ENGINE = (1 << 1), + PRECISE_POSITIONING_ENGINE = (1 << 2), + VP_POSITIONING_ENGINE = (1 << 3) +} PositioningEngineBits; +#define POSITION_ENGINE_MASK_ALL \ + (STANDARD_POSITIONING_ENGINE|DEAD_RECKONING_ENGINE| \ + PRECISE_POSITIONING_ENGINE|VP_POSITIONING_ENGINE) + +/** Specify the position engine running state.
*/ +enum LocEngineRunState { + /** Request the position engine to be put into resume state. + *
*/ + LOC_ENGINE_RUN_STATE_PAUSE = 1, + /** Request the position engine to be put into resume state. + *
*/ + LOC_ENGINE_RUN_STATE_RESUME = 2, +}; + +typedef uint64_t GnssDataMask; +typedef enum { + // Jammer Indicator is available + GNSS_LOC_DATA_JAMMER_IND_BIT = (1ULL << 0), + // AGC is available + GNSS_LOC_DATA_AGC_BIT = (1ULL << 1) +} GnssDataBits; + +typedef uint32_t GnssSystemTimeStructTypeFlags; +typedef enum { + GNSS_SYSTEM_TIME_WEEK_VALID = (1 << 0), + GNSS_SYSTEM_TIME_WEEK_MS_VALID = (1 << 1), + GNSS_SYSTEM_CLK_TIME_BIAS_VALID = (1 << 2), + GNSS_SYSTEM_CLK_TIME_BIAS_UNC_VALID = (1 << 3), + GNSS_SYSTEM_REF_FCOUNT_VALID = (1 << 4), + GNSS_SYSTEM_NUM_CLOCK_RESETS_VALID = (1 << 5) +} GnssSystemTimeTypeBits; + +typedef uint32_t GnssGloTimeStructTypeFlags; +typedef enum { + GNSS_CLO_DAYS_VALID = (1 << 0), + GNSS_GLO_MSEC_VALID = (1 << 1), + GNSS_GLO_CLK_TIME_BIAS_VALID = (1 << 2), + GNSS_GLO_CLK_TIME_BIAS_UNC_VALID = (1 << 3), + GNSS_GLO_REF_FCOUNT_VALID = (1 << 4), + GNSS_GLO_NUM_CLOCK_RESETS_VALID = (1 << 5), + GNSS_GLO_FOUR_YEAR_VALID = (1 << 6) +} GnssGloTimeTypeBits; + +typedef struct { + GnssAidingDataSvMask svMask; // bitwise OR of GnssAidingDataSvBits + GnssAidingDataSvTypeMask svTypeMask; // bitwise OR of GnssAidingDataSvTypeBits +} GnssAidingDataSv; + +typedef uint32_t GnssAidingDataCommonMask; +typedef enum { + GNSS_AIDING_DATA_COMMON_POSITION_BIT = (1<<0), // position estimate + GNSS_AIDING_DATA_COMMON_TIME_BIT = (1<<1), // reset all clock values + GNSS_AIDING_DATA_COMMON_UTC_BIT = (1<<2), // UTC estimate + GNSS_AIDING_DATA_COMMON_RTI_BIT = (1<<3), // RTI + GNSS_AIDING_DATA_COMMON_FREQ_BIAS_EST_BIT = (1<<4), // frequency bias estimate + GNSS_AIDING_DATA_COMMON_CELLDB_BIT = (1<<5), // all celldb info +} GnssAidingDataCommonBits; + +typedef struct { + GnssAidingDataCommonMask mask; // bitwise OR of GnssAidingDataCommonBits +} GnssAidingDataCommon; + +typedef uint32_t DrEngineAidingDataMask; +typedef enum { + DR_ENGINE_AIDING_DATA_CALIBRATION_BIT = (1<<0), // Calibration data for DRE engine +} DrEngineAidingDataBits; + +typedef struct { + bool deleteAll; // if true, delete all aiding data and ignore other params + GnssAidingDataSv sv; // SV specific aiding data + GnssAidingDataCommon common; // common aiding data + DrEngineAidingDataMask dreAidingDataMask;// aiding data mask for dr engine + PositioningEngineMask posEngineMask; // engines to perform the delete operation on. +} GnssAidingData; + +typedef uint16_t DrCalibrationStatusMask; +typedef enum { + // Indicate that roll calibration is needed. Need to take more turns on level ground + DR_ROLL_CALIBRATION_NEEDED = (1<<0), + // Indicate that pitch calibration is needed. Need to take more turns on level ground + DR_PITCH_CALIBRATION_NEEDED = (1<<1), + // Indicate that yaw calibration is needed. Need to accelerate in a straight line + DR_YAW_CALIBRATION_NEEDED = (1<<2), + // Indicate that odo calibration is needed. Need to accelerate in a straight line + DR_ODO_CALIBRATION_NEEDED = (1<<3), + // Indicate that gyro calibration is needed. Need to take more turns on level ground + DR_GYRO_CALIBRATION_NEEDED = (1<<4) +} DrCalibrationStatusBits; + +typedef struct { + uint32_t size; // set to sizeof(Location) + LocationFlagsMask flags; // bitwise OR of LocationFlagsBits to mark which params are valid + uint64_t timestamp; // UTC timestamp for location fix, milliseconds since January 1, 1970 + double latitude; // in degrees + double longitude; // in degrees + double altitude; // in meters above the WGS 84 reference ellipsoid + float speed; // in meters per second + float bearing; // in degrees; range [0, 360) + float accuracy; // in meters + float verticalAccuracy; // in meters + float speedAccuracy; // in meters/second + float bearingAccuracy; // in degrees (0 to 359.999) + float conformityIndex; // in range [0, 1] + LocationTechnologyMask techMask; + LocationSpoofMask spoofMask; + uint64_t elapsedRealTime; // in ns + uint64_t elapsedRealTimeUnc; // in ns +} Location; + +typedef enum { + LOC_REQ_ENGINE_FUSED_BIT = (1<<0), + LOC_REQ_ENGINE_SPE_BIT = (1<<1), + LOC_REQ_ENGINE_PPE_BIT = (1<<2), + LOC_REQ_ENGINE_VPE_BIT = (1<<3) +} LocReqEngineTypeMask; + +typedef enum { + LOC_OUTPUT_ENGINE_FUSED = 0, + /** This is the GNSS fix from modem */ + LOC_OUTPUT_ENGINE_SPE = 1, + /** This is the GNSS fix with correction PPP/RTK correction */ + LOC_OUTPUT_ENGINE_PPE = 2, + LOC_OUTPUT_ENGINE_VPE = 3, + LOC_OUTPUT_ENGINE_COUNT, +} LocOutputEngineType; + +struct LocationOptions { + uint32_t size; // set to sizeof(LocationOptions) + uint32_t minInterval; // in milliseconds + uint32_t minDistance; // in meters. if minDistance > 0, gnssSvCallback/gnssNmeaCallback/ + // gnssMeasurementsCallback may not be called + GnssSuplMode mode; // Standalone/MS-Based/MS-Assisted + // behavior when this field is 0: + // if engine hub is running, this will be fused fix, + // if engine hub is not running, this will be SPE fix + LocReqEngineTypeMask locReqEngTypeMask; + + inline LocationOptions() : + size(0), minInterval(0), minDistance(0), mode(GNSS_SUPL_MODE_STANDALONE), + locReqEngTypeMask((LocReqEngineTypeMask)0) {} +}; + +typedef enum { + GNSS_POWER_MODE_INVALID = 0, + GNSS_POWER_MODE_M1, /* Improved Accuracy Mode */ + GNSS_POWER_MODE_M2, /* Normal Mode */ + GNSS_POWER_MODE_M3, /* Background Mode */ + GNSS_POWER_MODE_M4, /* Background Mode */ + GNSS_POWER_MODE_M5 /* Background Mode */ +} GnssPowerMode; + +struct TrackingOptions : LocationOptions { + GnssPowerMode powerMode; /* Power Mode to be used for time based tracking + sessions */ + uint32_t tbm; /* Time interval between measurements specified in millis. + Applicable to background power modes */ + + inline TrackingOptions() : + LocationOptions(), powerMode(GNSS_POWER_MODE_INVALID), tbm(0) {} + inline TrackingOptions(uint32_t s, GnssPowerMode m, uint32_t t) : + LocationOptions(), powerMode(m), tbm(t) { LocationOptions::size = s; } + inline TrackingOptions(const LocationOptions& options) : + LocationOptions(options), powerMode(GNSS_POWER_MODE_INVALID), tbm(0) {} + inline void setLocationOptions(const LocationOptions& options) { + size = sizeof(TrackingOptions); + minInterval = options.minInterval; + minDistance = options.minDistance; + mode = options.mode; + locReqEngTypeMask = options.locReqEngTypeMask; + } + inline LocationOptions getLocationOptions() { + LocationOptions locOption; + locOption.size = sizeof(locOption); + locOption.minDistance = minDistance; + locOption.minInterval = minInterval; + locOption.mode = mode; + locOption.locReqEngTypeMask = locReqEngTypeMask; + return locOption; + } +}; + +struct BatchingOptions : LocationOptions { + BatchingMode batchingMode; + + inline BatchingOptions() : + LocationOptions(), batchingMode(BATCHING_MODE_ROUTINE) {} + inline BatchingOptions(uint32_t s, BatchingMode m) : + LocationOptions(), batchingMode(m) { LocationOptions::size = s; } + inline BatchingOptions(const LocationOptions& options) : + LocationOptions(options), batchingMode(BATCHING_MODE_ROUTINE) {} + inline void setLocationOptions(const LocationOptions& options) { + minInterval = options.minInterval; + minDistance = options.minDistance; + mode = options.mode; + } +}; + +typedef struct { + uint32_t size; + BatchingStatus batchingStatus; +} BatchingStatusInfo; + +typedef struct { + uint32_t size; // set to sizeof(GeofenceOption) + GeofenceBreachTypeMask breachTypeMask; // bitwise OR of GeofenceBreachTypeBits + uint32_t responsiveness; // in milliseconds + uint32_t dwellTime; // in seconds +} GeofenceOption; + +typedef struct { + uint32_t size; // set to sizeof(GeofenceInfo) + double latitude; // in degrees + double longitude; // in degrees + double radius; // in meters +} GeofenceInfo; + +typedef struct { + uint32_t size; // set to sizeof(GeofenceBreachNotification) + uint32_t count; // number of ids in array + uint32_t* ids; // array of ids that have breached + Location location; // location associated with breach + GeofenceBreachType type; // type of breach + uint64_t timestamp; // timestamp of breach +} GeofenceBreachNotification; + +typedef struct { + uint32_t size; // set to sizeof(GeofenceBreachNotification) + GeofenceStatusAvailable available; // GEOFENCE_STATUS_AVAILABILE_NO/_YES + LocationTechnologyType techType; // GNSS +} GeofenceStatusNotification; + +typedef struct { + uint64_t gpsSvUsedIdsMask; + uint64_t gloSvUsedIdsMask; + uint64_t galSvUsedIdsMask; + uint64_t bdsSvUsedIdsMask; + uint64_t qzssSvUsedIdsMask; + uint64_t navicSvUsedIdsMask; +} GnssLocationSvUsedInPosition; + +typedef struct { + /** GnssSignalType mask */ + GnssSignalTypeMask gnssSignalType; + /** Specifies GNSS Constellation Type */ + Gnss_LocSvSystemEnumType gnssConstellation; + /** Unique SV Identifier. + * For SV Range of supported constellation, please refer to + * the comment section of svId in GnssSv. + * For GLONASS: When slot-number to SV ID mapping is unknown, set as 255. + */ + uint16_t gnssSvId; +} GnssMeasUsageInfo; + +/** @struct + Body Frame parameters +*/ +typedef struct { + GnssLocationPosDataMask bodyFrameDataMask; // Contains Body frame LocPosDataMask bits + float longAccel; // Forward Acceleration in body frame (m/s2) + float latAccel; // Sideward Acceleration in body frame (m/s2) + float vertAccel; // Vertical Acceleration in body frame (m/s2) + float yawRate; // Heading Rate (Radians/second) + float pitch; // Body pitch (Radians) + float longAccelUnc; // Uncertainty of Forward Acceleration in body frame + float latAccelUnc; // Uncertainty of Side-ward Acceleration in body frame + float vertAccelUnc; // Uncertainty of Vertical Acceleration in body frame + float yawRateUnc; // Uncertainty of Heading Rate + float pitchUnc; // Uncertainty of Body pitch +} GnssLocationPositionDynamics; + +typedef struct { + GnssLocationPosDataMaskExt bodyFrameDataMask; // Contains Ext Body frame LocPosDataMask bits + float pitchRate; // Body pitch rate (Radians/second) + float pitchRateUnc; // Uncertainty of pitch rate (Radians/second) + float roll; // Roll of body frame. Clockwise positive. (radian + float rollUnc; // Uncertainty of Roll, 68% confidence level (radian) + float rollRate; // Roll rate of body frame. Clockwise positive. (radian/second) + float rollRateUnc; // Uncertainty of Roll rate, 68% confidence level (radian/second) + float yaw; // Yaw of body frame. Clockwise positive (radian) + float yawUnc; // Uncertainty of Yaw, 68% confidence level (radian) +} GnssLocationPositionDynamicsExt; + +typedef struct { + /** Validity mask for below fields */ + GnssSystemTimeStructTypeFlags validityMask; + /** Extended week number at reference tick. + Unit: Week. + Set to 65535 if week number is unknown. + For GPS: + Calculated from midnight, Jan. 6, 1980. + OTA decoded 10 bit GPS week is extended to map between: + [NV6264 to (NV6264 + 1023)]. + NV6264: Minimum GPS week number configuration. + Default value of NV6264: 1738 + For BDS: + Calculated from 00:00:00 on January 1, 2006 of Coordinated Universal Time (UTC). + For GAL: + Calculated from 00:00 UT on Sunday August 22, 1999 (midnight between August 21 and August 22). + */ + uint16_t systemWeek; + /** Time in to the current week at reference tick. + Unit: Millisecond. Range: 0 to 604799999. + Check for systemClkTimeUncMs before use */ + uint32_t systemMsec; + /** System clock time bias (sub-millisecond) + Units: Millisecond + Note: System time (TOW Millisecond) = systemMsec - systemClkTimeBias. + Check for systemClkTimeUncMs before use. */ + float systemClkTimeBias; + /** Single sided maximum time bias uncertainty + Units: Millisecond */ + float systemClkTimeUncMs; + /** FCount (free running HW timer) value. Don't use for relative time purpose + due to possible discontinuities. + Unit: Millisecond */ + uint32_t refFCount; + /** Number of clock resets/discontinuities detected, affecting the local hardware counter value. */ + uint32_t numClockResets; +} GnssSystemTimeStructType; + +typedef struct { + /** GLONASS day number in four years. Refer to GLONASS ICD. + Applicable only for GLONASS and shall be ignored for other constellations. + If unknown shall be set to 65535 */ + uint16_t gloDays; + /** Validity mask for below fields */ + GnssGloTimeStructTypeFlags validityMask; + /** GLONASS time of day in Millisecond. Refer to GLONASS ICD. + Units: Millisecond + Check for gloClkTimeUncMs before use */ + uint32_t gloMsec; + /** GLONASS clock time bias (sub-millisecond) + Units: Millisecond + Note: GLO time (TOD Millisecond) = gloMsec - gloClkTimeBias. + Check for gloClkTimeUncMs before use. */ + float gloClkTimeBias; + /** Single sided maximum time bias uncertainty + Units: Millisecond */ + float gloClkTimeUncMs; + /** FCount (free running HW timer) value. Don't use for relative time purpose + due to possible discontinuities. + Unit: Millisecond */ + uint32_t refFCount; + /** Number of clock resets/discontinuities detected, affecting the local hardware counter value. */ + uint32_t numClockResets; + /** GLONASS four year number from 1996. Refer to GLONASS ICD. + Applicable only for GLONASS and shall be ignored for other constellations. + If unknown shall be set to 255 */ + uint8_t gloFourYear; +} GnssGloTimeStructType; + +typedef union { + GnssSystemTimeStructType gpsSystemTime; + GnssSystemTimeStructType galSystemTime; + GnssSystemTimeStructType bdsSystemTime; + GnssSystemTimeStructType qzssSystemTime; + GnssGloTimeStructType gloSystemTime; + GnssSystemTimeStructType navicSystemTime; +} SystemTimeStructUnion; + /** Time applicability of PVT report */ +typedef struct { + /** Specifies GNSS system time reported. Mandatory field */ + Gnss_LocSvSystemEnumType gnssSystemTimeSrc; + /** Reporting of GPS system time is recommended. + If GPS time is unknown & other satellite system time is known, + it should be reported. + Mandatory field + */ + SystemTimeStructUnion u; +} GnssSystemTime; + +typedef uint32_t DrSolutionStatusMask; +#define VEHICLE_SENSOR_SPEED_INPUT_DETECTED (1<<0) +#define VEHICLE_SENSOR_SPEED_INPUT_USED (1<<1) + +typedef struct { + double latitude; // in degree + double longitude; // in degree + float altitude; // altitude wrt to ellipsoid +} LLAInfo; + +enum loc_sess_status { + LOC_SESS_SUCCESS, + LOC_SESS_INTERMEDIATE, + LOC_SESS_FAILURE +}; + +typedef struct { + uint32_t size; // set to sizeof(GnssLocationInfo) + Location location; // basic locaiton info, latitude, longitude, and etc + GnssLocationInfoFlagMask flags; // bitwise OR of GnssLocationInfoBits for param validity + float altitudeMeanSeaLevel; // altitude wrt mean sea level + float pdop; // position dilusion of precision + float hdop; // horizontal dilusion of precision + float vdop; // vertical dilusion of precision + float gdop; // geometric dilution of precision + float tdop; // time dilution of precision + float magneticDeviation; // magnetic deviation + LocationReliability horReliability; // horizontal reliability + LocationReliability verReliability; // vertical reliability + float horUncEllipseSemiMajor; // horizontal elliptical accuracy semi-major axis + float horUncEllipseSemiMinor; // horizontal elliptical accuracy semi-minor axis + float horUncEllipseOrientAzimuth; // horizontal elliptical accuracy azimuth + float northStdDeviation; // North standard deviation Unit: Meters + float eastStdDeviation; // East standard deviation. Unit: Meters + float northVelocity; // North Velocity.Unit: Meters/sec + float eastVelocity; // East Velocity Unit Meters/sec + float upVelocity; // Up Velocity. Unit Meters/sec + float northVelocityStdDeviation; + float eastVelocityStdDeviation; + float upVelocityStdDeviation; + uint16_t numSvUsedInPosition; + GnssLocationSvUsedInPosition svUsedInPosition;// Gnss sv used in position data + GnssLocationNavSolutionMask navSolutionMask; // Nav solution mask to indicate sbas corrections + GnssLocationPositionDynamics bodyFrameData; // Body Frame Dynamics: 4wayAcceleration and + // pitch set with validity + GnssSystemTime gnssSystemTime; // GNSS System Time + uint8_t numOfMeasReceived; // Number of measurements received for use in fix. + GnssMeasUsageInfo measUsageInfo[GNSS_SV_MAX]; // GNSS Measurement Usage info + uint8_t leapSeconds; // leap second + float timeUncMs; // Time uncertainty in milliseconds + uint8_t calibrationConfidence; // Sensor calibration confidence percent, + // in range of [0, 100] + DrCalibrationStatusMask calibrationStatus; // Sensor calibration status + // location engine type. When the fix. when the type is set to + // LOC_ENGINE_SRC_FUSED, the fix is the propagated/aggregated + // reports from all engines running on the system (e.g.: + // DR/SPE/PPE/VPE). To check which location engine contributes to + // the fused output, check for locOutputEngMask. + LocOutputEngineType locOutputEngType; + // when loc output eng type is set to fused, this field + // indicates the set of engines contribute to the fix. + PositioningEngineMask locOutputEngMask; + // When robust location is enabled, this field + // will how well the various input data considered for + // navigation solution conform to expectations. + // Range: 0 (least conforming) to 1 (most conforming) + float conformityIndex; + GnssLocationPositionDynamicsExt bodyFrameDataExt; // Additional Body Frame Dynamics + // VRR-based latitude/longitude/altitude + LLAInfo llaVRPBased; + // VRR-based east, north, and up velocity + float enuVelocityVRPBased[3]; + DrSolutionStatusMask drSolutionStatusMask; + // true: altitude is assumed, false: altitude is calculated + bool altitudeAssumed; + // location session status + loc_sess_status sessionStatus; +} GnssLocationInfoNotification; + +typedef struct { + uint32_t size; // set to sizeof(GnssNiNotification) + GnssNiType type; // type of NI (Voice, SUPL, Control Plane) + GnssNiOptionsMask options; // bitwise OR of GnssNiOptionsBits + uint32_t timeout; // time (seconds) to wait for user input + GnssNiResponse timeoutResponse; // the response that should be sent when timeout expires + char requestor[GNSS_NI_REQUESTOR_MAX]; // the requestor that is making the request + GnssNiEncodingType requestorEncoding; // the encoding type for requestor + char message[GNSS_NI_MESSAGE_ID_MAX]; // the message to show user + GnssNiEncodingType messageEncoding; // the encoding type for message + char extras[GNSS_NI_MESSAGE_ID_MAX]; +} GnssNiNotification; + +// carrier frequency of the signal tracked +#define GPS_L1CA_CARRIER_FREQUENCY (1575420000.0) +#define GPS_L1C_CARRIER_FREQUENCY (1575420000.0) +#define GPS_L2C_L_CARRIER_FREQUENCY (1227600000.0) +#define GPS_L5_Q_CARRIER_FREQUENCY (1176450000.0) +#define GLONASS_G1_CARRIER_FREQUENCY (1602000000.0) +#define GLONASS_G2_CARRIER_FREQUENCY (1246000000.0) +#define GALILEO_E1_C_CARRIER_FREQUENCY (1575420000.0) +#define GALILEO_E5A_Q_CARRIER_FREQUENCY (1176450000.0) +#define GALILEO_E5B_Q_CARRIER_FREQUENCY (1207140000.0) +#define BEIDOU_B1_I_CARRIER_FREQUENCY (1561098000.0) +#define BEIDOU_B1C_CARRIER_FREQUENCY (1575420000.0) +#define BEIDOU_B2_I_CARRIER_FREQUENCY (1207140000.0) +#define BEIDOU_B2A_I_CARRIER_FREQUENCY (1176450000.0) +#define BEIDOU_B2A_Q_CARRIER_FREQUENCY (1176450000.0) +#define QZSS_L1CA_CARRIER_FREQUENCY (1575420000.0) +#define QZSS_L1S_CARRIER_FREQUENCY (1575420000.0) +#define QZSS_L2C_L_CARRIER_FREQUENCY (1227600000.0) +#define QZSS_L5_Q_CARRIER_FREQUENCY (1176450000.0) +#define SBAS_L1_CA_CARRIER_FREQUENCY (1575420000.0) +#define NAVIC_L5_CARRIER_FREQUENCY (1176450000.0) + +typedef struct { + uint32_t size; // set to sizeof(GnssSv) + // Unique SV Identifier. + // SV Range for supported constellation is specified as below: + // - For GPS: 1 to 32 + // - For GLONASS: 65 to 96 + // - For SBAS: 120 to 158 and 183 to 191 + // - For QZSS: 193 to 197 + // - For BDS: 201 to 263 + // - For GAL: 301 to 336 + // - For NAVIC: 401 to 414 + uint16_t svId; + GnssSvType type; // type of SV (GPS, SBAS, GLONASS, QZSS, BEIDOU, GALILEO, NAVIC) + float cN0Dbhz; // signal strength + float elevation; // elevation of SV (in degrees) + float azimuth; // azimuth of SV (in degrees) + GnssSvOptionsMask gnssSvOptionsMask; // Bitwise OR of GnssSvOptionsBits + float carrierFrequencyHz; // carrier frequency of the signal tracked + GnssSignalTypeMask gnssSignalTypeMask; // Specifies GNSS signal type + double basebandCarrierToNoiseDbHz; // baseband signal strength + uint16_t gloFrequency; // GLONASS Frequency channel number +} GnssSv; + +struct GnssConfigSetAssistanceServer { + uint32_t size; // set to sizeof(GnssConfigSetAssistanceServer) + GnssAssistanceType type; // SUPL or C2K + const char* hostName; // null terminated string + uint32_t port; // port of server + + inline bool equals(const GnssConfigSetAssistanceServer& config) { + if (config.type == type && config.port == port && + ((NULL == config.hostName && NULL == hostName) || + (NULL != config.hostName && NULL != hostName && + 0 == strcmp(config.hostName, hostName)))) { + return true; + } + return false; + } +}; + +typedef struct { + // set to sizeof(GnssMeasurementsData) + uint32_t size; + // bitwise OR of GnssMeasurementsDataFlagsBits + GnssMeasurementsDataFlagsMask flags; + // Unique SV Identifier + // For SV Range of supported constellation, + // please refer to the comment section of svId in GnssSv. + int16_t svId; + GnssSvType svType; + double timeOffsetNs; + GnssMeasurementsStateMask stateMask; // bitwise OR of GnssMeasurementsStateBits + int64_t receivedSvTimeNs; + int64_t receivedSvTimeUncertaintyNs; + double carrierToNoiseDbHz; + double pseudorangeRateMps; + double pseudorangeRateUncertaintyMps; + GnssMeasurementsAdrStateMask adrStateMask; // bitwise OR of GnssMeasurementsAdrStateBits + double adrMeters; + double adrUncertaintyMeters; + float carrierFrequencyHz; + int64_t carrierCycles; + double carrierPhase; + double carrierPhaseUncertainty; + GnssMeasurementsMultipathIndicator multipathIndicator; + double signalToNoiseRatioDb; + double agcLevelDb; + GnssMeasurementsCodeType codeType; + char otherCodeTypeName[GNSS_MAX_NAME_LENGTH]; + double basebandCarrierToNoiseDbHz; + GnssSignalTypeMask gnssSignalType; + double fullInterSignalBiasNs; + double fullInterSignalBiasUncertaintyNs; + double satelliteInterSignalBiasNs; + double satelliteInterSignalBiasUncertaintyNs; + int16_t gloFrequency; + uint8_t cycleSlipCount; +} GnssMeasurementsData; + +typedef struct { + GnssSvType svType; + float carrierFrequencyHz; + GnssMeasurementsCodeType codeType; + char otherCodeTypeName[GNSS_MAX_NAME_LENGTH]; +} GnssMeasurementsSignalType; + +typedef struct { + uint32_t size; // set to sizeof(GnssReflectingPlane) + double latitudeDegrees; + double longitudeDegrees; + double altitudeMeters; + double azimuthDegrees; +} GnssReflectingPlane; + +typedef struct { + uint32_t size; // set to sizeof(GnssSingleSatCorrection) + GnssSingleSatCorrectionMask flags; + GnssSvType svType; + uint16_t svId; + float carrierFrequencyHz; + float probSatIsLos; + float excessPathLengthMeters; + float excessPathLengthUncertaintyMeters; + GnssReflectingPlane reflectingPlane; +} GnssSingleSatCorrection; + +typedef struct { + uint32_t size; // set to sizeof(GnssMeasurementCorrections) + double latitudeDegrees; + double longitudeDegrees; + double altitudeMeters; + double horizontalPositionUncertaintyMeters; + double verticalPositionUncertaintyMeters; + uint64_t toaGpsNanosecondsOfWeek; + std::vector satCorrections; + bool hasEnvironmentBearing; + float environmentBearingDegrees; + float environmentBearingUncertaintyDegrees; +} GnssMeasurementCorrections; + +typedef struct { + uint32_t size; // set to sizeof(GnssMeasurementsClock) + GnssMeasurementsClockFlagsMask flags; // bitwise OR of GnssMeasurementsClockFlagsBits + int16_t leapSecond; + int64_t timeNs; + double timeUncertaintyNs; + int64_t fullBiasNs; + double biasNs; + double biasUncertaintyNs; + double driftNsps; + double driftUncertaintyNsps; + uint32_t hwClockDiscontinuityCount; + GnssMeasurementsSignalType referenceSignalTypeForIsb; + uint64_t elapsedRealTime; // in ns + uint64_t elapsedRealTimeUnc; // in ns +} GnssMeasurementsClock; + +typedef struct { + uint32_t size; // set to sizeof(GnssSvNotification) + uint32_t count; // number of SVs in the GnssSv array + bool gnssSignalTypeMaskValid; + GnssSv gnssSvs[GNSS_SV_MAX]; // information on a number of SVs +} GnssSvNotification; + +typedef struct { + uint32_t size; // set to sizeof(GnssNmeaNotification) + uint64_t timestamp; // timestamp + const char* nmea; // nmea text + uint32_t length; // length of the nmea text +} GnssNmeaNotification; + +typedef struct { + uint32_t size; // set to sizeof(GnssDataNotification) + GnssDataMask gnssDataMask[GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES]; // bitwise OR of GnssDataBits + double jammerInd[GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES]; // Jammer Indication + double agc[GNSS_LOC_MAX_NUMBER_OF_SIGNAL_TYPES]; // Automatic gain control +} GnssDataNotification; + +typedef struct { + uint32_t size; // set to sizeof(GnssMeasurementsNotification) + uint32_t count; // number of items in GnssMeasurements array + GnssMeasurementsData measurements[GNSS_MEASUREMENTS_MAX]; + GnssMeasurementsClock clock; // clock +} GnssMeasurementsNotification; + +typedef uint32_t GnssSvId; + +struct GnssSvIdSource{ + uint32_t size; // set to sizeof(GnssSvIdSource) + GnssSvType constellation; // constellation for the sv to blacklist + GnssSvId svId; // Unique SV Identifier, + // For SV Range of supported constellation, + // please refer to the comment section of svId in GnssSv. +}; +inline bool operator ==(GnssSvIdSource const& left, GnssSvIdSource const& right) { + return left.size == right.size && + left.constellation == right.constellation && left.svId == right.svId; +} + +#define GNSS_SV_CONFIG_ALL_BITS_ENABLED_MASK ((uint64_t)0xFFFFFFFFFFFFFFFF) +struct GnssSvIdConfig { + uint32_t size; // set to sizeof(GnssSvIdConfig) + + // GLONASS - SV 65 maps to bit 0 +#define GNSS_SV_CONFIG_GLO_INITIAL_SV_ID 65 + uint64_t gloBlacklistSvMask; + + // BEIDOU - SV 201 maps to bit 0 +#define GNSS_SV_CONFIG_BDS_INITIAL_SV_ID 201 + uint64_t bdsBlacklistSvMask; + + // QZSS - SV 193 maps to bit 0 +#define GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID 193 + uint64_t qzssBlacklistSvMask; + + // GAL - SV 301 maps to bit 0 +#define GNSS_SV_CONFIG_GAL_INITIAL_SV_ID 301 + uint64_t galBlacklistSvMask; + + // SBAS - SV 120 to 158, maps to 0 to 38 + // SV 183 to 191, maps to 39 to 47 +#define GNSS_SV_CONFIG_SBAS_INITIAL_SV_ID 120 +#define GNSS_SV_CONFIG_SBAS_INITIAL_SV_LENGTH 39 +#define GNSS_SV_CONFIG_SBAS_INITIAL2_SV_ID 183 + uint64_t sbasBlacklistSvMask; + + //Navic - SV 401 maps to bit 0 +#define GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID 401 + uint64_t navicBlacklistSvMask; + + inline bool equals(const GnssSvIdConfig& inConfig) { + if ((inConfig.size == size) && + (inConfig.gloBlacklistSvMask == gloBlacklistSvMask) && + (inConfig.bdsBlacklistSvMask == bdsBlacklistSvMask) && + (inConfig.qzssBlacklistSvMask == qzssBlacklistSvMask) && + (inConfig.galBlacklistSvMask == galBlacklistSvMask) && + (inConfig.sbasBlacklistSvMask == sbasBlacklistSvMask) && + (inConfig.navicBlacklistSvMask == navicBlacklistSvMask)) { + return true; + } else { + return false; + } + } +}; + +// Specify the valid mask for robust location configure +// defined in GnssConfigRobustLocation. +enum GnssConfigRobustLocationValidMask { + // GnssConfigRobustLocation has valid enabled field. + GNSS_CONFIG_ROBUST_LOCATION_ENABLED_VALID_BIT = (1<<0), + // GnssConfigRobustLocation has valid enabledForE911 field. + GNSS_CONFIG_ROBUST_LOCATION_ENABLED_FOR_E911_VALID_BIT = (1<<1), + // GnssConfigRobustLocation has valid version field. + GNSS_CONFIG_ROBUST_LOCATION_VERSION_VALID_BIT = (1<<2), +}; + +struct GnssConfigRobustLocationVersion { + // Major version number + uint8_t major; + // Minor version number + uint16_t minor; + inline bool equals(const GnssConfigRobustLocationVersion& version) const { + return (version.major == major && version.minor == minor); + } +}; + +// specify the robust location configuration used by modem GNSS engine +struct GnssConfigRobustLocation { + GnssConfigRobustLocationValidMask validMask; + bool enabled; + bool enabledForE911; + GnssConfigRobustLocationVersion version; + + inline bool equals(const GnssConfigRobustLocation& config) const { + if (config.validMask == validMask && + config.enabled == enabled && + config.enabledForE911 == enabledForE911 && + config.version.equals(version)) { + return true; + } + return false; + } +}; + +/* Mask indicating enabled or disabled constellations and + secondary frequency.*/ +typedef uint64_t GnssSvTypesMask; +typedef enum { + GNSS_SV_TYPES_MASK_GLO_BIT = (1<<0), + GNSS_SV_TYPES_MASK_BDS_BIT = (1<<1), + GNSS_SV_TYPES_MASK_QZSS_BIT = (1<<2), + GNSS_SV_TYPES_MASK_GAL_BIT = (1<<3), + GNSS_SV_TYPES_MASK_NAVIC_BIT = (1<<4), + GNSS_SV_TYPES_MASK_GPS_BIT = (1<<5), +} GnssSvTypesMaskBits; +#define GNSS_SV_TYPES_MASK_ALL \ + (GNSS_SV_TYPES_MASK_GPS_BIT|GNSS_SV_TYPES_MASK_GLO_BIT|GNSS_SV_TYPES_MASK_BDS_BIT|\ + GNSS_SV_TYPES_MASK_QZSS_BIT|GNSS_SV_TYPES_MASK_GAL_BIT|GNSS_SV_TYPES_MASK_NAVIC_BIT) + +/* This SV Type config is injected directly to GNSS Adapter + * bypassing Location API */ +struct GnssSvTypeConfig{ + uint32_t size; // set to sizeof(GnssSvTypeConfig) + // Enabled Constellations + GnssSvTypesMask enabledSvTypesMask; + // Disabled Constellations + GnssSvTypesMask blacklistedSvTypesMask; + + inline bool equals (const GnssSvTypeConfig& inConfig) const { + return ((inConfig.size == size) && + (inConfig.enabledSvTypesMask == enabledSvTypesMask) && + (inConfig.blacklistedSvTypesMask == blacklistedSvTypesMask)); + } +}; + +struct GnssConfig{ + uint32_t size; // set to sizeof(GnssConfig) + GnssConfigFlagsMask flags; // bitwise OR of GnssConfigFlagsBits to mark which params are valid + GnssConfigGpsLock gpsLock; + GnssConfigSuplVersion suplVersion; + GnssConfigSetAssistanceServer assistanceServer; + GnssConfigLppProfileMask lppProfileMask; + GnssConfigLppeControlPlaneMask lppeControlPlaneMask; + GnssConfigLppeUserPlaneMask lppeUserPlaneMask; + GnssConfigAGlonassPositionProtocolMask aGlonassPositionProtocolMask; + GnssConfigEmergencyPdnForEmergencySupl emergencyPdnForEmergencySupl; + GnssConfigSuplEmergencyServices suplEmergencyServices; + GnssConfigSuplModeMask suplModeMask; //bitwise OR of GnssConfigSuplModeBits + std::vector blacklistedSvIds; + uint32_t emergencyExtensionSeconds; + GnssConfigRobustLocation robustLocationConfig; + uint16_t minGpsWeek; + uint8_t minSvElevation; + GnssSvTypeConfig secondaryBandConfig; + + inline bool equals(const GnssConfig& config) { + if (flags == config.flags && + gpsLock == config.gpsLock && + suplVersion == config.suplVersion && + assistanceServer.equals(config.assistanceServer) && + lppProfileMask == config.lppProfileMask && + lppeControlPlaneMask == config.lppeControlPlaneMask && + lppeUserPlaneMask == config.lppeUserPlaneMask && + aGlonassPositionProtocolMask == config.aGlonassPositionProtocolMask && + emergencyPdnForEmergencySupl == config.emergencyPdnForEmergencySupl && + suplEmergencyServices == config.suplEmergencyServices && + suplModeMask == config.suplModeMask && + blacklistedSvIds == config.blacklistedSvIds && + emergencyExtensionSeconds == config.emergencyExtensionSeconds && + robustLocationConfig.equals(config.robustLocationConfig) && + minGpsWeek == config.minGpsWeek && + minSvElevation == config.minSvElevation && + secondaryBandConfig.equals(config.secondaryBandConfig)) { + return true; + } + return false; + } +}; + +typedef struct { + uint32_t size; // set to sizeof + bool mValid; + Location mLocation; + double verticalAccuracyMeters; + double speedAccuracyMetersPerSecond; + double bearingAccuracyDegrees; + timespec mUtcReported; +} GnssDebugLocation; + +typedef struct { + uint32_t size; // set to sizeof + bool mValid; + int64_t timeEstimate; + float timeUncertaintyNs; + float frequencyUncertaintyNsPerSec; +} GnssDebugTime; + +typedef struct { + // set to sizeof + uint32_t size; + // Unique SV Identifier + // For SV Range of supported constellation, + // please refer to the comment section of svId in GnssSv. + uint32_t svid; + GnssSvType constellation; + GnssEphemerisType mEphemerisType; + GnssEphemerisSource mEphemerisSource; + GnssEphemerisHealth mEphemerisHealth; + float ephemerisAgeSeconds; + bool serverPredictionIsAvailable; + float serverPredictionAgeSeconds; +} GnssDebugSatelliteInfo; + +typedef struct { + uint32_t size; // set to sizeof + GnssDebugLocation mLocation; + GnssDebugTime mTime; + std::vector mSatelliteInfo; +} GnssDebugReport; + +typedef uint32_t LeapSecondSysInfoMask; +typedef enum { + // current leap second info is available. This info will only + // be available if the leap second change info is not available. + // + // If leap second change info is avaiable, to figure out + // the current leap second info, compare current gps time with + // the gps timestamp of leap second change to know whether to choose + // leapSecondBefore or leapSecondAfter as current leap second. + LEAP_SECOND_SYS_INFO_CURRENT_LEAP_SECONDS_BIT = (1ULL << 0), + // the last known leap change event is available. + // The info can be available on two scenario: + // 1: this leap second change event has been scheduled and yet to happen + // 2: this leap second change event has already happened and next + // leap second change event has not yet been scheduled. + LEAP_SECOND_SYS_INFO_LEAP_SECOND_CHANGE_BIT = (1ULL << 1), +} LeapSecondSysInfoDataBits; + +struct LeapSecondChangeInfo { + // GPS timestamp that corrresponds to the last known + // leap second change event. + // + // The info can be available on two scenario: + // 1: this leap second change event has been scheduled and yet to happen + // 2: this leap second change event has already happened and next + // leap second change event has not yet been scheduled. + GnssSystemTimeStructType gpsTimestampLsChange; + // Number of leap seconds prior to the leap second change event + // that corresponds to the timestamp at gpsTimestampLsChange. + uint8_t leapSecondsBeforeChange; + // Number of leap seconds after the leap second change event + // that corresponds to the timestamp at gpsTimestampLsChange. + uint8_t leapSecondsAfterChange; +}; + +struct LeapSecondSystemInfo { + LeapSecondSysInfoMask leapSecondInfoMask; + uint8_t leapSecondCurrent; + LeapSecondChangeInfo leapSecondChangeInfo; +}; + +typedef uint32_t LocationSystemInfoMask; +typedef enum { + // contains current leap second or leap second change info + LOCATION_SYS_INFO_LEAP_SECOND = (1ULL << 0), +} LocationSystemInfoDataBits; + +struct LocationSystemInfo { + LocationSystemInfoMask systemInfoMask; + LeapSecondSystemInfo leapSecondSysInfo; +}; + +// Specify the set of terrestrial technologies +enum TerrestrialTechMask { + TERRESTRIAL_TECH_GTP_WWAN = 1 << 0, +}; + +// Specify parameters related to lever arm +struct LeverArmParams { + // Offset along the vehicle forward axis + float forwardOffsetMeters; + // Offset along the vehicle starboard axis + float sidewaysOffsetMeters; + // Offset along the vehicle up axis + float upOffsetMeters; +}; + +typedef uint32_t LeverArmTypeMask; + +enum LeverArmTypeBits { + // Lever arm regarding the VRP (Vehicle Reference Point) w.r.t + // the origin (at the GPS Antenna) + LEVER_ARM_TYPE_GNSS_TO_VRP_BIT = (1<<0), + // Lever arm regarding GNSS Antenna w.r.t the origin at the IMU + // e.g.: inertial measurement unit for DR (dead reckoning + // engine) + LEVER_ARM_TYPE_DR_IMU_TO_GNSS_BIT = (1<<1), + // Lever arm regarding GNSS Antenna w.r.t the origin at the + // IMU (inertial measurement unit) for VEPP (vision enhanced + // precise positioning engine) + LEVER_ARM_TYPE_VEPP_IMU_TO_GNSS_BIT = (1<<2) +}; + +struct LeverArmConfigInfo { + // Valid mask for the types of lever arm parameters provided + LeverArmTypeMask leverArmValidMask; + // Lever arm regarding the VRP (Vehicle Reference Point) w.r.t the origin + // (at the GPS Antenna) + LeverArmParams gnssToVRP; + // Lever arm parameters regarding GNSS Antenna w.r.t the origin at the IMU + // (inertial measurement unit) for DR (dead reckoning engine) + LeverArmParams drImuToGnss; + // Lever arm regarding GNSS Antenna w.r.t the origin at the IMU + // (inertial measurement unit) for VEPP (vision enhanced precise position engine) + LeverArmParams veppImuToGnss; +}; + +// Specify vehicle body-to-Sensor mount parameters to be used +// by dead reckoning positioning engine. +struct BodyToSensorMountParams { + // The misalignment of the sensor board along the + // horizontal plane of the vehicle chassis measured looking + // from the vehicle to forward direction. In unit of degree. + float rollOffset; + // The misalignment along the horizontal plane of the vehicle + // chassis measured looking from the vehicle to the right + // side. Positive pitch indicates vehicle is inclined such + // that forward wheels are at higher elevation than rear + // wheels. In unit of degree. + float yawOffset; + // The angle between the vehicle forward direction and the + // sensor axis as seen from the top of the vehicle, and + // measured in counterclockwise direction. In unit of degree. + float pitchOffset; + // Single uncertainty number that may be the largest of the + // roll, pitch and yaw offset uncertainties. + float offsetUnc; +}; + +typedef uint64_t DeadReckoningEngineConfigValidMask; +// Specify the valid mask for the configuration paramters of +// dead reckoning position engine. +enum DeadReckoningEngineConfigValidBit { + // DeadReckoningEngineConfig has valid + // DeadReckoningEngineConfig::DeadReckoningEngineConfig. + BODY_TO_SENSOR_MOUNT_PARAMS_BIT = (1<<0), + // DeadReckoningEngineConfig has valid + // DeadReckoningEngineConfig::vehicleSpeedScaleFactor. + VEHICLE_SPEED_SCALE_FACTOR_BIT = (1<<1), + // DeadReckoningEngineConfig has valid + // DeadReckoningEngineConfig::vehicleSpeedScaleFactorUnc. + VEHICLE_SPEED_SCALE_FACTOR_UNC_BIT = (1<<2), + // DeadReckoningEngineConfig has valid + // DeadReckoningEngineConfig::gyroScaleFactor. + GYRO_SCALE_FACTOR_BIT = (1<<3), + // DeadReckoningEngineConfig has valid + // DeadReckoningEngineConfig::gyroScaleFactorUnc. + GYRO_SCALE_FACTOR_UNC_BIT = (1<<4), +}; + +// Specify the configuration parameters for the dead reckoning +// position engine +struct DeadReckoningEngineConfig{ + // Specify the valid fields in the config. + DeadReckoningEngineConfigValidMask validMask; + // Body to sensor mount parameters for use by dead reckoning + // positioning engine + BodyToSensorMountParams bodyToSensorMountParams; + + // Vehicle Speed Scale Factor configuration input for the dead + // reckoning positioning engine. The multiplicative scale + // factor is applied to received Vehicle Speed value (in m/s) + // to obtain the true Vehicle Speed. + // + // Range is [0.9 to 1.1]. + // + // Note: The scale factor is specific to a given vehicle + // make & model. + float vehicleSpeedScaleFactor; + // Vehicle Speed Scale Factor Uncertainty (68% confidence) + // configuration input for the dead reckoning positioning + // engine. + // + // Range is [0.0 to 0.1]. + // + // Note: The scale factor unc is specific to a given vehicle + // make & model. + float vehicleSpeedScaleFactorUnc; + + // Gyroscope Scale Factor configuration input for the dead + // reckoning positioning engine. The multiplicative scale + // factor is applied to received gyroscope value to obtain the + // true value. + // + // Range is [0.9 to 1.1]. + // + // Note: The scale factor is specific to the Gyroscope sensor + // and typically derived from either sensor data-sheet or + // from actual calibration. + float gyroScaleFactor; + + // Gyroscope Scale Factor uncertainty (68% confidence) + // configuration input for the dead reckoning positioning + // engine. + // + // Range is [0.0 to 0.1]. + // engine. + // + // Note: The scale factor unc is specific to the make & model + // of Gyroscope sensor and typically derived from either + // sensor data-sheet or from actual calibration. + float gyroScaleFactorUnc; +}; + +/* Provides the capabilities of the system + capabilities callback is called once soon after createInstance is called */ +typedef std::function capabilitiesCallback; + +/* Used by tracking, batching, and miscellanous APIs + responseCallback is called for every Tracking, Batching API, and Miscellanous API */ +typedef std::function responseCallback; + +/* Used by APIs that gets more than one LocationError in it's response + collectiveResponseCallback is called for every geofence API call. + ids array and LocationError array are only valid until collectiveResponseCallback returns. */ +typedef std::function collectiveResponseCallback; + +/* Used for startTracking API, optional can be NULL + trackingCallback is called when delivering a location in a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function trackingCallback; + +/* Used for startBatching API, optional can be NULL + batchingCallback is called when delivering locations in a batching session. + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function batchingCallback; + +typedef std::function & listOfCompletedTrips +)> batchingStatusCallback; + +/* Gives GNSS Location information, optional can be NULL + gnssLocationInfoCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function gnssLocationInfoCallback; + +/* Gives default combined location information from all engines and + location information individually from selected engines. + This callback is only used when there are multiple engines + running in the system. + + optional can be NULL + + engineLocationsInfoCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function engineLocationsInfoCallback; + +/* Used for addGeofences API, optional can be NULL + geofenceBreachCallback is called when any number of geofences have a state change */ +typedef std::function geofenceBreachCallback; + +/* Used for addGeofences API, optional can be NULL + geofenceStatusCallback is called when any number of geofences have a status change */ +typedef std::function geofenceStatusCallback; + +/* Network Initiated request, optional can be NULL + This callback should be responded to by calling gnssNiResponse */ +typedef std::function gnssNiCallback; + +/* Gives GNSS SV information, optional can be NULL + gnssSvCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function gnssSvCallback; + +/* Gives GNSS NMEA data, optional can be NULL + gnssNmeaCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function gnssNmeaCallback; + +/* Gives GNSS data, optional can be NULL + gnssDataCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function gnssDataCallback; + +/* Gives GNSS Measurements information, optional can be NULL + gnssMeasurementsCallback is called only during a tracking session + broadcasted to all clients, no matter if a session has started by client */ +typedef std::function gnssMeasurementsCallback; + +/* Provides the current GNSS configuration to the client */ +typedef std::function gnssConfigCallback; + +/* LocationSystemInfoCb is for receiving rare occuring location + system information update. optional, can be NULL. +*/ +typedef std::function locationSystemInfoCallback; + +typedef std::function locationApiDestroyCompleteCallback; + +typedef uint16_t LocationAdapterTypeMask; +typedef enum { + LOCATION_ADAPTER_GNSS_TYPE_BIT = (1<<0), // adapter type is GNSS + LOCATION_ADAPTER_BATCHING_TYPE_BIT = (1<<1), // adapter type is BATCHING + LOCATION_ADAPTER_GEOFENCE_TYPE_BIT = (1<<2) // adapter type is geo fence +} LocationAdapterTypeBits; + +typedef struct { + uint32_t size; // set to sizeof(LocationCallbacks) + capabilitiesCallback capabilitiesCb; // mandatory + responseCallback responseCb; // mandatory + collectiveResponseCallback collectiveResponseCb; // mandatory + trackingCallback trackingCb; // optional + batchingCallback batchingCb; // optional + geofenceBreachCallback geofenceBreachCb; // optional + geofenceStatusCallback geofenceStatusCb; // optional + gnssLocationInfoCallback gnssLocationInfoCb; // optional + gnssNiCallback gnssNiCb; // optional + gnssSvCallback gnssSvCb; // optional + gnssNmeaCallback gnssNmeaCb; // optional + gnssDataCallback gnssDataCb; // optional + gnssMeasurementsCallback gnssMeasurementsCb; // optional + batchingStatusCallback batchingStatusCb; // optional + locationSystemInfoCallback locationSystemInfoCb; // optional + engineLocationsInfoCallback engineLocationsInfoCb; // optional +} LocationCallbacks; + +typedef struct { + uint32_t size; // set to sizeof + double x; + double xUncertainty; + double y; + double yUncertainty; + double z; + double zUncertainty; +} GnssCoordinate; + +typedef struct { + uint32_t size; // set to sizeof + double carrierFrequencyMHz; + GnssCoordinate phaseCenterOffsetCoordinateMillimeters; + std::vector> phaseCenterVariationCorrectionMillimeters; + std::vector> phaseCenterVariationCorrectionUncertaintyMillimeters; + std::vector> signalGainCorrectionDbi; + std::vector> signalGainCorrectionUncertaintyDbi; +} GnssAntennaInformation; + +typedef struct { + uint32_t size; // set to sizeof + bool requiresNmeaLocation; + std::string hostNameOrIp; // null terminated string + std::string mountPoint; // null terminated string + std::string username; // null terminated string + std::string password; // null terminated string + uint32_t port; + bool useSSL; +} GnssNtripConnectionParams; + +typedef struct { + uint64_t meQtimer1; + uint64_t meQtimer2; + uint64_t meQtimer3; + uint64_t peQtimer1; + uint64_t peQtimer2; + uint64_t peQtimer3; + uint64_t smQtimer1; + uint64_t smQtimer2; + uint64_t smQtimer3; + uint64_t locMwQtimer; + uint64_t hlosQtimer1; + uint64_t hlosQtimer2; + uint64_t hlosQtimer3; + uint64_t hlosQtimer4; + uint64_t hlosQtimer5; +} GnssLatencyInfo; + +#endif /* LOCATIONDATATYPES_H */ diff --git a/gps/location/Makefile.am b/gps/location/Makefile.am new file mode 100644 index 0000000..6a5a750 --- /dev/null +++ b/gps/location/Makefile.am @@ -0,0 +1,44 @@ +ACLOCAL_AMFLAGS = -I m4 + +AM_CFLAGS = \ + -I./ \ + -I../utils \ + $(LOCPLA_CFLAGS) \ + $(GPSUTILS_CFLAGS) \ + -std=c++11 + +liblocation_api_la_SOURCES = \ + LocationAPI.cpp \ + LocationAPIClientBase.cpp + +if USE_EXTERNAL_AP +AM_CFLAGS += -DFEATURE_EXTERNAL_AP +endif + +if USE_GLIB +liblocation_api_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +liblocation_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 +liblocation_api_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +liblocation_api_la_CFLAGS = $(AM_CFLAGS) +liblocation_api_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0 +liblocation_api_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +liblocation_api_la_LIBADD = -lstdc++ -ldl $(GPSUTILS_LIBS) + +library_include_HEADERS = \ + LocationAPI.h \ + LocationAPIClientBase.h \ + location_interface.h \ + LocationDataTypes.h \ + ILocationAPI.h + +#Create and Install libraries +lib_LTLIBRARIES = liblocation_api.la + +library_includedir = $(pkgincludedir) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = location-api.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/location/configure.ac b/gps/location/configure.ac new file mode 100644 index 0000000..f8376f5 --- /dev/null +++ b/gps/location/configure.ac @@ -0,0 +1,95 @@ +# configure.ac -- Autoconf script for gps location-api-iface +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps location-api-iface package version 1.0.0 +AC_INIT([location-api-iface],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign subdir-objects]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([location-api.pc.in]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +# Checks for libraries. +PKG_CHECK_MODULES([GPSUTILS], [gps-utils]) +AC_SUBST([GPSUTILS_CFLAGS]) +AC_SUBST([GPSUTILS_LIBS]) + +AC_ARG_WITH([core_includes], + AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], + [Specify the location of the core headers]), + [core_incdir=$withval], + with_core_includes=no) + +if test "x$with_core_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${core_incdir}" +fi + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [Specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x${with_locpla_includes}" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_SUBST([CPPFLAGS]) + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +# External AP +AC_ARG_WITH([external_ap], + AC_HELP_STRING([--with-external_ap=@<:@dir@:>@], + [Using External Application Processor]), + [], + with_external_ap=no) + +if test "x$with_external_ap" != "xno"; then + CPPFLAGS="${CPPFLAGS} -DFEATURE_EXTERNAL_AP" +fi + +AM_CONDITIONAL(USE_EXTERNAL_AP, test "x${with_external_ap}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + location-api.pc \ + ]) + +AC_OUTPUT diff --git a/gps/location/location-api.pc.in b/gps/location/location-api.pc.in new file mode 100644 index 0000000..c7b146a --- /dev/null +++ b/gps/location/location-api.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: location-api +Description: Location API +Version: @VERSION +Libs: -L${libdir} -llocation_api +Cflags: -I${includedir}/location-api diff --git a/gps/location/location_interface.h b/gps/location/location_interface.h new file mode 100644 index 0000000..69d4f0c --- /dev/null +++ b/gps/location/location_interface.h @@ -0,0 +1,144 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LOCATION_INTERFACE_H +#define LOCATION_INTERFACE_H + +#include +#include +#include + +/* Used for callback to deliver GNSS energy consumed */ +/** @fn + @brief Used by query API that retrieves energy consumed by + modem GNSS engine. + + @param gnssEnergyConsumedFromFirstBoot: + Energy consumed by the GNSS engine since the first bootup + in units of 0.1 milli watt seconds. + A value of 0xffffffffffffffff indicates an invalid reading. +*/ +typedef std::function GnssEnergyConsumedCallback; + +typedef void (*removeClientCompleteCallback)(LocationAPI* client); + +struct GnssInterface { + size_t size; + void (*initialize)(void); + void (*deinitialize)(void); + void (*addClient)(LocationAPI* client, const LocationCallbacks& callbacks); + void (*removeClient)(LocationAPI* client, removeClientCompleteCallback rmClientCb); + void (*requestCapabilities)(LocationAPI* client); + uint32_t (*startTracking)(LocationAPI* client, TrackingOptions&); + void (*updateTrackingOptions)(LocationAPI* client, uint32_t id, TrackingOptions&); + void (*stopTracking)(LocationAPI* client, uint32_t id); + void (*gnssNiResponse)(LocationAPI* client, uint32_t id, GnssNiResponse response); + void (*setControlCallbacks)(LocationControlCallbacks& controlCallbacks); + uint32_t (*enable)(LocationTechnologyType techType); + void (*disable)(uint32_t id); + uint32_t* (*gnssUpdateConfig)(const GnssConfig& config); + uint32_t* (*gnssGetConfig)(GnssConfigFlagsMask config); + void (*gnssUpdateSvTypeConfig)(GnssSvTypeConfig& config); + void (*gnssGetSvTypeConfig)(GnssSvTypeConfigCallback& callback); + void (*gnssResetSvTypeConfig)(); + uint32_t (*gnssDeleteAidingData)(GnssAidingData& data); + void (*gnssUpdateXtraThrottle)(const bool enabled); + void (*injectLocation)(double latitude, double longitude, float accuracy); + void (*injectTime)(int64_t time, int64_t timeReference, int32_t uncertainty); + void (*agpsInit)(const AgpsCbInfo& cbInfo); + void (*agpsDataConnOpen)(AGpsExtType agpsType, const char* apnName, int apnLen, int ipType); + void (*agpsDataConnClosed)(AGpsExtType agpsType); + void (*agpsDataConnFailed)(AGpsExtType agpsType); + void (*getDebugReport)(GnssDebugReport& report); + void (*updateConnectionStatus)(bool connected, int8_t type, bool roaming, + NetworkHandle networkHandle, std::string& apn); + void (*odcpiInit)(const OdcpiRequestCallback& callback, OdcpiPrioritytype priority); + void (*odcpiInject)(const Location& location); + void (*blockCPI)(double latitude, double longitude, float accuracy, + int blockDurationMsec, double latLonDiffThreshold); + void (*getGnssEnergyConsumed)(GnssEnergyConsumedCallback energyConsumedCb); + void (*enableNfwLocationAccess)(bool enable); + void (*nfwInit)(const NfwCbInfo& cbInfo); + void (*getPowerStateChanges)(std::function powerStateCb); + void (*injectLocationExt)(const GnssLocationInfoNotification &locationInfo); + void (*updateBatteryStatus)(bool charging); + void (*updateSystemPowerState)(PowerStateType systemPowerState); + uint32_t (*setConstrainedTunc) (bool enable, float tuncConstraint, uint32_t energyBudget); + uint32_t (*setPositionAssistedClockEstimator) (bool enable); + uint32_t (*gnssUpdateSvConfig)(const GnssSvTypeConfig& constellationEnablementConfig, + const GnssSvIdConfig& blacklistSvConfig); + uint32_t (*configLeverArm)(const LeverArmConfigInfo& configInfo); + bool (*measCorrInit)(const measCorrSetCapabilitiesCb setCapabilitiesCb); + bool (*measCorrSetCorrections)(const GnssMeasurementCorrections gnssMeasCorr); + void (*measCorrClose)(); + uint32_t (*antennaInfoInit)(const antennaInfoCb antennaInfoCallback); + void (*antennaInfoClose) (); + uint32_t (*configRobustLocation)(bool enable, bool enableForE911); + uint32_t (*configMinGpsWeek)(uint16_t minGpsWeek); + uint32_t (*configDeadReckoningEngineParams)(const DeadReckoningEngineConfig& dreConfig); + void (*updateNTRIPGGAConsent)(bool consentAccepted); + void (*enablePPENtripStream)(const GnssNtripConnectionParams& params, bool enableRTKEngine); + void (*disablePPENtripStream)(); + uint32_t (*gnssUpdateSecondaryBandConfig)(const GnssSvTypeConfig& secondaryBandConfig); + uint32_t (*gnssGetSecondaryBandConfig)(); + void (*resetNetworkInfo)(); + uint32_t (*configEngineRunState)(PositioningEngineMask engType, + LocEngineRunState engState); +}; + +struct BatchingInterface { + size_t size; + void (*initialize)(void); + void (*deinitialize)(void); + void (*addClient)(LocationAPI* client, const LocationCallbacks& callbacks); + void (*removeClient)(LocationAPI* client, removeClientCompleteCallback rmClientCb); + void (*requestCapabilities)(LocationAPI* client); + uint32_t (*startBatching)(LocationAPI* client, BatchingOptions&); + void (*stopBatching)(LocationAPI* client, uint32_t id); + void (*updateBatchingOptions)(LocationAPI* client, uint32_t id, BatchingOptions&); + void (*getBatchedLocations)(LocationAPI* client, uint32_t id, size_t count); +}; + +struct GeofenceInterface { + size_t size; + void (*initialize)(void); + void (*deinitialize)(void); + void (*addClient)(LocationAPI* client, const LocationCallbacks& callbacks); + void (*removeClient)(LocationAPI* client, removeClientCompleteCallback rmClientCb); + void (*requestCapabilities)(LocationAPI* client); + uint32_t* (*addGeofences)(LocationAPI* client, size_t count, GeofenceOption*, GeofenceInfo*); + void (*removeGeofences)(LocationAPI* client, size_t count, uint32_t* ids); + void (*modifyGeofences)(LocationAPI* client, size_t count, uint32_t* ids, + GeofenceOption* options); + void (*pauseGeofences)(LocationAPI* client, size_t count, uint32_t* ids); + void (*resumeGeofences)(LocationAPI* client, size_t count, uint32_t* ids); +}; + +#endif /* LOCATION_INTERFACE_H */ diff --git a/gps/pla/Android.bp b/gps/pla/Android.bp new file mode 100644 index 0000000..5f240eb --- /dev/null +++ b/gps/pla/Android.bp @@ -0,0 +1,7 @@ + +cc_library_headers { + + name: "libloc_pla_headers", + export_include_dirs: ["android"], + vendor: true, +} diff --git a/gps/pla/android/loc_pla.h b/gps/pla/android/loc_pla.h new file mode 100644 index 0000000..34cb591 --- /dev/null +++ b/gps/pla/android/loc_pla.h @@ -0,0 +1,97 @@ +/* Copyright (c) 2014, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LOC_PLA__ +#define __LOC_PLA__ + +#ifdef __cplusplus +#include +#define uptimeMillis() android::uptimeMillis() +#define elapsedRealtime() android::elapsedRealtime() +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include + +#define UID_GPS (AID_GPS) +#define GID_GPS (AID_GPS) +#define UID_LOCCLIENT (4021) +#define GID_LOCCLIENT (4021) + +#define LOC_PATH_GPS_CONF_STR "/vendor/etc/gps.conf" +#define LOC_PATH_IZAT_CONF_STR "/vendor/etc/izat.conf" +#define LOC_PATH_FLP_CONF_STR "/vendor/etc/flp.conf" +#define LOC_PATH_LOWI_CONF_STR "/vendor/etc/lowi.conf" +#define LOC_PATH_SAP_CONF_STR "/vendor/etc/sap.conf" +#define LOC_PATH_APDR_CONF_STR "/vendor/etc/apdr.conf" +#define LOC_PATH_XTWIFI_CONF_STR "/vendor/etc/xtwifi.conf" +#define LOC_PATH_QUIPC_CONF_STR "/vendor/etc/quipc.conf" +#define LOC_PATH_ANT_CORR_STR "/vendor/etc/gnss_antenna_info.conf" +#define LOC_PATH_SLIM_CONF_STR "/vendor/etc/slim.conf" +#define LOC_PATH_VPE_CONF_STR "/vendor/etc/vpeglue.conf" + +/*! + * @brief Function for memory block copy + * + * @param[out] p_Dest Destination buffer. + * @param[in] q_DestSize Destination buffer size. + * @param[in] p_Src Source buffer. + * @param[in] q_SrcSize Source buffer size. + * + * @return Number of bytes copied. + */ +static inline size_t memscpy (void *p_Dest, size_t q_DestSize, const void *p_Src, size_t q_SrcSize) +{ + size_t res = (q_DestSize < q_SrcSize) ? q_DestSize : q_SrcSize; + if (p_Dest && p_Src && q_DestSize > 0 && q_SrcSize > 0) { + memcpy(p_Dest, p_Src, res); + } else { + res = 0; + } + return res; +} + +/*API for boot kpi marker prints */ +inline int loc_boot_kpi_marker(const char * pFmt, ...) +{ + return -1; +} + +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __LOC_PLA__ */ diff --git a/gps/pla/oe/loc_pla.h b/gps/pla/oe/loc_pla.h new file mode 100644 index 0000000..268b6bf --- /dev/null +++ b/gps/pla/oe/loc_pla.h @@ -0,0 +1,175 @@ +/* Copyright (c) 2014, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LOC_PLA__ +#define __LOC_PLA__ + +#ifdef __cplusplus +#ifndef FEATURE_EXTERNAL_AP +#include +#endif /* FEATURE_EXTERNAL_AP */ +#include +#include +#include + +#if defined(__GNUC__) && defined(__GNUC_PREREQ) +#if __GNUC_PREREQ(6,0) + #pragma message "GNU C version is above 6" +#else + #pragma message "GNU C version is less than 6" + #define NO_UNORDERED_SET_OR_MAP +#endif +#endif + +// use set/map instead of unordered_set/unordered_map for +// older GCC versions +#ifdef NO_UNORDERED_SET_OR_MAP +#define unordered_set set +#define unordered_map map +#endif + +inline int64_t sysTimeMillis(int clock) +{ + struct timespec ts; + int64_t time_ms = 0; + clock_gettime(clock, &ts); + time_ms += (ts.tv_sec * 1000000000LL); + time_ms += ts.tv_nsec + 500000LL; + return time_ms / 1000000LL; +} + +inline int64_t uptimeMillis() { + return sysTimeMillis(CLOCK_MONOTONIC); +} +inline int64_t elapsedRealtime() { + return sysTimeMillis(CLOCK_BOOTTIME); +} + +extern "C" { +#endif + +#ifndef FEATURE_EXTERNAL_AP +#include +#include +#include +#else +#define set_sched_policy(a, b) +#endif /* FEATURE_EXTERNAL_AP */ +#include +#include +#include +#include +#include +#include +#include +#define MAX_COMMAND_STR_LEN (255) +#define BOOT_KPI_FILE "/sys/kernel/debug/bootkpi/kpi_values" +#ifndef OFF_TARGET +#include +#define strlcat g_strlcat +#define strlcpy g_strlcpy +#else +#define strlcat strncat +#define strlcpy strncpy +#endif + +#define UID_GPS (1021) +#define GID_GPS (1021) +#define UID_LOCCLIENT (4021) +#define GID_LOCCLIENT (4021) + +#define LOC_PATH_GPS_CONF_STR "/etc/gps.conf" +#define LOC_PATH_IZAT_CONF_STR "/etc/izat.conf" +#define LOC_PATH_FLP_CONF_STR "/etc/flp.conf" +#define LOC_PATH_LOWI_CONF_STR "/etc/lowi.conf" +#define LOC_PATH_SAP_CONF_STR "/etc/sap.conf" +#define LOC_PATH_APDR_CONF_STR "/etc/apdr.conf" +#define LOC_PATH_XTWIFI_CONF_STR "/etc/xtwifi.conf" +#define LOC_PATH_QUIPC_CONF_STR "/etc/quipc.conf" +#define LOC_PATH_ANT_CORR_STR "/etc/gnss_antenna_info.conf" +#define LOC_PATH_SLIM_CONF_STR "/etc/slim.conf" +#define LOC_PATH_VPE_CONF_STR "/etc/vpeglue.conf" + +#ifdef FEATURE_EXTERNAL_AP +#define PROPERTY_VALUE_MAX 92 + +inline int property_get(const char* key, char* value, const char* default_value) +{ + strlcpy(value, default_value, PROPERTY_VALUE_MAX - 1); + return strlen(value); +} +#endif /* FEATURE_EXTERNAL_AP */ + +/*! + * @brief Function for memory block copy + * + * @param[out] p_Dest Destination buffer. + * @param[in] q_DestSize Destination buffer size. + * @param[in] p_Src Source buffer. + * @param[in] q_SrcSize Source buffer size. + * + * @return Number of bytes copied. + */ +static inline size_t memscpy (void *p_Dest, size_t q_DestSize, const void *p_Src, size_t q_SrcSize) +{ + size_t res = (q_DestSize < q_SrcSize) ? q_DestSize : q_SrcSize; + if (p_Dest && p_Src && q_DestSize > 0 && q_SrcSize > 0) { + memcpy(p_Dest, p_Src, res); + } else { + res = 0; + } + return res; +} + +/*API for boot kpi marker prints */ +static inline int loc_boot_kpi_marker(const char * pFmt, ...) +{ + int result = 0; + FILE *stream = NULL; + char data[MAX_COMMAND_STR_LEN] = {}; + char buf[MAX_COMMAND_STR_LEN] = {}; + + va_list ap; + va_start(ap, pFmt); + vsnprintf(&buf[0], sizeof(buf), pFmt, ap); + snprintf(data, sizeof(data), "echo -n %s > %s", buf, BOOT_KPI_FILE); + stream = popen(data, "w" ); + if (NULL == stream) { + result = -1; + } else { + pclose(stream); + } + va_end(ap); + return result; +} + +#ifdef __cplusplus +} +#endif /*__cplusplus */ + +#endif /* __LOC_PLA__ */ diff --git a/gps/utils/Android.bp b/gps/utils/Android.bp new file mode 100644 index 0000000..7d43d57 --- /dev/null +++ b/gps/utils/Android.bp @@ -0,0 +1,54 @@ + +cc_library_shared { + + name: "libgps.utils", + vendor: true, + + sanitize: GNSS_SANITIZE, + + //# Libs + shared_libs: [ + "libdl", + "libutils", + "libcutils", + "liblog", + "libprocessgroup", + ], + + srcs: [ + "loc_log.cpp", + "loc_cfg.cpp", + "msg_q.c", + "linked_list.c", + "loc_target.cpp", + "LocHeap.cpp", + "LocTimer.cpp", + "LocThread.cpp", + "MsgTask.cpp", + "loc_misc_utils.cpp", + "loc_nmea.cpp", + "LocIpc.cpp", + "LogBuffer.cpp", + ], + + cflags: [ + "-fno-short-enums", + "-D_ANDROID_", + ] + GNSS_CFLAGS, + + //# Includes + ldflags: ["-Wl,--export-dynamic"], + + header_libs: [ + "libutils_headers", + "libloc_pla_headers", + "liblocation_api_headers", + ], +} + +cc_library_headers { + + name: "libgps.utils_headers", + export_include_dirs: ["."], + vendor: true, +} diff --git a/gps/utils/LocHeap.cpp b/gps/utils/LocHeap.cpp new file mode 100644 index 0000000..4d047e4 --- /dev/null +++ b/gps/utils/LocHeap.cpp @@ -0,0 +1,280 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include + +namespace loc_util { + +class LocHeapNode { + friend class LocHeap; + + // size of of the subtree, excluding self, 1 if no subtree + int mSize; + LocHeapNode* mLeft; + LocHeapNode* mRight; + LocRankable* mData; +public: + inline LocHeapNode(LocRankable& data) : + mSize(1), mLeft(NULL), mRight(NULL), mData(&data) {} + ~LocHeapNode(); + + // this only swaps the data of the two nodes, so no + // detach / re-attached is necessary + void swap(LocHeapNode& node); + + LocRankable* detachData(); + + // push a node into the tree stucture, keeping sorted by rank + void push(LocHeapNode& node); + + // pop the head node out of the tree stucture. keeping sorted by rank + static LocHeapNode* pop(LocHeapNode*& top); + + // remove a specific node from the tree + // returns the pointer to the node removed, which would be either the + // same as input (if successfully removed); or NULL (if failed). + static LocHeapNode* remove(LocHeapNode*& top, LocRankable& data); + + // convenience method to compare data ranking + inline bool outRanks(LocHeapNode& node) { return mData->outRanks(*node.mData); } + inline bool outRanks(LocRankable& data) { return mData->outRanks(data); } + + // checks if mSize is correct, AND this node is the highest ranking + // of the entire subtree + bool checkNodes(); + + inline int getSize() { return mSize; } +}; + +inline +LocHeapNode::~LocHeapNode() { + if (mLeft) { + delete mLeft; + mLeft = NULL; + } + if (mRight) { + delete mRight; + mRight = NULL; + } + if (mData) { + mData = NULL; + } +} + +inline +void LocHeapNode::swap(LocHeapNode& node) { + LocRankable* tmpData = node.mData; + node.mData = mData; + mData = tmpData; +} + +inline +LocRankable* LocHeapNode::detachData() { + LocRankable* data = mData; + mData = NULL; + return data; +} + +// push keeps the tree sorted by rank, it also tries to balance the +// tree by adding the new node to the smaller of the subtrees. +// The pointer to the tree and internal links never change. If the +// mData of tree top ranks lower than that of the incoming node, +// mData will be swapped with that of the incoming node to ensure +// ranking, no restructuring the container nodes. +void LocHeapNode::push(LocHeapNode& node) { + // ensure the current node ranks higher than in the incoming one + if (node.outRanks(*this)) { + swap(node); + } + + // now drop the new node (ensured lower than *this) into a subtree + if (NULL == mLeft) { + mLeft = &node; + } else if (NULL == mRight) { + mRight = &node; + } else if (mLeft->mSize <= mRight->mSize) { + mLeft->push(node); + } else { + mRight->push(node); + } + mSize++; +} + +// pop keeps the tree sorted by rank, but it does not try to balance +// the tree. It recursively swaps with the higher ranked top of the +// subtrees. +// The return is a popped out node from leaf level, that has the data +// swapped all the way down from the top. The pinter to the tree and +// internal links will not be changed or restructured, except for the +// node that is popped out. +// If the return pointer == this, this the last node in the tree. +LocHeapNode* LocHeapNode::pop(LocHeapNode*& top) { + // we know the top has the highest ranking at this point, else + // the tree is broken. This top will be popped out. But we need + // a node from the left or right child, whichever ranks higher, + // to replace the current top. This then will need to be done + // recursively to the leaf level. So we swap the mData of the + // current top node all the way down to the leaf level. + LocHeapNode* poppedNode = top; + // top is losing a node in its subtree + top->mSize--; + if (top->mLeft || top->mRight) { + // if mLeft is NULL, mRight for sure is NOT NULL, take that; + // else if mRight is NULL, mLeft for sure is NOT, take that; + // else we take the address of whatever has higher ranking mData + LocHeapNode*& subTop = (NULL == top->mLeft) ? top->mRight : + ((NULL == top->mRight) ? top->mLeft : + (top->mLeft->outRanks(*(top->mRight)) ? top->mLeft : top->mRight)); + // swap mData, the tree top gets updated with the new data. + top->swap(*subTop); + // pop out from the subtree + poppedNode = pop(subTop); + } else { + // if the top has only single node + // detach the poppedNode from the tree + // subTop is the reference of ether mLeft or mRight + // NOT a local stack pointer. so it MUST be NULL'ed here. + top = NULL; + } + + return poppedNode; +} + +// navigating through the tree and find the node that hass the input +// data. Since this is a heap, we do recursive linear search. +// returns the pointer to the node removed, which would be either the +// same as input (if successfully removed); or NULL (if failed). +LocHeapNode* LocHeapNode::remove(LocHeapNode*& top, LocRankable& data) { + LocHeapNode* removedNode = NULL; + // this is the node, by address + if (&data == (LocRankable*)(top->mData)) { + // pop this node out + removedNode = pop(top); + } else if (!data.outRanks(*top->mData)) { + // subtrees might have this node + if (top->mLeft) { + removedNode = remove(top->mLeft, data); + } + // if we did not find in mLeft, and mRight is not empty + if (!removedNode && top->mRight) { + removedNode = remove(top->mRight, data); + } + + // top lost a node in its subtree + if (removedNode) { + top->mSize--; + } + } + + return removedNode; +} + +// checks if mSize is correct, AND this node is the highest ranking +// of the entire subtree +bool LocHeapNode::checkNodes() { + // size of the current subtree + int totalSize = mSize; + if (mLeft) { + // check the consistency of left subtree + if (mLeft->outRanks(*this) || !mLeft->checkNodes()) { + return false; + } + // subtract the size of left subtree (with subtree head) + totalSize -= mLeft->mSize; + } + + if (mRight) { + // check the consistency of right subtree + if (mRight->outRanks(*this) || !mRight->checkNodes()) { + return false; + } + // subtract the size of right subtree (with subtree head) + totalSize -= mRight->mSize; + } + + // for the tree nodes to consistent, totalSize must be 1 now + return totalSize == 1; +} + +LocHeap::~LocHeap() { + if (mTree) { + delete mTree; + } +} + +void LocHeap::push(LocRankable& node) { + LocHeapNode* heapNode = new LocHeapNode(node); + if (!mTree) { + mTree = heapNode; + } else { + mTree->push(*heapNode); + } +} + +LocRankable* LocHeap::peek() { + LocRankable* top = NULL; + if (mTree) { + top = mTree->mData; + } + return top; +} + +LocRankable* LocHeap::pop() { + LocRankable* locNode = NULL; + if (mTree) { + // mTree may become NULL after this call + LocHeapNode* heapNode = LocHeapNode::pop(mTree); + locNode = heapNode->detachData(); + delete heapNode; + } + return locNode; +} + +LocRankable* LocHeap::remove(LocRankable& rankable) { + LocRankable* locNode = NULL; + if (mTree) { + // mTree may become NULL after this call + LocHeapNode* heapNode = LocHeapNode::remove(mTree, rankable); + if (heapNode) { + locNode = heapNode->detachData(); + delete heapNode; + } + } + return locNode; +} + +} // namespace loc_util + +#ifdef __LOC_UNIT_TEST__ +bool LocHeap::checkTree() { + return ((NULL == mTree) || mTree->checkNodes()); +} +uint32_t LocHeap::getTreeSize() { + return (NULL == mTree) ? 0 : mTree->getSize(); +} +#endif diff --git a/gps/utils/LocHeap.h b/gps/utils/LocHeap.h new file mode 100644 index 0000000..bb62d6b --- /dev/null +++ b/gps/utils/LocHeap.h @@ -0,0 +1,100 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_HEAP__ +#define __LOC_HEAP__ + +#include +#include + +namespace loc_util { + +// abstract class to be implemented by client to provide a rankable class +class LocRankable { +public: + virtual inline ~LocRankable() {} + + // method to rank objects of such type for sorting purposes. + // The pointer of the input node would be stored in the heap. + // >0 if ranks higher than the input; + // ==0 if equally ranks with the input; + // <0 if ranks lower than the input + virtual int ranks(LocRankable& rankable) = 0; + + // convenient method to rank objects of such type for sorting purposes. + inline bool outRanks(LocRankable& rankable) { return ranks(rankable) > 0; } +}; + +// opaque class to provide service implementation. +class LocHeapNode; + +// a heap whose left and right children are not sorted. It is sorted only vertically, +// i.e. parent always ranks higher than children, if they exist. Ranking algorithm is +// implemented in Rankable. The reason that there is no sort between children is to +// help beter balance the tree with lower cost. When a node is pushed to the tree, +// it is guaranteed that the subtree that is smaller gets to have the new node. +class LocHeap { +protected: + LocHeapNode* mTree; +public: + inline LocHeap() : mTree(NULL) {} + ~LocHeap(); + + // push keeps the tree sorted by rank, it also tries to balance the + // tree by adding the new node to the smaller of the subtrees. + // node is reference to an obj that is managed by client, that client + // creates and destroyes. The destroy should happen after the + // node is popped out from the heap. + void push(LocRankable& node); + + // Peeks the node data on tree top, which has currently the highest ranking + // There is no change the tree structure with this operation + // Returns NULL if the tree is empty, otherwise pointer to the node data of + // the tree top. + LocRankable* peek(); + + // pop keeps the tree sorted by rank, but it does not try to balance + // the tree. + // Return - pointer to the node popped out, or NULL if heap is already empty + LocRankable* pop(); + + // navigating through the tree and find the node that ranks the same + // as the input data, then remove it from the tree. Rank is implemented + // by rankable obj. + // returns the pointer to the node removed; or NULL (if failed). + LocRankable* remove(LocRankable& rankable); + +#ifdef __LOC_UNIT_TEST__ + bool checkTree(); + uint32_t getTreeSize(); +#endif +}; + +} // namespace loc_util + +#endif //__LOC_HEAP__ diff --git a/gps/utils/LocIpc.cpp b/gps/utils/LocIpc.cpp new file mode 100644 index 0000000..746ca87 --- /dev/null +++ b/gps/utils/LocIpc.cpp @@ -0,0 +1,430 @@ +/* Copyright (c) 2017-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace loc_util { + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LocSvc_LocIpc" + +#define SOCK_OP_AND_LOG(buf, length, opable, rtv, exe) \ + if (nullptr == (buf) || 0 == (length)) { \ + LOC_LOGe("Invalid inputs: buf - %p, length - %u", (buf), (length)); \ + } else if (!(opable)) { \ + LOC_LOGe("Invalid object: operable - %d", (opable)); \ + } else { \ + rtv = (exe); \ + if (-1 == rtv) { \ + LOC_LOGw("failed reason: %s", strerror(errno)); \ + } \ + } + +const char Sock::MSG_ABORT[] = "LocIpc::Sock::ABORT"; +const char Sock::LOC_IPC_HEAD[] = "$MSGLEN$"; +ssize_t Sock::send(const void *buf, uint32_t len, int flags, const struct sockaddr *destAddr, + socklen_t addrlen) const { + ssize_t rtv = -1; + SOCK_OP_AND_LOG(buf, len, isValid(), rtv, sendto(buf, len, flags, destAddr, addrlen)); + return rtv; +} +ssize_t Sock::recv(const LocIpcRecver& recver, const shared_ptr& dataCb, int flags, + struct sockaddr *srcAddr, socklen_t *addrlen, int sid) const { + ssize_t rtv = -1; + if (-1 == sid) { + sid = mSid; + } // else it sid would be connection based socket id for recv + SOCK_OP_AND_LOG(dataCb.get(), mMaxTxSize, isValid(), rtv, + recvfrom(recver, dataCb, sid, flags, srcAddr, addrlen)); + return rtv; +} +ssize_t Sock::sendto(const void *buf, size_t len, int flags, const struct sockaddr *destAddr, + socklen_t addrlen) const { + ssize_t rtv = -1; + if (len <= mMaxTxSize) { + rtv = ::sendto(mSid, buf, len, flags, destAddr, addrlen); + } else { + std::string head(LOC_IPC_HEAD + to_string(len)); + rtv = ::sendto(mSid, head.c_str(), head.length(), flags, destAddr, addrlen); + if (rtv > 0) { + for (size_t offset = 0; offset < len && rtv > 0; offset += rtv) { + rtv = ::sendto(mSid, (char*)buf + offset, min(len - offset, (size_t)mMaxTxSize), + flags, destAddr, addrlen); + } + rtv = (rtv > 0) ? (head.length() + len) : -1; + } + } + return rtv; +} +ssize_t Sock::recvfrom(const LocIpcRecver& recver, const shared_ptr& dataCb, + int sid, int flags, struct sockaddr *srcAddr, socklen_t *addrlen) const { + std::string msg(mMaxTxSize, 0); + ssize_t nBytes = ::recvfrom(sid, (void*)msg.data(), msg.size(), flags, srcAddr, addrlen); + if (nBytes > 0) { + if (strncmp(msg.data(), MSG_ABORT, sizeof(MSG_ABORT)) == 0) { + LOC_LOGi("recvd abort msg.data %s", msg.data()); + nBytes = 0; + } else if (strncmp(msg.data(), LOC_IPC_HEAD, sizeof(LOC_IPC_HEAD) - 1)) { + // short message + msg.resize(nBytes); + dataCb->onReceive(msg.data(), nBytes, &recver); + } else { + // long message + size_t msgLen = 0; + sscanf(msg.data() + sizeof(LOC_IPC_HEAD) - 1, "%zu", &msgLen); + msg.resize(msgLen); + for (size_t msgLenReceived = 0; (msgLenReceived < msgLen) && (nBytes > 0); + msgLenReceived += nBytes) { + nBytes = ::recvfrom(sid, &(msg[msgLenReceived]), msg.size() - msgLenReceived, + flags, srcAddr, addrlen); + } + if (nBytes > 0) { + nBytes = msgLen; + dataCb->onReceive(msg.data(), nBytes, &recver); + } + } + } + + return nBytes; +} +ssize_t Sock::sendAbort(int flags, const struct sockaddr *destAddr, socklen_t addrlen) { + return send(MSG_ABORT, sizeof(MSG_ABORT), flags, destAddr, addrlen); +} + +class LocIpcLocalSender : public LocIpcSender { +protected: + shared_ptr mSock; + struct sockaddr_un mAddr; + inline virtual bool isOperable() const override { return mSock != nullptr && mSock->isValid(); } + inline virtual ssize_t send(const uint8_t data[], uint32_t length, int32_t /* msgId */) const { + return mSock->send(data, length, 0, (struct sockaddr*)&mAddr, sizeof(mAddr)); + } +public: + inline LocIpcLocalSender(const char* name) : LocIpcSender(), + mSock(nullptr), + mAddr({.sun_family = AF_UNIX, {}}) { + + int fd = -1; + if (nullptr != name) { + fd = ::socket(AF_UNIX, SOCK_DGRAM, 0); + if (fd >= 0) { + timeval timeout; + timeout.tv_sec = 2; + timeout.tv_usec = 0; + setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); + } + } + mSock.reset(new Sock(fd)); + if (mSock != nullptr && mSock->isValid()) { + snprintf(mAddr.sun_path, sizeof(mAddr.sun_path), "%s", name); + } + } +}; + +class LocIpcLocalRecver : public LocIpcLocalSender, public LocIpcRecver { +protected: + inline virtual ssize_t recv() const override { + socklen_t size = sizeof(mAddr); + return mSock->recv(*this, mDataCb, 0, (struct sockaddr*)&mAddr, &size); + } +public: + inline LocIpcLocalRecver(const shared_ptr& listener, const char* name) : + LocIpcLocalSender(name), LocIpcRecver(listener, *this) { + + if ((unlink(mAddr.sun_path) < 0) && (errno != ENOENT)) { + LOC_LOGw("unlink socket error. reason:%s", strerror(errno)); + } + + umask(0157); + if (mSock->isValid() && ::bind(mSock->mSid, (struct sockaddr*)&mAddr, sizeof(mAddr)) < 0) { + LOC_LOGe("bind socket error. sock fd: %d: %s, reason: %s", mSock->mSid, + mAddr.sun_path, strerror(errno)); + mSock->close(); + } + } + inline virtual ~LocIpcLocalRecver() { unlink(mAddr.sun_path); } + inline virtual const char* getName() const override { return mAddr.sun_path; }; + inline virtual void abort() const override { + if (isSendable()) { + mSock->sendAbort(0, (struct sockaddr*)&mAddr, sizeof(mAddr)); + } + } +}; + +class LocIpcInetSender : public LocIpcSender { +protected: + int mSockType; + shared_ptr mSock; + const string mName; + sockaddr_in mAddr; + inline virtual bool isOperable() const override { return mSock != nullptr && mSock->isValid(); } + virtual ssize_t send(const uint8_t data[], uint32_t length, int32_t /* msgId */) const { + return mSock->send(data, length, 0, (struct sockaddr*)&mAddr, sizeof(mAddr)); + } +public: + inline LocIpcInetSender(const LocIpcInetSender& sender) : + mSockType(sender.mSockType), mSock(sender.mSock), + mName(sender.mName), mAddr(sender.mAddr) { + } + inline LocIpcInetSender(const char* name, int32_t port, int sockType) : LocIpcSender(), + mSockType(sockType), + mSock(make_shared((nullptr == name) ? -1 : (::socket(AF_INET, mSockType, 0)))), + mName((nullptr == name) ? "" : name), + mAddr({.sin_family = AF_INET, .sin_port = htons(port), + .sin_addr = {htonl(INADDR_ANY)}}) { + if (mSock != nullptr && mSock->isValid() && nullptr != name) { + struct hostent* hp = gethostbyname(name); + if (nullptr != hp) { + memcpy((char*)&(mAddr.sin_addr.s_addr), hp->h_addr_list[0], hp->h_length); + } + } + } + + unique_ptr getRecver(const shared_ptr& listener) override { + return make_unique(listener, *this, mSock); + } +}; + +class LocIpcInetTcpSender : public LocIpcInetSender { +protected: + mutable bool mFirstTime; + + virtual ssize_t send(const uint8_t data[], uint32_t length, int32_t /* msgId */) const { + if (mFirstTime) { + mFirstTime = false; + ::connect(mSock->mSid, (const struct sockaddr*)&mAddr, sizeof(mAddr)); + } + return mSock->send(data, length, 0, (struct sockaddr*)&mAddr, sizeof(mAddr)); + } + +public: + inline LocIpcInetTcpSender(const char* name, int32_t port) : + LocIpcInetSender(name, port, SOCK_STREAM), + mFirstTime(true) {} +}; + +class LocIpcInetRecver : public LocIpcInetSender, public LocIpcRecver { + int32_t mPort; +protected: + virtual ssize_t recv() const = 0; +public: + inline LocIpcInetRecver(const shared_ptr& listener, const char* name, + int32_t port, int sockType) : + LocIpcInetSender(name, port, sockType), LocIpcRecver(listener, *this), + mPort(port) { + if (mSock->isValid() && ::bind(mSock->mSid, (struct sockaddr*)&mAddr, sizeof(mAddr)) < 0) { + LOC_LOGe("bind socket error. sock fd: %d, reason: %s", mSock->mSid, strerror(errno)); + mSock->close(); + } + } + inline virtual ~LocIpcInetRecver() {} + inline virtual const char* getName() const override { return mName.data(); }; + inline virtual void abort() const override { + if (isSendable()) { + sockaddr_in loopBackAddr = {.sin_family = AF_INET, .sin_port = htons(mPort), + .sin_addr = {htonl(INADDR_LOOPBACK)}}; + mSock->sendAbort(0, (struct sockaddr*)&loopBackAddr, sizeof(loopBackAddr)); + } + } + inline virtual unique_ptr getLastSender() const override { + return make_unique(static_cast(*this)); + } +}; + +class LocIpcInetTcpRecver : public LocIpcInetRecver { + mutable int32_t mConnFd; +protected: + inline virtual ssize_t recv() const override { + socklen_t size = sizeof(mAddr); + if (-1 == mConnFd && mSock->isValid()) { + if (::listen(mSock->mSid, 3) < 0 || + (mConnFd = accept(mSock->mSid, (struct sockaddr*)&mAddr, &size)) < 0) { + mSock->close(); + mConnFd = -1; + } + } + return mSock->recv(*this, mDataCb, 0, (struct sockaddr*)&mAddr, &size, mConnFd); + } +public: + inline LocIpcInetTcpRecver(const shared_ptr& listener, const char* name, + int32_t port) : + LocIpcInetRecver(listener, name, port, SOCK_STREAM), mConnFd(-1) {} + inline virtual ~LocIpcInetTcpRecver() { if (-1 != mConnFd) ::close(mConnFd);} +}; + +class LocIpcInetUdpRecver : public LocIpcInetRecver { +protected: + inline virtual ssize_t recv() const override { + socklen_t size = sizeof(mAddr); + return mSock->recv(*this, mDataCb, 0, (struct sockaddr*)&mAddr, &size); + } +public: + inline LocIpcInetUdpRecver(const shared_ptr& listener, const char* name, + int32_t port) : + LocIpcInetRecver(listener, name, port, SOCK_DGRAM) {} + + inline virtual ~LocIpcInetUdpRecver() {} +}; + +class LocIpcRunnable : public LocRunnable { + bool mAbortCalled; + LocIpc& mLocIpc; + unique_ptr mIpcRecver; +public: + inline LocIpcRunnable(LocIpc& locIpc, unique_ptr& ipcRecver) : + mAbortCalled(false), + mLocIpc(locIpc), + mIpcRecver(move(ipcRecver)) {} + inline virtual bool run() override { + if (mIpcRecver != nullptr) { + mLocIpc.startBlockingListening(*(mIpcRecver.get())); + if (!mAbortCalled) { + LOC_LOGw("startListeningBlocking() returned w/o stopBlockingListening() called"); + } + } + // return false so the calling thread exits while loop + return false; + } + inline virtual void interrupt() override { + mAbortCalled = true; + if (mIpcRecver != nullptr) { + mIpcRecver->abort(); + } + } +}; + +bool LocIpc::startNonBlockingListening(unique_ptr& ipcRecver) { + if (ipcRecver != nullptr && ipcRecver->isRecvable()) { + std::string threadName("LocIpc-"); + threadName.append(ipcRecver->getName()); + return mThread.start(threadName.c_str(), make_shared(*this, ipcRecver)); + } else { + LOC_LOGe("ipcRecver is null OR ipcRecver->recvable() is fasle"); + return false; + } +} + +bool LocIpc::startBlockingListening(LocIpcRecver& ipcRecver) { + if (ipcRecver.isRecvable()) { + // inform that the socket is ready to receive message + ipcRecver.onListenerReady(); + while (ipcRecver.recvData()); + return true; + } else { + LOC_LOGe("ipcRecver is null OR ipcRecver->recvable() is fasle"); + return false; + } +} + +void LocIpc::stopNonBlockingListening() { + mThread.stop(); +} + +void LocIpc::stopBlockingListening(LocIpcRecver& ipcRecver) { + if (ipcRecver.isRecvable()) { + ipcRecver.abort(); + } +} + +bool LocIpc::send(LocIpcSender& sender, const uint8_t data[], uint32_t length, int32_t msgId) { + return sender.sendData(data, length, msgId); +} + +shared_ptr LocIpc::getLocIpcLocalSender(const char* localSockName) { + return make_shared(localSockName); +} +unique_ptr LocIpc::getLocIpcLocalRecver(const shared_ptr& listener, + const char* localSockName) { + return make_unique(listener, localSockName); +} +static void* sLibQrtrHandle = nullptr; +static const char* sLibQrtrName = "libloc_socket.so"; +shared_ptr LocIpc::getLocIpcQrtrSender(int service, int instance) { + typedef shared_ptr (*creator_t) (int, int); + static creator_t creator = (creator_t)dlGetSymFromLib(sLibQrtrHandle, sLibQrtrName, + "_ZN8loc_util22createLocIpcQrtrSenderEii"); + return (nullptr == creator) ? nullptr : creator(service, instance); +} +unique_ptr LocIpc::getLocIpcQrtrRecver(const shared_ptr& listener, + int service, int instance, + const shared_ptr& watcher) { + typedef unique_ptr (*creator_t)(const shared_ptr&, int, int, + const shared_ptr& watcher); + static creator_t creator = (creator_t)dlGetSymFromLib(sLibQrtrHandle, sLibQrtrName, +#ifdef USE_GLIB + "_ZN8loc_util22createLocIpcQrtrRecverERKSt10shared_ptrINS_15ILocIpcListenerEEiiRKS0_INS_17LocIpcQrtrWatcherEE"); +#else + "_ZN8loc_util22createLocIpcQrtrRecverERKNSt3__110shared_ptrINS_15ILocIpcListenerEEEiiRKNS1_INS_17LocIpcQrtrWatcherEEE"); +#endif + return (nullptr == creator) ? nullptr : creator(listener, service, instance, watcher); +} +shared_ptr LocIpc::getLocIpcInetTcpSender(const char* serverName, int32_t port) { + return make_shared(serverName, port); +} +unique_ptr LocIpc::getLocIpcInetTcpRecver(const shared_ptr& listener, + const char* serverName, int32_t port) { + return make_unique(listener, serverName, port); +} +shared_ptr LocIpc::getLocIpcInetUdpSender(const char* serverName, int32_t port) { + return make_shared(serverName, port, SOCK_DGRAM); +} +unique_ptr LocIpc::getLocIpcInetUdpRecver(const shared_ptr& listener, + const char* serverName, int32_t port) { + return make_unique(listener, serverName, port); +} +pair, unique_ptr> + LocIpc::getLocIpcQmiLocServiceSenderRecverPair(const shared_ptr& listener, int instance) { + typedef pair, unique_ptr> (*creator_t)(const shared_ptr&, int); + static void* sLibEmuHandle = nullptr; + static creator_t creator = (creator_t)dlGetSymFromLib(sLibEmuHandle, "libloc_emu.so", +#ifdef USE_GLIB + "_ZN13QmiLocService41createLocIpcQmiLocServiceSenderRecverPair"\ + "ERKSt10shared_ptrIN8loc_util15ILocIpcListenerEEi"); +#else + "_ZN13QmiLocService41createLocIpcQmiLocServiceSenderRecverPair"\ + "ERKNSt3__110shared_ptrIN8loc_util15ILocIpcListenerEEEi"); +#endif + return (nullptr == creator) ? + make_pair, unique_ptr>(nullptr, nullptr) : + creator(listener, instance); +} + +} diff --git a/gps/utils/LocIpc.h b/gps/utils/LocIpc.h new file mode 100644 index 0000000..b2586e6 --- /dev/null +++ b/gps/utils/LocIpc.h @@ -0,0 +1,241 @@ +/* Copyright (c) 2017-2018, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_IPC__ +#define __LOC_IPC__ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace loc_util { + +class LocIpcRecver; +class LocIpcSender; + +class ILocIpcListener { +protected: + inline virtual ~ILocIpcListener() {} +public: + // LocIpc client can overwrite this function to get notification + // when the socket for LocIpc is ready to receive messages. + inline virtual void onListenerReady() {} + virtual void onReceive(const char* data, uint32_t len, const LocIpcRecver* recver) = 0; +}; + +class LocIpcQrtrWatcher { + const unordered_set mServicesToWatch; + unordered_set mClientsToWatch; + mutex mMutex; + inline bool isInWatch(const unordered_set& idsToWatch, int id) { + return idsToWatch.find(id) != idsToWatch.end(); + } +protected: + inline virtual ~LocIpcQrtrWatcher() {} + inline LocIpcQrtrWatcher(unordered_set servicesToWatch) + : mServicesToWatch(servicesToWatch) {} +public: + enum class ServiceStatus { UP, DOWN }; + inline bool isServiceInWatch(int serviceId) { + return isInWatch(mServicesToWatch, serviceId); + } + inline bool isClientInWatch(int nodeId) { + lock_guard lock(mMutex); + return isInWatch(mClientsToWatch, nodeId); + } + inline void addClientToWatch(int nodeId) { + lock_guard lock(mMutex); + mClientsToWatch.emplace(nodeId); + } + virtual void onServiceStatusChange(int sericeId, int instanceId, ServiceStatus status, + const LocIpcSender& sender) = 0; + inline virtual void onClientGone(int nodeId, int portId) {} + inline const unordered_set& getServicesToWatch() { return mServicesToWatch; } +}; + +class LocIpc { +public: + inline LocIpc() = default; + inline virtual ~LocIpc() { + stopNonBlockingListening(); + } + + static shared_ptr + getLocIpcLocalSender(const char* localSockName); + static shared_ptr + getLocIpcInetUdpSender(const char* serverName, int32_t port); + static shared_ptr + getLocIpcInetTcpSender(const char* serverName, int32_t port); + static shared_ptr + getLocIpcQrtrSender(int service, int instance); + + static unique_ptr + getLocIpcLocalRecver(const shared_ptr& listener, + const char* localSockName); + static unique_ptr + getLocIpcInetUdpRecver(const shared_ptr& listener, + const char* serverName, int32_t port); + static unique_ptr + getLocIpcInetTcpRecver(const shared_ptr& listener, + const char* serverName, int32_t port); + inline static unique_ptr + getLocIpcQrtrRecver(const shared_ptr& listener, + int service, int instance) { + const shared_ptr qrtrWatcher = nullptr; + return getLocIpcQrtrRecver(listener, service, instance, qrtrWatcher); + } + static unique_ptr + getLocIpcQrtrRecver(const shared_ptr& listener, + int service, int instance, + const shared_ptr& qrtrWatcher); + + static pair, unique_ptr> + getLocIpcQmiLocServiceSenderRecverPair(const shared_ptr& listener, + int instance); + + // Listen for new messages in current thread. Calling this funciton will + // block current thread. + // The listening can be stopped by calling stopBlockingListening() passing + // in the same ipcRecver obj handle. + static bool startBlockingListening(LocIpcRecver& ipcRecver); + static void stopBlockingListening(LocIpcRecver& ipcRecver); + + // Create a new LocThread and listen for new messages in it. + // Calling this function will return immediately and won't block current thread. + // The listening can be stopped by calling stopNonBlockingListening(). + bool startNonBlockingListening(unique_ptr& ipcRecver); + void stopNonBlockingListening(); + + // Send out a message. + // Call this function to send a message in argument data to socket in argument name. + // + // Argument name contains the name of the target unix socket. data contains the + // message to be sent out. Convert your message to a string before calling this function. + // The function will return true on success, and false on failure. + static bool send(LocIpcSender& sender, const uint8_t data[], + uint32_t length, int32_t msgId = -1); + +private: + LocThread mThread; +}; + +/* this is only when client needs to implement Sender / Recver that are not already provided by + the factor methods prvoided by LocIpc. */ + +class LocIpcSender { +protected: + LocIpcSender() = default; + virtual bool isOperable() const = 0; + virtual ssize_t send(const uint8_t data[], uint32_t length, int32_t msgId) const = 0; +public: + virtual ~LocIpcSender() = default; + inline bool isSendable() const { return isOperable(); } + inline bool sendData(const uint8_t data[], uint32_t length, int32_t msgId) const { + return isSendable() && (send(data, length, msgId) > 0); + } + virtual unique_ptr getRecver(const shared_ptr& listener) { + return nullptr; + } + inline virtual void copyDestAddrFrom(const LocIpcSender& otherSender) {} +}; + +class LocIpcRecver { + LocIpcSender& mIpcSender; +protected: + const shared_ptr mDataCb; + inline LocIpcRecver(const shared_ptr& listener, LocIpcSender& sender) : + mIpcSender(sender), mDataCb(listener) {} + LocIpcRecver(LocIpcRecver const& recver) = delete; + LocIpcRecver& operator=(LocIpcRecver const& recver) = delete; + virtual ssize_t recv() const = 0; +public: + virtual ~LocIpcRecver() = default; + inline bool recvData() const { return isRecvable() && (recv() > 0); } + inline bool isRecvable() const { return mDataCb != nullptr && mIpcSender.isSendable(); } + virtual void onListenerReady() { if (mDataCb != nullptr) mDataCb->onListenerReady(); } + inline virtual unique_ptr getLastSender() const { + return nullptr; + } + virtual void abort() const = 0; + virtual const char* getName() const = 0; +}; + +class Sock { + static const char MSG_ABORT[]; + static const char LOC_IPC_HEAD[]; + const uint32_t mMaxTxSize; + ssize_t sendto(const void *buf, size_t len, int flags, const struct sockaddr *destAddr, + socklen_t addrlen) const; + ssize_t recvfrom(const LocIpcRecver& recver, const shared_ptr& dataCb, + int sid, int flags, struct sockaddr *srcAddr, socklen_t *addrlen) const; +public: + int mSid; + inline Sock(int sid, const uint32_t maxTxSize = 8192) : mMaxTxSize(maxTxSize), mSid(sid) {} + inline ~Sock() { close(); } + inline bool isValid() const { return -1 != mSid; } + ssize_t send(const void *buf, uint32_t len, int flags, const struct sockaddr *destAddr, + socklen_t addrlen) const; + ssize_t recv(const LocIpcRecver& recver, const shared_ptr& dataCb, int flags, + struct sockaddr *srcAddr, socklen_t *addrlen, int sid = -1) const; + ssize_t sendAbort(int flags, const struct sockaddr *destAddr, socklen_t addrlen); + inline void close() { + if (isValid()) { + ::close(mSid); + mSid = -1; + } + } +}; + +class SockRecver : public LocIpcRecver { + shared_ptr mSock; +protected: + inline virtual ssize_t recv() const override { + return mSock->recv(*this, mDataCb, 0, nullptr, nullptr); + } +public: + inline SockRecver(const shared_ptr& listener, + LocIpcSender& sender, shared_ptr sock) : + LocIpcRecver(listener, sender), mSock(sock) { + } + inline virtual const char* getName() const override { + return "SockRecver"; + } + inline virtual void abort() const override {} +}; + +} + +#endif //__LOC_IPC__ diff --git a/gps/utils/LocLoggerBase.h b/gps/utils/LocLoggerBase.h new file mode 100644 index 0000000..867b6e2 --- /dev/null +++ b/gps/utils/LocLoggerBase.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_LOGGER_BASE_H +#define LOC_LOGGER_BASE_H + +namespace loc_util { +class LocLoggerBase { +public: + virtual void log() {} +}; +} + +#endif diff --git a/gps/utils/LocSharedLock.h b/gps/utils/LocSharedLock.h new file mode 100644 index 0000000..1ef2c57 --- /dev/null +++ b/gps/utils/LocSharedLock.h @@ -0,0 +1,81 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_SHARED_LOCK__ +#define __LOC_SHARED_LOCK__ + +#include +#ifndef FEATURE_EXTERNAL_AP +#include +#endif /* FEATURE_EXTERNAL_AP */ +#include + +#ifdef FEATURE_EXTERNAL_AP +#include + +inline int32_t android_atomic_inc(volatile int32_t *addr) +{ + volatile std::atomic_int_least32_t* a = (volatile std::atomic_int_least32_t*)addr; + return std::atomic_fetch_add_explicit(a, 1, std::memory_order_release); +} + +inline int32_t android_atomic_dec(volatile int32_t *addr) +{ + volatile std::atomic_int_least32_t* a = (volatile std::atomic_int_least32_t*)addr; + return std::atomic_fetch_sub_explicit(a, 1, std::memory_order_release); +} +#endif /* FEATURE_EXTERNAL_AP */ + +namespace loc_util { + +// This is a utility created for use cases such that there are more than +// one client who need to share the same lock, but it is not predictable +// which of these clients is to last to go away. This shared lock deletes +// itself when the last client calls its drop() method. To add a cient, +// this share lock's share() method has to be called, so that the obj +// can maintain an accurate client count. +class LocSharedLock { + volatile int32_t mRef; + pthread_mutex_t mMutex; + inline ~LocSharedLock() { pthread_mutex_destroy(&mMutex); } +public: + // first client to create this LockSharedLock + inline LocSharedLock() : mRef(1) { pthread_mutex_init(&mMutex, NULL); } + // following client(s) are to *share()* this lock created by the first client + inline LocSharedLock* share() { android_atomic_inc(&mRef); return this; } + // whe a client no longer needs this shared lock, drop() shall be called. + inline void drop() { if (1 == android_atomic_dec(&mRef)) delete this; } + // locking the lock to enter critical section + inline void lock() { pthread_mutex_lock(&mMutex); } + // unlocking the lock to leave the critical section + inline void unlock() { pthread_mutex_unlock(&mMutex); } +}; + +} //namespace loc_util + +#endif //__LOC_SHARED_LOCK__ diff --git a/gps/utils/LocThread.cpp b/gps/utils/LocThread.cpp new file mode 100644 index 0000000..3cac1f9 --- /dev/null +++ b/gps/utils/LocThread.cpp @@ -0,0 +1,111 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include +#include +#include +#include +#include +#include + +using std::weak_ptr; +using std::shared_ptr; +using std::thread; +using std::string; + +namespace loc_util { + +class LocThreadDelegate { + static const char defaultThreadName[]; + weak_ptr mRunnable; + thread mThread; + LocThreadDelegate(const string tName, shared_ptr r); +public: + ~LocThreadDelegate() { + shared_ptr runnable = mRunnable.lock(); + if (nullptr != runnable) { + runnable->interrupt(); + } + } + inline static LocThreadDelegate* create(const char* tName, shared_ptr runnable); +}; + +const char LocThreadDelegate::defaultThreadName[] = "LocThread"; + +LocThreadDelegate* LocThreadDelegate::create(const char* tName, shared_ptr runnable) { + LocThreadDelegate* threadDelegate = nullptr; + + if (nullptr != runnable) { + if (!tName) { + tName = defaultThreadName; + } + + char lname[16]; + auto nameSize = strlen(tName) + 1; + int len = std::min(sizeof(lname), nameSize) - 1; + memcpy(lname, tName, len); + lname[len] = 0; + + threadDelegate = new LocThreadDelegate(lname, runnable); + } + + return threadDelegate; +} + +LocThreadDelegate::LocThreadDelegate(const string tName, shared_ptr runnable) : + mRunnable(runnable), + mThread([tName, runnable] { + prctl(PR_SET_NAME, tName.c_str(), 0, 0, 0); + runnable->prerun(); + while (runnable->run()); + runnable->postrun(); + }) { + + mThread.detach(); +} + + + +bool LocThread::start(const char* tName, shared_ptr runnable) { + bool success = false; + if (!mThread) { + mThread = LocThreadDelegate::create(tName, runnable); + // true only if thread is created successfully + success = (NULL != mThread); + } + return success; +} + +void LocThread::stop() { + if (nullptr != mThread) { + delete mThread; + mThread = nullptr; + } +} + +} // loc_util diff --git a/gps/utils/LocThread.h b/gps/utils/LocThread.h new file mode 100644 index 0000000..c7ece87 --- /dev/null +++ b/gps/utils/LocThread.h @@ -0,0 +1,95 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_THREAD__ +#define __LOC_THREAD__ + +#include +#include + +using std::shared_ptr; + +namespace loc_util { + +// abstract class to be implemented by client to provide a runnable class +// which gets scheduled by LocThread +class LocRunnable { +public: + inline LocRunnable() = default; + inline virtual ~LocRunnable() = default; + + // The method to be implemented by thread clients + // and be scheduled by LocThread + // This method will be repeated called until it returns false; or + // until thread is stopped. + virtual bool run() = 0; + + // The method to be run before thread loop (conditionally repeatedly) + // calls run() + inline virtual void prerun() {} + + // The method to be run after thread loop (conditionally repeatedly) + // calls run() + inline virtual void postrun() {} + + // The method to wake up the potential blocking thread + // no op if not applicable + inline virtual void interrupt() = 0; +}; + +// opaque class to provide service implementation. +class LocThreadDelegate; + +// A utility class to create a thread and run LocRunnable +// caller passes in. +class LocThread { + LocThreadDelegate* mThread; +public: + inline LocThread() : mThread(NULL) {} + inline virtual ~LocThread() { stop(); } + + // client starts thread with a runnable, which implements + // the logics to fun in the created thread context. + // The thread is always detached. + // runnable is an obj managed by client. Client creates and + // frees it (but must be after stop() is called, or + // this LocThread obj is deleted). + // The obj will be deleted by LocThread if start() + // returns true. Else it is client's responsibility + // to delete the object + // Returns 0 if success; false if failure. + bool start(const char* threadName, shared_ptr runnable); + + void stop(); + + // thread status check + inline bool isRunning() { return NULL != mThread; } +}; + +} // loc_util +#endif //__LOC_THREAD__ diff --git a/gps/utils/LocTimer.cpp b/gps/utils/LocTimer.cpp new file mode 100644 index 0000000..915cf54 --- /dev/null +++ b/gps/utils/LocTimer.cpp @@ -0,0 +1,648 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __HOST_UNIT_TEST__ +#define EPOLLWAKEUP 0 +#define CLOCK_BOOTTIME CLOCK_MONOTONIC +#define CLOCK_BOOTTIME_ALARM CLOCK_MONOTONIC +#endif + +namespace loc_util { + +/* +There are implementations of 5 classes in this file: +LocTimer, LocTimerDelegate, LocTimerContainer, LocTimerPollTask, LocTimerWrapper + +LocTimer - client front end, interface for client to start / stop timers, also + to provide a callback. +LocTimerDelegate - an internal timer entity, which also is a LocRankable obj. + Its life cycle is different than that of LocTimer. It gets + created when LocTimer::start() is called, and gets deleted + when it expires or clients calls the hosting LocTimer obj's + stop() method. When a LocTimerDelegate obj is ticking, it + stays in the corresponding LocTimerContainer. When expired + or stopped, the obj is removed from the container. Since it + is also a LocRankable obj, and LocTimerContainer also is a + heap, its ranks() implementation decides where it is placed + in the heap. +LocTimerContainer - core of the timer service. It is a container (derived from + LocHeap) for LocTimerDelegate (implements LocRankable) objs. + There are 2 of such containers, one for sw timers (or Linux + timers) one for hw timers (or Linux alarms). It adds one of + each (those that expire the soonest) to kernel via services + provided by LocTimerPollTask. All the heap management on the + LocTimerDelegate objs are done in the MsgTask context, such + that synchronization is ensured. +LocTimerPollTask - is a class that wraps timerfd and epoll POXIS APIs. It also + both implements LocRunnalbe with epoll_wait() in the run() + method. It is also a LocThread client, so as to loop the run + method. +LocTimerWrapper - a LocTimer client itself, to implement the existing C API with + APIs, loc_timer_start() and loc_timer_stop(). + +*/ + +class LocTimerPollTask; + +// This is a multi-functaional class that: +// * extends the LocHeap class for the detection of head update upon add / remove +// events. When that happens, soonest time out changes, so timerfd needs update. +// * contains the timers, and add / remove them into the heap +// * provides and maps 2 of such containers, one for timers (or mSwTimers), one +// for alarms (or mHwTimers); +// * provides a polling thread; +// * provides a MsgTask thread for synchronized add / remove / timer client callback. +class LocTimerContainer : public LocHeap { + // mutex to synchronize getters of static members + static pthread_mutex_t mMutex; + // Container of timers + static LocTimerContainer* mSwTimers; + // Container of alarms + static LocTimerContainer* mHwTimers; + // Msg task to provider msg Q, sender and reader. + static MsgTask* mMsgTask; + // Poll task to provide epoll call and threading to poll. + static LocTimerPollTask* mPollTask; + // timer / alarm fd + int mDevFd; + // ctor + LocTimerContainer(bool wakeOnExpire); + // dtor + ~LocTimerContainer(); + static MsgTask* getMsgTaskLocked(); + static LocTimerPollTask* getPollTaskLocked(); + // extend LocHeap and pop if the top outRanks input + LocTimerDelegate* popIfOutRanks(LocTimerDelegate& timer); + // update the timer POSIX calls with updated soonest timer spec + void updateSoonestTime(LocTimerDelegate* priorTop); + +public: + // factory method to control the creation of mSwTimers / mHwTimers + static LocTimerContainer* get(bool wakeOnExpire); + + LocTimerDelegate* getSoonestTimer(); + int getTimerFd(); + // add a timer / alarm obj into the container + void add(LocTimerDelegate& timer); + // remove a timer / alarm obj from the container + void remove(LocTimerDelegate& timer); + // handling of timer / alarm expiration + void expire(); +}; + +class TimerRunnable : public LocRunnable { + const int mFd; +public: + inline TimerRunnable(const int fd) : mFd(fd) {} + // The method to be implemented by thread clients + // and be scheduled by LocThread + // This method will be repeated called until it returns false; or + // until thread is stopped. + virtual bool run() override; + + // The method to wake up the potential blocking thread + // no op if not applicable + inline virtual void interrupt() { close(mFd); } +}; + +// This class implements the polling thread that epolls imer / alarm fds. +// The LocRunnable::run() contains the actual polling. The other methods +// will be run in the caller's thread context to add / remove timer / alarm +// fds the kernel, while the polling is blocked on epoll_wait() call. +// Since the design is that we have maximally 2 polls, one for all the +// timers; one for all the alarms, we will poll at most on 2 fds. But it +// is possile that all we have are only timers or alarms at one time, so we +// allow dynamically add / remove fds we poll on. The design decision of +// having 1 fd per container of timer / alarm is such that, we may not need +// to make a system call each time a timer / alarm is added / removed, unless +// that changes the "soonest" time out of that of all the timers / alarms. +class LocTimerPollTask { + // the epoll fd + const int mFd; + // the thread that calls TimerRunnable::run() method, where + // epoll_wait() is blocking and waiting for events.. + LocThread mThread; +public: + // ctor + LocTimerPollTask(); + // dtor + ~LocTimerPollTask() = default; + // add a container of timers. Each contain has a unique device fd, i.e. + // either timer or alarm fd, and a heap of timers / alarms. It is expected + // that container would have written to the device fd with the soonest + // time out value in the heap at the time of calling this method. So all + // this method does is to add the fd of the input container to the poll + // and also add the pointer of the container to the event data ptr, such + // when poll_wait wakes up on events, we know who is the owner of the fd. + void addPoll(LocTimerContainer& timerContainer); + // remove a fd that is assciated with a container. The expectation is that + // the atual timer would have been removed from the container. + void removePoll(LocTimerContainer& timerContainer); +}; + +// Internal class of timer obj. It gets born when client calls LocTimer::start(); +// and gets deleted when client calls LocTimer::stop() or when the it expire()'s. +// This class implements LocRankable::ranks() so that when an obj is added into +// the container (of LocHeap), it gets placed in sorted order. +class LocTimerDelegate : public LocRankable { + friend class LocTimerContainer; + friend class LocTimer; + LocTimer* mClient; + LocSharedLock* mLock; + struct timespec mFutureTime; + LocTimerContainer* mContainer; + // not a complete obj, just ctor for LocRankable comparisons + inline LocTimerDelegate(struct timespec& delay) + : mClient(NULL), mLock(NULL), mFutureTime(delay), mContainer(NULL) {} + inline ~LocTimerDelegate() { if (mLock) { mLock->drop(); mLock = NULL; } } +public: + LocTimerDelegate(LocTimer& client, struct timespec& futureTime, LocTimerContainer* container); + void destroyLocked(); + // LocRankable virtual method + virtual int ranks(LocRankable& rankable); + void expire(); + inline struct timespec getFutureTime() { return mFutureTime; } +}; + +/***************************LocTimerContainer methods***************************/ + +// Most of these static recources are created on demand. They however are never +// destoyed. The theory is that there are processes that link to this util lib +// but never use timer, then these resources would never need to be created. +// For those processes that do use timer, it will likely also need to every +// once in a while. It might be cheaper keeping them around. +pthread_mutex_t LocTimerContainer::mMutex = PTHREAD_MUTEX_INITIALIZER; +LocTimerContainer* LocTimerContainer::mSwTimers = NULL; +LocTimerContainer* LocTimerContainer::mHwTimers = NULL; +MsgTask* LocTimerContainer::mMsgTask = NULL; +LocTimerPollTask* LocTimerContainer::mPollTask = NULL; + +// ctor - initialize timer heaps +// A container for swTimer (timer) is created, when wakeOnExpire is true; or +// HwTimer (alarm), when wakeOnExpire is false. +LocTimerContainer::LocTimerContainer(bool wakeOnExpire) : + mDevFd(timerfd_create(wakeOnExpire ? CLOCK_BOOTTIME_ALARM : CLOCK_BOOTTIME, 0)) { + + if ((-1 == mDevFd) && (errno == EINVAL)) { + LOC_LOGW("%s: timerfd_create failure, fallback to CLOCK_MONOTONIC - %s", + __FUNCTION__, strerror(errno)); + mDevFd = timerfd_create(CLOCK_MONOTONIC, 0); + } + + if (-1 != mDevFd) { + // ensure we have the necessary resources created + LocTimerContainer::getPollTaskLocked(); + LocTimerContainer::getMsgTaskLocked(); + } else { + LOC_LOGE("%s: timerfd_create failure - %s", __FUNCTION__, strerror(errno)); + } +} + +// dtor +// we do not ever destroy the static resources. +inline +LocTimerContainer::~LocTimerContainer() { + close(mDevFd); +} + +LocTimerContainer* LocTimerContainer::get(bool wakeOnExpire) { + // get the reference of either mHwTimer or mSwTimers per wakeOnExpire + LocTimerContainer*& container = wakeOnExpire ? mHwTimers : mSwTimers; + // it is cheap to check pointer first than locking mutext unconditionally + if (!container) { + pthread_mutex_lock(&mMutex); + // let's check one more time to be safe + if (!container) { + container = new LocTimerContainer(wakeOnExpire); + // timerfd_create failure + if (-1 == container->getTimerFd()) { + delete container; + container = NULL; + } + } + pthread_mutex_unlock(&mMutex); + } + return container; +} + +MsgTask* LocTimerContainer::getMsgTaskLocked() { + // it is cheap to check pointer first than locking mutext unconditionally + if (!mMsgTask) { + mMsgTask = new MsgTask("LocTimerMsgTask"); + } + return mMsgTask; +} + +LocTimerPollTask* LocTimerContainer::getPollTaskLocked() { + // it is cheap to check pointer first than locking mutext unconditionally + if (!mPollTask) { + mPollTask = new LocTimerPollTask(); + } + return mPollTask; +} + +inline +LocTimerDelegate* LocTimerContainer::getSoonestTimer() { + return (LocTimerDelegate*)(peek()); +} + +inline +int LocTimerContainer::getTimerFd() { + return mDevFd; +} + +void LocTimerContainer::updateSoonestTime(LocTimerDelegate* priorTop) { + LocTimerDelegate* curTop = getSoonestTimer(); + + // check if top has changed + if (curTop != priorTop) { + struct itimerspec delay; + memset(&delay, 0, sizeof(struct itimerspec)); + bool toSetTime = false; + // if tree is empty now, we remove poll and disarm timer + if (!curTop) { + mPollTask->removePoll(*this); + // setting the values to disarm timer + delay.it_value.tv_sec = 0; + delay.it_value.tv_nsec = 0; + toSetTime = true; + } else if (!priorTop || curTop->outRanks(*priorTop)) { + // do this first to avoid race condition, in case settime is called + // with too small an interval + mPollTask->addPoll(*this); + delay.it_value = curTop->getFutureTime(); + toSetTime = true; + } + if (toSetTime) { + timerfd_settime(getTimerFd(), TFD_TIMER_ABSTIME, &delay, NULL); + } + } +} + +// all the heap management is done in the MsgTask context. +inline +void LocTimerContainer::add(LocTimerDelegate& timer) { + struct MsgTimerPush : public LocMsg { + LocTimerContainer* mTimerContainer; + LocTimerDelegate* mTimer; + inline MsgTimerPush(LocTimerContainer& container, LocTimerDelegate& timer) : + LocMsg(), mTimerContainer(&container), mTimer(&timer) {} + inline virtual void proc() const { + LocTimerDelegate* priorTop = mTimerContainer->getSoonestTimer(); + mTimerContainer->push((LocRankable&)(*mTimer)); + mTimerContainer->updateSoonestTime(priorTop); + } + }; + + mMsgTask->sendMsg(new MsgTimerPush(*this, timer)); +} + +// all the heap management is done in the MsgTask context. +void LocTimerContainer::remove(LocTimerDelegate& timer) { + struct MsgTimerRemove : public LocMsg { + LocTimerContainer* mTimerContainer; + LocTimerDelegate* mTimer; + inline MsgTimerRemove(LocTimerContainer& container, LocTimerDelegate& timer) : + LocMsg(), mTimerContainer(&container), mTimer(&timer) {} + inline virtual void proc() const { + LocTimerDelegate* priorTop = mTimerContainer->getSoonestTimer(); + + // update soonest timer only if mTimer is actually removed from + // mTimerContainer AND mTimer is not priorTop. + if (priorTop == ((LocHeap*)mTimerContainer)->remove((LocRankable&)*mTimer)) { + // if passing in NULL, we tell updateSoonestTime to update + // kernel with the current top timer interval. + mTimerContainer->updateSoonestTime(NULL); + } + // all timers are deleted here, and only here. + delete mTimer; + } + }; + + mMsgTask->sendMsg(new MsgTimerRemove(*this, timer)); +} + +// all the heap management is done in the MsgTask context. +// Upon expire, we check and continuously pop the heap until +// the top node's timeout is in the future. +void LocTimerContainer::expire() { + struct MsgTimerExpire : public LocMsg { + LocTimerContainer* mTimerContainer; + inline MsgTimerExpire(LocTimerContainer& container) : + LocMsg(), mTimerContainer(&container) {} + inline virtual void proc() const { + struct timespec now; + // get time spec of now + clock_gettime(CLOCK_BOOTTIME, &now); + LocTimerDelegate timerOfNow(now); + // pop everything in the heap that outRanks now, i.e. has time older than now + // and then call expire() on that timer. + for (LocTimerDelegate* timer = (LocTimerDelegate*)mTimerContainer->pop(); + NULL != timer; + timer = mTimerContainer->popIfOutRanks(timerOfNow)) { + // the timer delegate obj will be deleted before the return of this call + timer->expire(); + } + mTimerContainer->updateSoonestTime(NULL); + } + }; + + struct itimerspec delay; + memset(&delay, 0, sizeof(struct itimerspec)); + timerfd_settime(getTimerFd(), TFD_TIMER_ABSTIME, &delay, NULL); + mPollTask->removePoll(*this); + mMsgTask->sendMsg(new MsgTimerExpire(*this)); +} + +LocTimerDelegate* LocTimerContainer::popIfOutRanks(LocTimerDelegate& timer) { + LocTimerDelegate* poppedNode = NULL; + if (mTree && !timer.outRanks(*peek())) { + poppedNode = (LocTimerDelegate*)(pop()); + } + + return poppedNode; +} + + +/***************************LocTimerPollTask methods***************************/ + +inline +LocTimerPollTask::LocTimerPollTask() + : mFd(epoll_create(2)), mThread() { + // before a next call returens, a thread will be created. The run() method + // could already be running in parallel. Also, since each of the objs + // creates a thread, the container will make sure that there will be only + // one of such obj for our timer implementation. + mThread.start("LocTimerPollTask", std::make_shared(mFd)); +} + +void LocTimerPollTask::addPoll(LocTimerContainer& timerContainer) { + struct epoll_event ev; + memset(&ev, 0, sizeof(ev)); + + ev.events = EPOLLIN; + ev.data.fd = timerContainer.getTimerFd(); + // it is important that we set this context pointer with the input + // timer container this is how we know which container should handle + // which expiration. + ev.data.ptr = &timerContainer; + + epoll_ctl(mFd, EPOLL_CTL_ADD, timerContainer.getTimerFd(), &ev); +} + +inline +void LocTimerPollTask::removePoll(LocTimerContainer& timerContainer) { + epoll_ctl(mFd, EPOLL_CTL_DEL, timerContainer.getTimerFd(), NULL); +} + +// The polling thread context will call this method. If run() method needs to +// be repetitvely called, it must return true from the previous call. +bool TimerRunnable::run() { + struct epoll_event ev[2]; + + // we have max 2 descriptors to poll from + int fds = epoll_wait(mFd, ev, 2, -1); + + // we pretty much want to continually poll until the fd is closed + bool rerun = (fds > 0) || (errno == EINTR); + + if (fds > 0) { + // we may have 2 events + for (int i = 0; i < fds; i++) { + // each fd has a context pointer associated with the right timer container + LocTimerContainer* container = (LocTimerContainer*)(ev[i].data.ptr); + if (container) { + container->expire(); + } else { + epoll_ctl(mFd, EPOLL_CTL_DEL, ev[i].data.fd, NULL); + } + } + } + + // if rerun is true, we are requesting to be scheduled again + return rerun; +} + +/***************************LocTimerDelegate methods***************************/ + +inline +LocTimerDelegate::LocTimerDelegate(LocTimer& client, + struct timespec& futureTime, + LocTimerContainer* container) + : mClient(&client), + mLock(mClient->mLock->share()), + mFutureTime(futureTime), + mContainer(container) { + // adding the timer into the container + mContainer->add(*this); +} + +inline +void LocTimerDelegate::destroyLocked() { + // client handle will likely be deleted soon after this + // method returns. Nulling this handle so that expire() + // won't call the callback on the dead handle any more. + mClient = NULL; + + if (mContainer) { + LocTimerContainer* container = mContainer; + mContainer = NULL; + if (container) { + container->remove(*this); + } + } // else we do not do anything. No such *this* can be + // created and reached here with mContainer ever been + // a non NULL. So *this* must have reached the if clause + // once, and we want it reach there only once. +} + +int LocTimerDelegate::ranks(LocRankable& rankable) { + int rank = -1; + LocTimerDelegate* timer = (LocTimerDelegate*)(&rankable); + if (timer) { + // larger time ranks lower!!! + // IOW, if input obj has bigger tv_sec/tv_nsec, this obj outRanks higher + rank = timer->mFutureTime.tv_sec - mFutureTime.tv_sec; + if(0 == rank) + { + //rank against tv_nsec for msec accuracy + rank = (int)(timer->mFutureTime.tv_nsec - mFutureTime.tv_nsec); + } + } + return rank; +} + +inline +void LocTimerDelegate::expire() { + // keeping a copy of client pointer to be safe + // when timeOutCallback() is called at the end of this + // method, *this* obj may be already deleted. + LocTimer* client = mClient; + // force a stop, which will lead to delete of this obj + if (client && client->stop()) { + // calling client callback with a pointer save on the stack + // only if stop() returns true, i.e. it hasn't been stopped + // already. + client->timeOutCallback(); + } +} + + +/***************************LocTimer methods***************************/ +LocTimer::LocTimer() : mTimer(NULL), mLock(new LocSharedLock()) { +} + +LocTimer::~LocTimer() { + stop(); + if (mLock) { + mLock->drop(); + mLock = NULL; + } +} + +bool LocTimer::start(unsigned int timeOutInMs, bool wakeOnExpire) { + bool success = false; + mLock->lock(); + if (!mTimer) { + struct timespec futureTime; + clock_gettime(CLOCK_BOOTTIME, &futureTime); + futureTime.tv_sec += timeOutInMs / 1000; + futureTime.tv_nsec += (timeOutInMs % 1000) * 1000000; + if (futureTime.tv_nsec >= 1000000000) { + futureTime.tv_sec += futureTime.tv_nsec / 1000000000; + futureTime.tv_nsec %= 1000000000; + } + + LocTimerContainer* container; + container = LocTimerContainer::get(wakeOnExpire); + if (NULL != container) { + mTimer = new LocTimerDelegate(*this, futureTime, container); + // if mTimer is non 0, success should be 0; or vice versa + } + success = (NULL != mTimer); + } + mLock->unlock(); + return success; +} + +bool LocTimer::stop() { + bool success = false; + mLock->lock(); + if (mTimer) { + LocTimerDelegate* timer = mTimer; + mTimer = NULL; + if (timer) { + timer->destroyLocked(); + success = true; + } + } + mLock->unlock(); + return success; +} + +/***************************LocTimerWrapper methods***************************/ +////////////////////////////////////////////////////////////////////////// +// This section below wraps for the C style APIs +////////////////////////////////////////////////////////////////////////// +class LocTimerWrapper : public LocTimer { + loc_timer_callback mCb; + void* mCallerData; + LocTimerWrapper* mMe; + static pthread_mutex_t mMutex; + inline ~LocTimerWrapper() { mCb = NULL; mMe = NULL; } +public: + inline LocTimerWrapper(loc_timer_callback cb, void* callerData) : + mCb(cb), mCallerData(callerData), mMe(this) { + } + void destroy() { + pthread_mutex_lock(&mMutex); + if (NULL != mCb && this == mMe) { + delete this; + } + pthread_mutex_unlock(&mMutex); + } + virtual void timeOutCallback() { + loc_timer_callback cb = mCb; + void* callerData = mCallerData; + if (cb) { + cb(callerData, 0); + } + destroy(); + } +}; + +} // namespace loc_util + +////////////////////////////////////////////////////////////////////////// +// This section below wraps for the C style APIs +////////////////////////////////////////////////////////////////////////// + +using loc_util::LocTimerWrapper; + +pthread_mutex_t LocTimerWrapper::mMutex = PTHREAD_MUTEX_INITIALIZER; + +void* loc_timer_start(uint64_t msec, loc_timer_callback cb_func, + void *caller_data, bool wake_on_expire) +{ + LocTimerWrapper* locTimerWrapper = NULL; + + if (cb_func) { + locTimerWrapper = new LocTimerWrapper(cb_func, caller_data); + + if (locTimerWrapper) { + locTimerWrapper->start(msec, wake_on_expire); + } + } + + return locTimerWrapper; +} + +void loc_timer_stop(void*& handle) +{ + if (handle) { + LocTimerWrapper* locTimerWrapper = (LocTimerWrapper*)(handle); + locTimerWrapper->destroy(); + handle = NULL; + } +} diff --git a/gps/utils/LocTimer.h b/gps/utils/LocTimer.h new file mode 100644 index 0000000..c883de2 --- /dev/null +++ b/gps/utils/LocTimer.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_TIMER_CPP_H__ +#define __LOC_TIMER_CPP_H__ + +#include +#include + +namespace loc_util { + +// opaque class to provide service implementation. +class LocTimerDelegate; +class LocSharedLock; + +// LocTimer client must extend this class and implementthe callback. +// start() / stop() methods are to arm / disarm timer. +class LocTimer +{ + LocTimerDelegate* mTimer; + LocSharedLock* mLock; + // don't really want mLock to be manipulated by clients, yet LocTimer + // has to have a reference to the lock so that the delete of LocTimer + // and LocTimerDelegate can work together on their share resources. + friend class LocTimerDelegate; + +public: + LocTimer(); + virtual ~LocTimer(); + + // timeOutInMs: timeout delay in ms + // wakeOnExpire: true if to wake up CPU (if sleeping) upon timer + // expiration and notify the client. + // false if to wait until next time CPU wakes up (if + // sleeping) and then notify the client. + // return: true on success; + // false on failure, e.g. timer is already running. + bool start(uint32_t timeOutInMs, bool wakeOnExpire); + + // return: true on success; + // false on failure, e.g. timer is not running. + bool stop(); + + // LocTimer client Should implement this method. + // This method is used for timeout calling back to client. This method + // should be short enough (eg: send a message to your own thread). + virtual void timeOutCallback() = 0; +}; + +} // namespace loc_util + +#endif //__LOC_DELAY_H__ diff --git a/gps/utils/LocUnorderedSetMap.h b/gps/utils/LocUnorderedSetMap.h new file mode 100644 index 0000000..7b25ad0 --- /dev/null +++ b/gps/utils/LocUnorderedSetMap.h @@ -0,0 +1,201 @@ +/* Copyright (c) 2015, 2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __LOC_UNORDERDED_SETMAP_H__ +#define __LOC_UNORDERDED_SETMAP_H__ + +#include +#include + +#ifdef NO_UNORDERED_SET_OR_MAP + #include + #include +#else + #include + #include +#endif + +using std::unordered_set; +using std::unordered_map; + +namespace loc_util { + +// Trim from *fromSet* any elements that also exist in *rVals*. +// The optional *goneVals*, if not null, will be populated with removed elements. +template +inline static void trimSet(unordered_set& fromSet, const unordered_set& rVals, + unordered_set* goneVals) { + for (auto val : rVals) { + if (fromSet.erase(val) > 0 && nullptr != goneVals) { + goneVals->insert(val); + } + } +} + +// this method is destructive to the input unordered_sets. +// the return set is the interset extracted out from the two input sets, *s1* and *s2*. +// *s1* and *s2* will be left with the intersect removed from them. +template +static unordered_set removeAndReturnInterset(unordered_set& s1, unordered_set& s2) { + unordered_set common = {}; + for (auto b = s2.begin(); b != s2.end(); b++) { + auto a = find(s1.begin(), s1.end(), *b); + if (a != s1.end()) { + // this is a common item of both l1 and l2, remove from both + // but after we add to common + common.insert(*a); + s1.erase(a); + s2.erase(b); + } + } + return common; +} + +template +class LocUnorderedSetMap { + unordered_map> mMap; + + // Trim the VALs pointed to by *iter*, with everything that also exist in *rVals*. + // If the set becomes empty, remove the map entry. *goneVals*, if not null, records + // the trimmed VALs. + bool trimOrRemove(typename unordered_map>::iterator iter, + const unordered_set& rVals, unordered_set* goneVals) { + trimSet(iter->second, rVals, goneVals); + bool removeEntry = (iter->second.empty()); + if (removeEntry) { + mMap.erase(iter); + } + return removeEntry; + } + +public: + inline LocUnorderedSetMap() {} + inline LocUnorderedSetMap(size_t size) : LocUnorderedSetMap() { + mMap.get_allocator().allocate(size); + } + + inline bool empty() { return mMap.empty(); } + + // This gets the raw pointer to the VALs pointed to by *key* + // If the entry is not in the map, nullptr will be returned. + inline unordered_set* getValSetPtr(const KEY& key) { + auto entry = mMap.find(key); + return (entry != mMap.end()) ? &(entry->second) : nullptr; + } + + // This gets a copy of VALs pointed to by *key* + // If the entry is not in the map, an empty set will be returned. + inline unordered_set getValSet(const KEY& key) { + auto entry = mMap.find(key); + return (entry != mMap.end()) ? entry->second : unordered_set{}; + } + + // This gets all the KEYs from the map + inline unordered_set getKeys() { + unordered_set keys = {}; + for (auto entry : mMap) { + keys.insert(entry.first); + } + return keys; + } + + inline bool remove(const KEY& key) { + return mMap.erase(key) > 0; + } + + // This looks into all the entries keyed by *keys*. Remove any VALs from the entries + // that also exist in *rVals*. If the entry is left with an empty set, the entry will + // be removed. The optional parameters *goneKeys* and *goneVals* will record the KEYs + // (or entries) and the collapsed VALs removed from the map, respectively. + inline void trimOrRemove(unordered_set&& keys, const unordered_set& rVals, + unordered_set* goneKeys, unordered_set* goneVals) { + trimOrRemove(keys, rVals, goneKeys, goneVals); + } + + inline void trimOrRemove(unordered_set& keys, const unordered_set& rVals, + unordered_set* goneKeys, unordered_set* goneVals) { + for (auto key : keys) { + auto iter = mMap.find(key); + if (iter != mMap.end() && trimOrRemove(iter, rVals, goneVals) && nullptr != goneKeys) { + goneKeys->insert(iter->first); + } + } + } + + // This adds all VALs from *newVals* to the map entry keyed by *key*. Or if it + // doesn't exist yet, add the set to the map. + bool add(const KEY& key, const unordered_set& newVals) { + bool newEntryAdded = false; + if (!newVals.empty()) { + auto iter = mMap.find(key); + if (iter != mMap.end()) { + iter->second.insert(newVals.begin(), newVals.end()); + } else { + mMap[key] = newVals; + newEntryAdded = true; + } + } + return newEntryAdded; + } + + // This adds to each of entries in the map keyed by *keys* with the VALs in the + // *enwVals*. If there new entries added (new key in *keys*), *newKeys*, if not + // null, would be populated with those keys. + inline void add(const unordered_set& keys, const unordered_set&& newVals, + unordered_set* newKeys) { + add(keys, newVals, newKeys); + } + + inline void add(const unordered_set& keys, const unordered_set& newVals, + unordered_set* newKeys) { + for (auto key : keys) { + if (add(key, newVals) && nullptr != newKeys) { + newKeys->insert(key); + } + } + } + + // This puts *newVals* into the map keyed by *key*, and returns the VALs that are + // in effect removed from the keyed VAL set in the map entry. + // This call would also remove those same VALs from *newVals*. + inline unordered_set update(const KEY& key, unordered_set& newVals) { + unordered_set goneVals = {}; + if (newVals.empty()) { + mMap.erase(key); + } else { + auto curVals = mMap[key]; + mMap[key] = newVals; + goneVals = removeAndReturnInterset(curVals, newVals); + } + return goneVals; + } +}; + +} // namespace loc_util + +#endif // #ifndef __LOC_UNORDERDED_SETMAP_H__ diff --git a/gps/utils/LogBuffer.cpp b/gps/utils/LogBuffer.cpp new file mode 100644 index 0000000..c280c82 --- /dev/null +++ b/gps/utils/LogBuffer.cpp @@ -0,0 +1,189 @@ +/* Copyright (c) 2019 - 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "LogBuffer.h" +#ifdef USE_GLIB +#include +#endif + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "LocSvc_LogBuffer" + +namespace loc_util { + +LogBuffer* LogBuffer::mInstance; +struct sigaction LogBuffer::mOriSigAction[NSIG]; +struct sigaction LogBuffer::mNewSigAction; +mutex LogBuffer::sLock; + +LogBuffer* LogBuffer::getInstance() { + if (mInstance == nullptr) { + lock_guard guard(sLock); + if (mInstance == nullptr) { + mInstance = new LogBuffer(); + } + } + return mInstance; +} + +LogBuffer::LogBuffer(): mLogList(TOTAL_LOG_LEVELS), + mConfigVec(TOTAL_LOG_LEVELS, ConfigsInLevel(TIME_DEPTH_THRESHOLD_MINIMAL_IN_SEC, + MAXIMUM_NUM_IN_LIST, 0)) { + loc_param_s_type log_buff_config_table[] = + { + {"E_LEVEL_TIME_DEPTH", &mConfigVec[0].mTimeDepthThres, NULL, 'n'}, + {"E_LEVEL_MAX_CAPACITY", &mConfigVec[0].mMaxNumThres, NULL, 'n'}, + {"W_LEVEL_TIME_DEPTH", &mConfigVec[1].mTimeDepthThres, NULL, 'n'}, + {"W_LEVEL_MAX_CAPACITY", &mConfigVec[1].mMaxNumThres, NULL, 'n'}, + {"I_LEVEL_TIME_DEPTH", &mConfigVec[2].mTimeDepthThres, NULL, 'n'}, + {"I_LEVEL_MAX_CAPACITY", &mConfigVec[2].mMaxNumThres, NULL, 'n'}, + {"D_LEVEL_TIME_DEPTH", &mConfigVec[3].mTimeDepthThres, NULL, 'n'}, + {"D_LEVEL_MAX_CAPACITY", &mConfigVec[3].mMaxNumThres, NULL, 'n'}, + {"V_LEVEL_TIME_DEPTH", &mConfigVec[4].mTimeDepthThres, NULL, 'n'}, + {"V_LEVEL_MAX_CAPACITY", &mConfigVec[4].mMaxNumThres, NULL, 'n'}, + }; + loc_read_conf(LOC_PATH_GPS_CONF_STR, log_buff_config_table, + sizeof(log_buff_config_table)/sizeof(log_buff_config_table[0])); + registerSignalHandler(); +} + +void LogBuffer::append(string& data, int level, uint64_t timestamp) { + lock_guard guard(mLock); + pair item(timestamp, data); + mLogList.append(item, level); + mConfigVec[level].mCurrentSize++; + + while ((timestamp - mLogList.front(level).first) > mConfigVec[level].mTimeDepthThres || + mConfigVec[level].mCurrentSize > mConfigVec[level].mMaxNumThres) { + mLogList.pop(level); + mConfigVec[level].mCurrentSize--; + } +} + +//Dump the log buffer of specific level, level = -1 to dump all the levels in log buffer. +void LogBuffer::dump(std::function log, int level) { + lock_guard guard(mLock); + list, int>> li; + if (-1 == level) { + li = mLogList.dump(); + } else { + li = mLogList.dump(level); + } + ALOGE("Begining of dump, buffer size: %d", (int)li.size()); + stringstream ln; + ln << "dump log buffer, level[" << level << "]" << ", buffer size: " << li.size() << endl; + log(ln); + for_each (li.begin(), li.end(), [&, this](const pair, int> &item){ + stringstream line; + line << "["<append(s, 0, elapsedTime); + } + } +#endif + //Dump the log buffer to adb logcat + mInstance->dumpToAdbLogcat(); + + //Dump the log buffer to file + time_t now = time(NULL); + struct tm *curr_time = localtime(&now); + char path[50]; + snprintf(path, 50, LOG_BUFFER_FILE_PATH "gpslog_%d%d%d-%d%d%d.log", + (1900 + curr_time->tm_year), ( 1 + curr_time->tm_mon), curr_time->tm_mday, + curr_time->tm_hour, curr_time->tm_min, curr_time->tm_sec); + + mInstance->dumpToLogFile(path); + + //Process won't be terminated if SIGUSR1 is recieved + if (code != SIGUSR1) { + mOriSigAction[code].sa_sigaction(code, si, sc); + } +} + +} diff --git a/gps/utils/LogBuffer.h b/gps/utils/LogBuffer.h new file mode 100644 index 0000000..8d90439 --- /dev/null +++ b/gps/utils/LogBuffer.h @@ -0,0 +1,95 @@ +/* Copyright (c) 2019 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOG_BUFFER_H +#define LOG_BUFFER_H + +#include "SkipList.h" +#include "log_util.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//default error level time depth threshold, +#define TIME_DEPTH_THRESHOLD_MINIMAL_IN_SEC 60 +//default maximum log buffer size +#define MAXIMUM_NUM_IN_LIST 50 +//file path of dumped log buffer +#define LOG_BUFFER_FILE_PATH "/data/vendor/location/" + +namespace loc_util { + +class ConfigsInLevel{ +public: + uint32_t mTimeDepthThres; + uint32_t mMaxNumThres; + int mCurrentSize; + + ConfigsInLevel(uint32_t time, int num, int size): + mTimeDepthThres(time), mMaxNumThres(num), mCurrentSize(size) {} +}; + +class LogBuffer { +private: + static LogBuffer* mInstance; + static struct sigaction mOriSigAction[NSIG]; + static struct sigaction mNewSigAction; + static mutex sLock; + + SkipList> mLogList; + vector mConfigVec; + mutex mLock; + + const vector mLevelMap {"E", "W", "I", "D", "V"}; + +public: + static LogBuffer* getInstance(); + void append(string& data, int level, uint64_t timestamp); + void dump(std::function log, int level = -1); + void dumpToAdbLogcat(); + void dumpToLogFile(string filePath); + void flush(); +private: + LogBuffer(); + void registerSignalHandler(); + static void signalHandler(const int code, siginfo_t *const si, void *const sc); + +}; + +} + +#endif diff --git a/gps/utils/Makefile.am b/gps/utils/Makefile.am new file mode 100644 index 0000000..ada504c --- /dev/null +++ b/gps/utils/Makefile.am @@ -0,0 +1,75 @@ +ACLOCAL_AMFLAGS = -I m4 + +AM_CFLAGS = -Wundef \ + -MD \ + -Wno-trigraphs \ + -g -O0 \ + -fno-inline \ + -fno-short-enums \ + -fpic \ + -I./ \ + -std=c++14 \ + $(LOCPLA_CFLAGS) + +libgps_utils_la_h_sources = \ + msg_q.h \ + linked_list.h \ + loc_cfg.h \ + loc_log.h \ + loc_target.h \ + loc_timer.h \ + MsgTask.h \ + LocHeap.h \ + LocThread.h \ + LocTimer.h \ + LocIpc.h \ + SkipList.h\ + loc_misc_utils.h \ + loc_nmea.h \ + gps_extended_c.h \ + gps_extended.h \ + loc_gps.h \ + log_util.h \ + LocSharedLock.h \ + LocUnorderedSetMap.h\ + LocLoggerBase.h + +libgps_utils_la_c_sources = \ + linked_list.c \ + msg_q.c \ + loc_cfg.cpp \ + loc_log.cpp \ + loc_target.cpp \ + LocHeap.cpp \ + LocTimer.cpp \ + LocThread.cpp \ + LocIpc.cpp \ + LogBuffer.cpp \ + MsgTask.cpp \ + loc_misc_utils.cpp \ + loc_nmea.cpp + +library_includedir = $(pkgincludedir) + +library_include_HEADERS = $(libgps_utils_la_h_sources) + +libgps_utils_la_SOURCES = $(libgps_utils_la_c_sources) + +if USE_GLIB +libgps_utils_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +libgps_utils_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 +libgps_utils_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +libgps_utils_la_CFLAGS = $(AM_CFLAGS) +libgps_utils_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0 +libgps_utils_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +libgps_utils_la_LIBADD = $(CUTILS_LIBS) -ldl + +#Create and Install libraries +lib_LTLIBRARIES = libgps_utils.la + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = gps-utils.pc +EXTRA_DIST = $(pkgconfig_DATA) diff --git a/gps/utils/MsgTask.cpp b/gps/utils/MsgTask.cpp new file mode 100644 index 0000000..6ef689a --- /dev/null +++ b/gps/utils/MsgTask.cpp @@ -0,0 +1,120 @@ +/* Copyright (c) 2011-2013, 2015, 2017, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_MsgTask" + +#include +#include +#include +#include +#include +#include + +namespace loc_util { + +class MTRunnable : public LocRunnable { + const void* mQ; +public: + inline MTRunnable(const void* q) : mQ(q) {} + virtual ~MTRunnable(); + // Overrides of LocRunnable methods + // This method will be repeated called until it returns false; or + // until thread is stopped. + virtual bool run() override; + + // The method to be run before thread loop (conditionally repeatedly) + // calls run() + virtual void prerun() override; + + // to interrupt the run() method and come out of that + virtual void interrupt() override; +}; + +static void LocMsgDestroy(void* msg) { + delete (LocMsg*)msg; +} + +MsgTask::MsgTask(const char* threadName) : + mQ(msg_q_init2()), mThread() { + mThread.start(threadName, std::make_shared(mQ)); +} + +void MsgTask::sendMsg(const LocMsg* msg) const { + if (msg && this) { + msg_q_snd((void*)mQ, (void*)msg, LocMsgDestroy); + } else { + LOC_LOGE("%s: msg is %p and this is %p", + __func__, msg, this); + } +} + +void MsgTask::sendMsg(const std::function runnable) const { + struct RunMsg : public LocMsg { + const std::function mRunnable; + public: + inline RunMsg(const std::function runnable) : mRunnable(runnable) {} + ~RunMsg() = default; + inline virtual void proc() const override { mRunnable(); } + }; + sendMsg(new RunMsg(runnable)); +} + +void MTRunnable::interrupt() { + msg_q_unblock((void*)mQ); +} + +void MTRunnable::prerun() { + // make sure we do not run in background scheduling group + set_sched_policy(gettid(), SP_FOREGROUND); +} + +bool MTRunnable::run() { + LocMsg* msg; + msq_q_err_type result = msg_q_rcv((void*)mQ, (void **)&msg); + if (eMSG_Q_SUCCESS != result) { + LOC_LOGE("%s:%d] fail receiving msg: %s\n", __func__, __LINE__, + loc_get_msg_q_status(result)); + return false; + } + + msg->log(); + // there is where each individual msg handling is invoked + msg->proc(); + + delete msg; + + return true; +} + +MTRunnable::~MTRunnable() { + msg_q_flush((void*)mQ); + msg_q_destroy((void**)&mQ); +} + +} // namespace loc_util diff --git a/gps/utils/MsgTask.h b/gps/utils/MsgTask.h new file mode 100644 index 0000000..a8cce9e --- /dev/null +++ b/gps/utils/MsgTask.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2011-2013, 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __MSG_TASK__ +#define __MSG_TASK__ + +#include +#include + +namespace loc_util { + +struct LocMsg { + inline LocMsg() {} + inline virtual ~LocMsg() {} + virtual void proc() const = 0; + inline virtual void log() const {} +}; + +class MsgTask { + const void* mQ; + LocThread mThread; +public: + ~MsgTask() = default; + MsgTask(const char* threadName = NULL); + void sendMsg(const LocMsg* msg) const; + void sendMsg(const std::function runnable) const; +}; + +} // + +#endif //__MSG_TASK__ diff --git a/gps/utils/SkipList.h b/gps/utils/SkipList.h new file mode 100644 index 0000000..afaa1a6 --- /dev/null +++ b/gps/utils/SkipList.h @@ -0,0 +1,158 @@ +/* Copyright (c) 2019 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_SKIP_LIST_H +#define LOC_SKIP_LIST_H + +#include +#include +#include +#include +#include + +using namespace std; + +namespace loc_util { + +template > class container = list> +class SkipNode { +public: + typedef typename container>::iterator NodeIterator; + + int mLevel; + T mData; + NodeIterator mNextInLevel; + + SkipNode(int level, T& data): mLevel(level), mData(data) {} +}; + +template +class SkipList { + using NodeIterator = typename SkipNode::NodeIterator; +private: + list> mMainList; + vector mHeadVec; + vector mTailVec; +public: + SkipList(int totalLevels); + void append(T& data, int level); + void pop(int level); + void pop(); + T front(int level); + int size(); + void flush(); + list> dump(); + list> dump(int level); +}; + +template +SkipList::SkipList(int totalLevels): mHeadVec(totalLevels, mMainList.end()), + mTailVec(totalLevels, mMainList.end()) {} + +template +void SkipList::append(T& data, int level) { + if ( level < 0 || level >= mHeadVec.size()) { + return; + } + + SkipNode node(level, data); + node.mNextInLevel = mMainList.end(); + mMainList.push_back(node); + auto iter = --mMainList.end(); + if (mHeadVec[level] == mMainList.end()) { + mHeadVec[level] = iter; + } else { + (*mTailVec[level]).mNextInLevel = iter; + } + mTailVec[level] = iter; +} + +template +void SkipList::pop(int level) { + if (mHeadVec[level] == mMainList.end()) { + return; + } + + if ((*mHeadVec[level]).mNextInLevel == mMainList.end()) { + mTailVec[level] = mMainList.end(); + } + + auto tmp_iter = (*mHeadVec[level]).mNextInLevel; + mMainList.erase(mHeadVec[level]); + mHeadVec[level] = tmp_iter; +} + +template +void SkipList::pop() { + pop(mMainList.front().mLevel); +} + +template +T SkipList::front(int level) { + return (*mHeadVec[level]).mData; +} + +template +int SkipList::size() { + return mMainList.size(); +} + +template +void SkipList::flush() { + mMainList.clear(); + for (int i = 0; i < mHeadVec.size(); i++) { + mHeadVec[i] = mMainList.end(); + mTailVec[i] = mMainList.end(); + } +} + +template +list> SkipList::dump() { + list> li; + for_each(mMainList.begin(), mMainList.end(), [&](SkipNode &item) { + li.push_back(make_pair(item.mData, item.mLevel)); + }); + return li; +} + +template +list> SkipList::dump(int level) { + list> li; + auto head = mHeadVec[level]; + while (head != mMainList.end()) { + li.push_back(make_pair((*head).mData, (*head).mLevel)); + head = (*head).mNextInLevel; + } + return li; +} + +} + +#endif diff --git a/gps/utils/configure.ac b/gps/utils/configure.ac new file mode 100644 index 0000000..2a04f45 --- /dev/null +++ b/gps/utils/configure.ac @@ -0,0 +1,92 @@ +# configure.ac -- Autoconf script for gps gps-utils +# +# Process this file with autoconf to produce a configure script + +# Requires autoconf tool later than 2.61 +AC_PREREQ(2.61) +# Initialize the gps gps-utils package version 1.0.0 +AC_INIT([gps-utils],1.0.0) +# Does not strictly follow GNU Coding standards +AM_INIT_AUTOMAKE([foreign subdir-objects]) +# Disables auto rebuilding of configure, Makefile.ins +AM_MAINTAINER_MODE +# Verifies the --srcdir is correct by checking for the path +AC_CONFIG_SRCDIR([Makefile.am]) +# defines some macros variable to be included by source +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +# Checks for programs. +AC_PROG_LIBTOOL +AC_PROG_CXX +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_AWK +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +PKG_PROG_PKG_CONFIG + +AC_ARG_WITH([external_ap], + AC_HELP_STRING([--with-external_ap=@<:@dir@:>@], + [Using External Application Processor]), + [], + with_external_ap=no) + +if test "x$with_external_ap" != "xno"; then + CPPFLAGS="${CPPFLAGS} -DFEATURE_EXTERNAL_AP" +else + # Checks for libraries. + PKG_CHECK_MODULES([CUTILS], [libcutils]) + AC_SUBST([CUTILS_CFLAGS]) + AC_SUBST([CUTILS_LIBS]) +fi + +AC_ARG_WITH([core_includes], + AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], + [Specify the location of the core headers]), + [core_incdir=$withval], + with_core_includes=no) + +if test "x$with_core_includes" != "xno"; then + CPPFLAGS="${CPPFLAGS} -I${core_incdir}" +fi + +AC_ARG_WITH([locpla_includes], + AC_HELP_STRING([--with-locpla-includes=@<:@dir@:>@], + [specify the path to locpla-includes in loc-pla_git.bb]), + [locpla_incdir=$withval], + with_locpla_includes=no) + +if test "x$with_locpla_includes" != "xno"; then + AC_SUBST(LOCPLA_CFLAGS, "-I${locpla_incdir}") +fi + +AC_SUBST([CPPFLAGS]) + +AC_ARG_WITH([glib], + AC_HELP_STRING([--with-glib], + [enable glib, building HLOS systems which use glib])) + +if (test "x${with_glib}" = "xyes"); then + AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib]) + PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GThread >= 2.16 is required)) + PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes, + AC_MSG_ERROR(GLib >= 2.16 is required)) + GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS" + GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS" + + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) +fi + +AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes") + +AC_CONFIG_FILES([ \ + Makefile \ + gps-utils.pc + ]) + +AC_OUTPUT diff --git a/gps/utils/gps-utils.pc.in b/gps/utils/gps-utils.pc.in new file mode 100644 index 0000000..a988731 --- /dev/null +++ b/gps/utils/gps-utils.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: gps-utils +Description: QTI GPS Location utils +Version: @VERSION +Libs: -L${libdir} -lgps_utils +Cflags: -I${includedir}/gps-utils diff --git a/gps/utils/gps_extended.h b/gps/utils/gps_extended.h new file mode 100644 index 0000000..2455629 --- /dev/null +++ b/gps/utils/gps_extended.h @@ -0,0 +1,114 @@ +/* Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GPS_EXTENDED_H +#define GPS_EXTENDED_H + +/** + * @file + * @brief C++ declarations for GPS types + */ + +#include +#if defined(USE_GLIB) || defined(OFF_TARGET) +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + + +struct LocPosMode +{ + LocPositionMode mode; + LocGpsPositionRecurrence recurrence; + uint32_t min_interval; + uint32_t preferred_accuracy; + uint32_t preferred_time; + bool share_position; + char credentials[14]; + char provider[8]; + GnssPowerMode powerMode; + uint32_t timeBetweenMeasurements; + LocPosMode(LocPositionMode m, LocGpsPositionRecurrence recr, + uint32_t gap, uint32_t accu, uint32_t time, + bool sp, const char* cred, const char* prov, + GnssPowerMode pMode = GNSS_POWER_MODE_INVALID, + uint32_t tbm = 0) : + mode(m), recurrence(recr), + min_interval(gap < GPS_MIN_POSSIBLE_FIX_INTERVAL_MS ? + GPS_MIN_POSSIBLE_FIX_INTERVAL_MS : gap), + preferred_accuracy(accu), preferred_time(time), + share_position(sp), powerMode(pMode), + timeBetweenMeasurements(tbm) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + if (NULL != cred) { + memcpy(credentials, cred, sizeof(credentials)-1); + } + if (NULL != prov) { + memcpy(provider, prov, sizeof(provider)-1); + } + } + + inline LocPosMode() : + mode(LOC_POSITION_MODE_MS_BASED), + recurrence(LOC_GPS_POSITION_RECURRENCE_PERIODIC), + min_interval(GPS_DEFAULT_FIX_INTERVAL_MS), + preferred_accuracy(50), preferred_time(120000), + share_position(true), powerMode(GNSS_POWER_MODE_INVALID), + timeBetweenMeasurements(GPS_DEFAULT_FIX_INTERVAL_MS) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + } + + inline bool equals(const LocPosMode &anotherMode) const + { + return anotherMode.mode == mode && + anotherMode.recurrence == recurrence && + anotherMode.min_interval == min_interval && + anotherMode.preferred_accuracy == preferred_accuracy && + anotherMode.preferred_time == preferred_time && + anotherMode.powerMode == powerMode && + anotherMode.timeBetweenMeasurements == timeBetweenMeasurements && + !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) && + !strncmp(anotherMode.provider, provider, sizeof(provider)-1); + } + + void logv() const; +}; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GPS_EXTENDED_H */ + diff --git a/gps/utils/gps_extended_c.h b/gps/utils/gps_extended_c.h new file mode 100644 index 0000000..f368975 --- /dev/null +++ b/gps/utils/gps_extended_c.h @@ -0,0 +1,2429 @@ +/* Copyright (c) 2013-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GPS_EXTENDED_C_H +#define GPS_EXTENDED_C_H + +#include +#include +#include +#include +#include +#include + +struct timespec32_t { + uint32_t tv_sec; /* seconds */ + uint32_t tv_nsec; /* and nanoseconds */ +}; + + +/** + * @file + * @brief C++ declarations for GPS types + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** Location has valid source information. */ +#define LOCATION_HAS_SOURCE_INFO 0x0020 +/** LocGpsLocation has valid "is indoor?" flag */ +#define LOC_GPS_LOCATION_HAS_IS_INDOOR 0x0040 +/** LocGpsLocation has valid floor number */ +#define LOC_GPS_LOCATION_HAS_FLOOR_NUMBER 0x0080 +/** LocGpsLocation has valid map URL*/ +#define LOC_GPS_LOCATION_HAS_MAP_URL 0x0100 +/** LocGpsLocation has valid map index */ +#define LOC_GPS_LOCATION_HAS_MAP_INDEX 0x0200 + +#define GNSS_INVALID_JAMMER_IND 0x7FFFFFFF + +/** Sizes for indoor fields */ +#define GPS_LOCATION_MAP_URL_SIZE 400 +#define GPS_LOCATION_MAP_INDEX_SIZE 16 + +/** Position source is ULP */ +#define ULP_LOCATION_IS_FROM_HYBRID 0x0001 +/** Position source is GNSS only */ +#define ULP_LOCATION_IS_FROM_GNSS 0x0002 +/** Position is from a Geofence Breach Event */ +#define ULP_LOCATION_IS_FROM_GEOFENCE 0X0004 +/** Position is from Hardware FLP */ +#define ULP_LOCATION_IS_FROM_HW_FLP 0x0008 +/** Position is from NLP */ +#define ULP_LOCATION_IS_FROM_NLP 0x0010 +/** Position is from external DR solution*/ +#define ULP_LOCATION_IS_FROM_EXT_DR 0X0020 +/** Raw GNSS position fixes */ +#define ULP_LOCATION_IS_FROM_GNSS_RAW 0X0040 + +typedef uint32_t LocSvInfoSource; +/** SVinfo source is GNSS/DR */ +#define ULP_SVINFO_IS_FROM_GNSS ((LocSvInfoSource)0x0001) +/** Raw SVinfo from GNSS */ +#define ULP_SVINFO_IS_FROM_DR ((LocSvInfoSource)0x0002) + +#define ULP_MIN_INTERVAL_INVALID 0xffffffff +#define ULP_MAX_NMEA_STRING_SIZE 201 + +/*Emergency SUPL*/ +#define LOC_GPS_NI_TYPE_EMERGENCY_SUPL 4 + +#define LOC_AGPS_CERTIFICATE_MAX_LENGTH 2000 +#define LOC_AGPS_CERTIFICATE_MAX_SLOTS 10 + +/* TBM Threshold for tracking in background power mode : in millis */ +#define TRACKING_TBM_THRESHOLD_MILLIS 480000 + +/** Maximum number of satellites in an ephemeris report. */ +#define GNSS_EPHEMERIS_LIST_MAX_SIZE_V02 32 + +typedef uint32_t LocPosTechMask; +#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000) +#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001) +#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002) +#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004) +#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008) +#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010) +#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020) +#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040) +#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080) +#define LOC_POS_TECH_MASK_PPE ((LocPosTechMask)0x00000100) +#define LOC_POS_TECH_MASK_VEH ((LocPosTechMask)0x00000200) +#define LOC_POS_TECH_MASK_VIS ((LocPosTechMask)0x00000400) + + +enum loc_registration_mask_status { + LOC_REGISTRATION_MASK_ENABLED, + LOC_REGISTRATION_MASK_DISABLED, + LOC_REGISTRATION_MASK_SET +}; + +typedef enum { + LOC_SUPPORTED_FEATURE_ODCPI_2_V02 = 0, /**< Support ODCPI version 2 feature */ + LOC_SUPPORTED_FEATURE_WIFI_AP_DATA_INJECT_2_V02, /**< Support Wifi AP data inject version 2 feature */ + LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02, /**< Support debug NMEA feature */ + LOC_SUPPORTED_FEATURE_GNSS_ONLY_POSITION_REPORT, /**< Support GNSS Only position reports */ + LOC_SUPPORTED_FEATURE_FDCL, /**< Support FDCL */ + LOC_SUPPORTED_FEATURE_CONSTELLATION_ENABLEMENT_V02, /**< Support constellation enablement */ + LOC_SUPPORTED_FEATURE_AGPM_V02, /**< Support AGPM feature */ + LOC_SUPPORTED_FEATURE_XTRA_INTEGRITY, /**< Support XTRA integrity */ + LOC_SUPPORTED_FEATURE_FDCL_2, /**< Support FDCL V2 */ + LOC_SUPPORTED_FEATURE_LOCATION_PRIVACY, /**< Support location privacy */ + LOC_SUPPORTED_FEATURE_NAVIC, /**< Support NAVIC constellation */ + LOC_SUPPORTED_FEATURE_MEASUREMENTS_CORRECTION, /**< Support measurements correction */ + LOC_SUPPORTED_FEATURE_ROBUST_LOCATION, /**< Support Robust Location feature */ + LOC_SUPPORTED_FEATURE_EDGNSS /**< Support precise location dgnss */ +} loc_supported_feature_enum; + +typedef struct { + /** set to sizeof(UlpLocation) */ + uint32_t size; + LocGpsLocation gpsLocation; + /* Provider indicator for HYBRID or GPS */ + uint16_t position_source; + LocPosTechMask tech_mask; + bool unpropagatedPosition; +} UlpLocation; + +typedef struct { + /** set to sizeof(UlpNmea) */ + uint32_t size; + char nmea_str[ULP_MAX_NMEA_STRING_SIZE]; + unsigned int len; +} UlpNmea; + + +/** AGPS type */ +typedef int8_t AGpsExtType; +#define LOC_AGPS_TYPE_INVALID -1 +#define LOC_AGPS_TYPE_ANY 0 +#define LOC_AGPS_TYPE_SUPL 1 +#define LOC_AGPS_TYPE_C2K 2 +#define LOC_AGPS_TYPE_WWAN_ANY 3 +#define LOC_AGPS_TYPE_WIFI 4 +#define LOC_AGPS_TYPE_SUPL_ES 5 + +/** SSID length */ +#define SSID_BUF_SIZE (32+1) + +typedef int16_t AGpsBearerType; +#define AGPS_APN_BEARER_INVALID 0 +#define AGPS_APN_BEARER_IPV4 1 +#define AGPS_APN_BEARER_IPV6 2 +#define AGPS_APN_BEARER_IPV4V6 3 + +typedef uint32_t LocApnTypeMask; +/**< Denotes APN type for Default/Internet traffic */ +#define LOC_APN_TYPE_MASK_DEFAULT ((LocApnTypeMask)0x00000001) +/**< Denotes APN type for IP Multimedia Subsystem */ +#define LOC_APN_TYPE_MASK_IMS ((LocApnTypeMask)0x00000002) +/**< Denotes APN type for Multimedia Messaging Service */ +#define LOC_APN_TYPE_MASK_MMS ((LocApnTypeMask)0x00000004) +/**< Denotes APN type for Dial Up Network */ +#define LOC_APN_TYPE_MASK_DUN ((LocApnTypeMask)0x00000008) +/**< Denotes APN type for Secure User Plane Location */ +#define LOC_APN_TYPE_MASK_SUPL ((LocApnTypeMask)0x00000010) +/**< Denotes APN type for High Priority Mobile Data */ +#define LOC_APN_TYPE_MASK_HIPRI ((LocApnTypeMask)0x00000020) +/**< Denotes APN type for over the air administration */ +#define LOC_APN_TYPE_MASK_FOTA ((LocApnTypeMask)0x00000040) +/**< Denotes APN type for Carrier Branded Services */ +#define LOC_APN_TYPE_MASK_CBS ((LocApnTypeMask)0x00000080) +/**< Denotes APN type for Initial Attach */ +#define LOC_APN_TYPE_MASK_IA ((LocApnTypeMask)0x00000100) +/**< Denotes APN type for emergency */ +#define LOC_APN_TYPE_MASK_EMERGENCY ((LocApnTypeMask)0x00000200) + +typedef uint32_t AGpsTypeMask; +#define AGPS_ATL_TYPE_SUPL ((AGpsTypeMask)0x00000001) +#define AGPS_ATL_TYPE_SUPL_ES ((AGpsTypeMask)0x00000002) +#define AGPS_ATL_TYPE_WWAN ((AGpsTypeMask)0x00000004) + +typedef struct { + void* statusV4Cb; + AGpsTypeMask atlType; +} AgpsCbInfo; + +typedef struct { + void* visibilityControlCb; + void* isInEmergencySession; +} NfwCbInfo; + +/** GPS extended callback structure. */ +typedef struct { + /** set to sizeof(LocGpsCallbacks) */ + uint32_t size; + loc_gps_set_capabilities set_capabilities_cb; + loc_gps_acquire_wakelock acquire_wakelock_cb; + loc_gps_release_wakelock release_wakelock_cb; + loc_gps_create_thread create_thread_cb; + loc_gps_request_utc_time request_utc_time_cb; +} GpsExtCallbacks; + +/** Callback to report the xtra server url to the client. + * The client should use this url when downloading xtra unless overwritten + * in the gps.conf file + */ +typedef void (* report_xtra_server)(const char*, const char*, const char*); + +/** Callback structure for the XTRA interface. */ +typedef struct { + loc_gps_xtra_download_request download_request_cb; + loc_gps_create_thread create_thread_cb; + report_xtra_server report_xtra_server_cb; +} GpsXtraExtCallbacks; + +/** Represents the status of AGPS. */ +typedef struct { + /** set to sizeof(AGpsExtStatus) */ + uint32_t size; + + AGpsExtType type; + LocAGpsStatusValue status; + uint32_t ipv4_addr; + struct sockaddr_storage addr; + char ssid[SSID_BUF_SIZE]; + char password[SSID_BUF_SIZE]; +} AGpsExtStatus; + +/** Callback with AGPS status information. + * Can only be called from a thread created by create_thread_cb. + */ +typedef void (* agps_status_extended)(AGpsExtStatus* status); + +/** Callback structure for the AGPS interface. */ +typedef struct { + agps_status_extended status_cb; + loc_gps_create_thread create_thread_cb; +} AGpsExtCallbacks; + + +typedef void (*loc_ni_notify_callback)(LocGpsNiNotification *notification, bool esEnalbed); +/** GPS NI callback structure. */ +typedef struct +{ + /** + * Sends the notification request from HAL to GPSLocationProvider. + */ + loc_ni_notify_callback notify_cb; +} GpsNiExtCallbacks; + +typedef enum loc_server_type { + LOC_AGPS_CDMA_PDE_SERVER, + LOC_AGPS_CUSTOM_PDE_SERVER, + LOC_AGPS_MPC_SERVER, + LOC_AGPS_SUPL_SERVER, + LOC_AGPS_MO_SUPL_SERVER +} LocServerType; + +typedef enum loc_position_mode_type { + LOC_POSITION_MODE_INVALID = -1, + LOC_POSITION_MODE_STANDALONE = 0, + LOC_POSITION_MODE_MS_BASED, + LOC_POSITION_MODE_MS_ASSISTED, + LOC_POSITION_MODE_RESERVED_1, + LOC_POSITION_MODE_RESERVED_2, + LOC_POSITION_MODE_RESERVED_3, + LOC_POSITION_MODE_RESERVED_4, + LOC_POSITION_MODE_RESERVED_5 + +} LocPositionMode; + +/** + * @brief Minimum allowed value for fix interval. + * + * This value is a sanity limit in GPS framework. The hardware has own internal + * limits that may not match this value + * + * @sa GPS_DEFAULT_FIX_INTERVAL_MS + */ + +#define GPS_MIN_POSSIBLE_FIX_INTERVAL_MS 100 +/** + * @brief Default value for fix interval. + * + * This value is used by default whenever appropriate. + * + * @sa GPS_MIN_POSSIBLE_FIX_INTERVAL_MS + */ +#define GPS_DEFAULT_FIX_INTERVAL_MS 1000 + +/** Flags to indicate which values are valid in a GpsLocationExtended. */ +typedef uint64_t GpsLocationExtendedFlags; +/** GpsLocationExtended has valid pdop, hdop, vdop. */ +#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001 +/** GpsLocationExtended has valid altitude mean sea level. */ +#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002 +/** UlpLocation has valid magnetic deviation. */ +#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004 +/** UlpLocation has valid mode indicator. */ +#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008 +/** GpsLocationExtended has valid vertical uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010 +/** GpsLocationExtended has valid speed uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020 +/** GpsLocationExtended has valid heading uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_BEARING_UNC 0x0040 +/** GpsLocationExtended has valid horizontal reliability */ +#define GPS_LOCATION_EXTENDED_HAS_HOR_RELIABILITY 0x0080 +/** GpsLocationExtended has valid vertical reliability */ +#define GPS_LOCATION_EXTENDED_HAS_VERT_RELIABILITY 0x0100 +/** GpsLocationExtended has valid Horizontal Elliptical Uncertainty (Semi-Major Axis) */ +#define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MAJOR 0x0200 +/** GpsLocationExtended has valid Horizontal Elliptical Uncertainty (Semi-Minor Axis) */ +#define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_MINOR 0x0400 +/** GpsLocationExtended has valid Elliptical Horizontal Uncertainty Azimuth */ +#define GPS_LOCATION_EXTENDED_HAS_HOR_ELIP_UNC_AZIMUTH 0x0800 +/** GpsLocationExtended has valid gnss sv used in position data */ +#define GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA 0x1000 +/** GpsLocationExtended has valid navSolutionMask */ +#define GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK 0x2000 +/** GpsLocationExtended has valid LocPosTechMask */ +#define GPS_LOCATION_EXTENDED_HAS_POS_TECH_MASK 0x4000 +/** GpsLocationExtended has valid LocSvInfoSource */ +#define GPS_LOCATION_EXTENDED_HAS_SV_SOURCE_INFO 0x8000 +/** GpsLocationExtended has valid position dynamics data */ +#define GPS_LOCATION_EXTENDED_HAS_POS_DYNAMICS_DATA 0x10000 +/** GpsLocationExtended has GPS Time */ +#define GPS_LOCATION_EXTENDED_HAS_GPS_TIME 0x20000 +/** GpsLocationExtended has Extended Dilution of Precision */ +#define GPS_LOCATION_EXTENDED_HAS_EXT_DOP 0x40000 +/** GpsLocationExtended has North standard deviation */ +#define GPS_LOCATION_EXTENDED_HAS_NORTH_STD_DEV 0x80000 +/** GpsLocationExtended has East standard deviation*/ +#define GPS_LOCATION_EXTENDED_HAS_EAST_STD_DEV 0x100000 +/** GpsLocationExtended has North Velocity */ +#define GPS_LOCATION_EXTENDED_HAS_NORTH_VEL 0x200000 +/** GpsLocationExtended has East Velocity */ +#define GPS_LOCATION_EXTENDED_HAS_EAST_VEL 0x400000 +/** GpsLocationExtended has up Velocity */ +#define GPS_LOCATION_EXTENDED_HAS_UP_VEL 0x800000 +/** GpsLocationExtended has North Velocity Uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_NORTH_VEL_UNC 0x1000000 +/** GpsLocationExtended has East Velocity Uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_EAST_VEL_UNC 0x2000000 +/** GpsLocationExtended has up Velocity Uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_UP_VEL_UNC 0x4000000 +/** GpsLocationExtended has Clock Bias */ +#define GPS_LOCATION_EXTENDED_HAS_CLOCK_BIAS 0x8000000 +/** GpsLocationExtended has Clock Bias std deviation*/ +#define GPS_LOCATION_EXTENDED_HAS_CLOCK_BIAS_STD_DEV 0x10000000 +/** GpsLocationExtended has Clock drift*/ +#define GPS_LOCATION_EXTENDED_HAS_CLOCK_DRIFT 0x20000000 +/** GpsLocationExtended has Clock drift std deviation**/ +#define GPS_LOCATION_EXTENDED_HAS_CLOCK_DRIFT_STD_DEV 0x40000000 +/** GpsLocationExtended has leap seconds **/ +#define GPS_LOCATION_EXTENDED_HAS_LEAP_SECONDS 0x80000000 +/** GpsLocationExtended has time uncertainty **/ +#define GPS_LOCATION_EXTENDED_HAS_TIME_UNC 0x100000000 +/** GpsLocationExtended has heading rate **/ +#define GPS_LOCATION_EXTENDED_HAS_HEADING_RATE 0x200000000 +/** GpsLocationExtended has multiband signals **/ +#define GPS_LOCATION_EXTENDED_HAS_MULTIBAND 0x400000000 +/** GpsLocationExtended has sensor calibration confidence */ +#define GPS_LOCATION_EXTENDED_HAS_CALIBRATION_CONFIDENCE 0x800000000 +/** GpsLocationExtended has sensor calibration status */ +#define GPS_LOCATION_EXTENDED_HAS_CALIBRATION_STATUS 0x1000000000 +/** GpsLocationExtended has the engine type that produced this + * position, the bit mask will only be set when there are two + * or more position engines running in the system */ +#define GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_TYPE 0x2000000000 + /** GpsLocationExtended has the engine mask that indicates the + * set of engines contribute to the fix. */ +#define GPS_LOCATION_EXTENDED_HAS_OUTPUT_ENG_MASK 0x4000000000 +/** GpsLocationExtended has dgnss correction source */ +#define GPS_LOCATION_EXTENDED_HAS_DGNSS_CORRECTION_SOURCE_TYPE 0x8000000000 +/** GpsLocationExtended has dgnss correction source ID */ +#define GPS_LOCATION_EXTENDED_HAS_DGNSS_CORRECTION_SOURCE_ID 0x10000000000 +/** GpsLocationExtended has dgnss constellation usage */ +#define GPS_LOCATION_EXTENDED_HAS_DGNSS_CONSTELLATION_USAGE 0x20000000000 +/** GpsLocationExtended has dgnss ref station Id */ +#define GPS_LOCATION_EXTENDED_HAS_DGNSS_REF_STATION_ID 0x40000000000 +/** GpsLocationExtended has dgnss data age */ +#define GPS_LOCATION_EXTENDED_HAS_DGNSS_DATA_AGE 0x80000000000 + /** GpsLocationExtended has the conformityIndex computed from + * robust location feature. */ +#define GPS_LOCATION_EXTENDED_HAS_CONFORMITY_INDEX 0x100000000000 + /** GpsLocationExtended has the llaVRPased. */ +#define GPS_LOCATION_EXTENDED_HAS_LLA_VRP_BASED 0x200000000000 +/** GpsLocationExtended has the velocityVRPased. */ +#define GPS_LOCATION_EXTENDED_HAS_ENU_VELOCITY_LLA_VRP_BASED 0x400000000000 +/** GpsLocationExtended has upperTriangleFullCovMatrix. */ +#define GPS_LOCATION_EXTENDED_HAS_UPPER_TRIANGLE_FULL_COV_MATRIX 0x800000000000 +/** GpsLocationExtended has drSolutionStatusMask. */ +#define GPS_LOCATION_EXTENDED_HAS_DR_SOLUTION_STATUS_MASK 0x1000000000000 +/** GpsLocationExtended has altitudeAssumed. */ +#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_ASSUMED 0x2000000000000 + +typedef uint32_t LocNavSolutionMask; +/* Bitmask to specify whether SBAS ionospheric correction is used */ +#define LOC_NAV_MASK_SBAS_CORRECTION_IONO ((LocNavSolutionMask)0x0001) +/* Bitmask to specify whether SBAS fast correction is used */ +#define LOC_NAV_MASK_SBAS_CORRECTION_FAST ((LocNavSolutionMask)0x0002) +/**< Bitmask to specify whether SBAS long-tem correction is used */ +#define LOC_NAV_MASK_SBAS_CORRECTION_LONG ((LocNavSolutionMask)0x0004) +/**< Bitmask to specify whether SBAS integrity information is used */ +#define LOC_NAV_MASK_SBAS_INTEGRITY ((LocNavSolutionMask)0x0008) +/**< Bitmask to specify whether Position Report is DGNSS corrected */ +#define LOC_NAV_MASK_DGNSS_CORRECTION ((LocNavSolutionMask)0x0010) +/**< Bitmask to specify whether Position Report is RTK corrected */ +#define LOC_NAV_MASK_RTK_CORRECTION ((LocNavSolutionMask)0x0020) +/**< Bitmask to specify whether Position Report is PPP corrected */ +#define LOC_NAV_MASK_PPP_CORRECTION ((LocNavSolutionMask)0x0040) +/**< Bitmask to specify whether Position Report is RTK fixed corrected */ +#define LOC_NAV_MASK_RTK_FIXED_CORRECTION ((LocNavSolutionMask)0x0080) +/**< Bitmask specifying whether only SBAS corrected SVs are used for the fix */ +#define LOC_NAV_MASK_ONLY_SBAS_CORRECTED_SV_USED ((LocNavSolutionMask)0x0100) + +typedef uint32_t LocPosDataMask; +/* Bitmask to specify whether Navigation data has Forward Acceleration */ +#define LOC_NAV_DATA_HAS_LONG_ACCEL ((LocPosDataMask)0x0001) +/* Bitmask to specify whether Navigation data has Sideward Acceleration */ +#define LOC_NAV_DATA_HAS_LAT_ACCEL ((LocPosDataMask)0x0002) +/* Bitmask to specify whether Navigation data has Vertical Acceleration */ +#define LOC_NAV_DATA_HAS_VERT_ACCEL ((LocPosDataMask)0x0004) +/* Bitmask to specify whether Navigation data has Heading Rate */ +#define LOC_NAV_DATA_HAS_YAW_RATE ((LocPosDataMask)0x0008) +/* Bitmask to specify whether Navigation data has Body pitch */ +#define LOC_NAV_DATA_HAS_PITCH ((LocPosDataMask)0x0010) +/* Bitmask to specify whether Navigation data has Forward Acceleration Unc */ +#define LOC_NAV_DATA_HAS_LONG_ACCEL_UNC ((LocPosDataMask)0x0020) +/* Bitmask to specify whether Navigation data has Sideward Acceleration Unc*/ +#define LOC_NAV_DATA_HAS_LAT_ACCEL_UNC ((LocPosDataMask)0x0040) +/* Bitmask to specify whether Navigation data has Vertical Acceleration Unc*/ +#define LOC_NAV_DATA_HAS_VERT_ACCEL_UNC ((LocPosDataMask)0x0080) +/* Bitmask to specify whether Navigation data has Heading Rate Unc*/ +#define LOC_NAV_DATA_HAS_YAW_RATE_UNC ((LocPosDataMask)0x0100) +/* Bitmask to specify whether Navigation data has Body pitch Unc*/ +#define LOC_NAV_DATA_HAS_PITCH_UNC ((LocPosDataMask)0x0200) + +typedef uint32_t GnssAdditionalSystemInfoMask; +/* Bitmask to specify whether Tauc is valid */ +#define GNSS_ADDITIONAL_SYSTEMINFO_HAS_TAUC ((GnssAdditionalSystemInfoMask)0x0001) +/* Bitmask to specify whether leapSec is valid */ +#define GNSS_ADDITIONAL_SYSTEMINFO_HAS_LEAP_SEC ((GnssAdditionalSystemInfoMask)0x0002) + + +/** GPS PRN Range */ +#define GPS_SV_PRN_MIN 1 +#define GPS_SV_PRN_MAX 32 +#define GLO_SV_PRN_MIN 65 +#define GLO_SV_PRN_MAX 96 +#define SBAS_SV_PRN_MIN 120 +#define SBAS_SV_PRN_MAX 191 +#define QZSS_SV_PRN_MIN 193 +#define QZSS_SV_PRN_MAX 197 +#define BDS_SV_PRN_MIN 201 +#define BDS_SV_PRN_MAX 263 +#define GAL_SV_PRN_MIN 301 +#define GAL_SV_PRN_MAX 336 +#define NAVIC_SV_PRN_MIN 401 +#define NAVIC_SV_PRN_MAX 414 +#define GLO_SV_PRN_SLOT_UNKNOWN 255 + +/* Checking svIdOneBase can be set to the corresponding bit in mask */ +#define svFitsMask(mask, svIdOneBase) \ + ((svIdOneBase) >= 1 && (svIdOneBase) <= (sizeof(mask) << 3)) +/* Setting svIdOneBase specific bit in the mask if the bit offset fits */ +#define setSvMask(mask, svIdOneBase) \ + if (svFitsMask(mask, svIdOneBase)) mask |= (1ULL << ((svIdOneBase) - 1)) + +#define isValInRangeInclusive(val, min, max) ((val) >= (min) && (val) <= (max)) +#define isGloSlotUnknown(val) ((val) == GLO_SV_PRN_SLOT_UNKNOWN) + +typedef enum { + LOC_RELIABILITY_NOT_SET = 0, + LOC_RELIABILITY_VERY_LOW = 1, + LOC_RELIABILITY_LOW = 2, + LOC_RELIABILITY_MEDIUM = 3, + LOC_RELIABILITY_HIGH = 4 +}LocReliability; + +typedef enum { + LOC_IN_EMERGENCY_UNKNOWN = 0, + LOC_IN_EMERGENCY_SET = 1, + LOC_IN_EMERGENCY_NOT_SET = 2 +}LocInEmergency; + +typedef struct { + struct timespec32_t apTimeStamp; + /*boottime received from pps-ktimer*/ + float apTimeStampUncertaintyMs; + /* timestamp uncertainty in milli seconds */ +}Gnss_ApTimeStampStructType; + +typedef struct { + uint64_t gps_sv_used_ids_mask; + uint64_t glo_sv_used_ids_mask; + uint64_t gal_sv_used_ids_mask; + uint64_t bds_sv_used_ids_mask; + uint64_t qzss_sv_used_ids_mask; + uint64_t navic_sv_used_ids_mask; +} GnssSvUsedInPosition; + +typedef struct { + uint64_t gps_l1ca_sv_used_ids_mask; // GPS L1CA + uint64_t gps_l1c_sv_used_ids_mask; // GPS L1C + uint64_t gps_l2_sv_used_ids_mask; // GPS L2 + uint64_t gps_l5_sv_used_ids_mask; // GPS L5 + uint64_t glo_g1_sv_used_ids_mask; // GLO G1 + uint64_t glo_g2_sv_used_ids_mask; // GLO G2 + uint64_t gal_e1_sv_used_ids_mask; // GAL E1 + uint64_t gal_e5a_sv_used_ids_mask; // GAL E5A + uint64_t gal_e5b_sv_used_ids_mask; // GAL E5B + uint64_t bds_b1i_sv_used_ids_mask; // BDS B1I + uint64_t bds_b1c_sv_used_ids_mask; // BDS B1C + uint64_t bds_b2i_sv_used_ids_mask; // BDS B2I + uint64_t bds_b2ai_sv_used_ids_mask; // BDS B2AI + uint64_t qzss_l1ca_sv_used_ids_mask; // QZSS L1CA + uint64_t qzss_l1s_sv_used_ids_mask; // QZSS L1S + uint64_t qzss_l2_sv_used_ids_mask; // QZSS L2 + uint64_t qzss_l5_sv_used_ids_mask; // QZSS L5 + uint64_t sbas_l1_sv_used_ids_mask; // SBAS L1 + uint64_t bds_b2aq_sv_used_ids_mask; // BDS B2AQ +} GnssSvMbUsedInPosition; + +/* Body Frame parameters */ +typedef struct { + /** Contains Body frame LocPosDataMask bits. */ + uint32_t bodyFrameDatamask; + /* Forward Acceleration in body frame (m/s2)*/ + float longAccel; + /** Uncertainty of Forward Acceleration in body frame */ + float longAccelUnc; + /* Sideward Acceleration in body frame (m/s2)*/ + float latAccel; + /** Uncertainty of Side-ward Acceleration in body frame */ + float latAccelUnc; + /* Vertical Acceleration in body frame (m/s2)*/ + float vertAccel; + /** Uncertainty of Vertical Acceleration in body frame */ + float vertAccelUnc; + /* Heading Rate (Radians/second) */ + float yawRate; + /** Uncertainty of Heading Rate */ + float yawRateUnc; + /* Body pitch (Radians) */ + float pitch; + /** Uncertainty of Body pitch */ + float pitchRadUnc; +}LocPositionDynamics; + +typedef struct { + + /** Position dilution of precision. + Range: 1 (highest accuracy) to 50 (lowest accuracy) */ + float PDOP; + + /** Horizontal dilution of precision. + Range: 1 (highest accuracy) to 50 (lowest accuracy) */ + float HDOP; + + /** Vertical dilution of precision. + Range: 1 (highest accuracy) to 50 (lowest accuracy) */ + float VDOP; + + /** geometric dilution of precision. + Range: 1 (highest accuracy) to 50 (lowest accuracy) */ + float GDOP; + + /** time dilution of precision. + Range: 1 (highest accuracy) to 50 (lowest accuracy) */ + float TDOP; +}LocExtDOP; + +/* GPS Time structure */ +typedef struct { + + /**< Current GPS week as calculated from midnight, Jan. 6, 1980. \n + - Units: Weeks */ + uint16_t gpsWeek; + + /**< Amount of time into the current GPS week. \n + - Units: Milliseconds */ + uint32_t gpsTimeOfWeekMs; +}GPSTimeStruct; + +typedef uint8_t CarrierPhaseAmbiguityType; +#define CARRIER_PHASE_AMBIGUITY_RESOLUTION_NONE ((CarrierPhaseAmbiguityType)0) +#define CARRIER_PHASE_AMBIGUITY_RESOLUTION_FLOAT ((CarrierPhaseAmbiguityType)1) +#define CARRIER_PHASE_AMBIGUITY_RESOLUTION_FIXED ((CarrierPhaseAmbiguityType)2) + + +typedef enum { + LOC_DGNSS_CORR_SOURCE_TYPE_INVALID = 0, /**< Invalid DGNSS correction source type \n */ + LOC_DGNSS_CORR_SOURCE_TYPE_RTCM = 1, /**< DGNSS correction source type RTCM \n */ + LOC_DGNSS_CORR_SOURCE_TYPE_3GPP = 2, /**< DGNSS correction source type 3GPP \n */ +}LocDgnssCorrectionSourceType; + +typedef uint16_t GnssMeasUsageStatusBitMask; +/** Used in fix */ +#define GNSS_MEAS_USED_IN_PVT ((GnssMeasUsageStatusBitMask)0x00000001ul) +/** Measurement is Bad */ +#define GNSS_MEAS_USAGE_STATUS_BAD_MEAS ((GnssMeasUsageStatusBitMask)0x00000002ul) +/** Measurement has too low C/N */ +#define GNSS_MEAS_USAGE_STATUS_CNO_TOO_LOW ((GnssMeasUsageStatusBitMask)0x00000004ul) +/** Measurement has too low elevation */ +#define GNSS_MEAS_USAGE_STATUS_ELEVATION_TOO_LOW ((GnssMeasUsageStatusBitMask)0x00000008ul) +/** No ephemeris available for this measurement */ +#define GNSS_MEAS_USAGE_STATUS_NO_EPHEMERIS ((GnssMeasUsageStatusBitMask)0x00000010ul) +/** No corrections available for the measurement */ +#define GNSS_MEAS_USAGE_STATUS_NO_CORRECTIONS ((GnssMeasUsageStatusBitMask)0x00000020ul) +/** Corrections has timed out for the measurement */ +#define GNSS_MEAS_USAGE_STATUS_CORRECTION_TIMEOUT ((GnssMeasUsageStatusBitMask)0x00000040ul) +/** Measurement is unhealthy */ +#define GNSS_MEAS_USAGE_STATUS_UNHEALTHY ((GnssMeasUsageStatusBitMask)0x00000080ul) +/** Configuration is disabled for this measurement */ +#define GNSS_MEAS_USAGE_STATUS_CONFIG_DISABLED ((GnssMeasUsageStatusBitMask)0x00000100ul) +/** Measurement not used for other reasons */ +#define GNSS_MEAS_USAGE_STATUS_OTHER ((GnssMeasUsageStatusBitMask)0x00000200ul) + +/** Flags to indicate valid fields in epMeasUsageInfo */ +typedef uint16_t GnssMeasUsageInfoValidityMask; +#define GNSS_PSEUDO_RANGE_RESIDUAL_VALID ((GnssMeasUsageInfoValidityMask)0x00000001ul) +#define GNSS_DOPPLER_RESIDUAL_VALID ((GnssMeasUsageInfoValidityMask)0x00000002ul) +#define GNSS_CARRIER_PHASE_RESIDUAL_VALID ((GnssMeasUsageInfoValidityMask)0x00000004ul) +#define GNSS_CARRIER_PHASE_AMBIGUITY_TYPE_VALID ((GnssMeasUsageInfoValidityMask)0x00000008ul) + +typedef uint16_t GnssSvPolyStatusMask; +#define GNSS_SV_POLY_SRC_ALM_CORR_V02 ((GnssSvPolyStatusMask)0x01) +#define GNSS_SV_POLY_GLO_STR4_V02 ((GnssSvPolyStatusMask)0x02) +#define GNSS_SV_POLY_DELETE_V02 ((GnssSvPolyStatusMask)0x04) +#define GNSS_SV_POLY_SRC_GAL_FNAV_OR_INAV_V02 ((GnssSvPolyStatusMask)0x08) +typedef uint16_t GnssSvPolyStatusMaskValidity; +#define GNSS_SV_POLY_SRC_ALM_CORR_VALID_V02 ((GnssSvPolyStatusMaskValidity)0x01) +#define GNSS_SV_POLY_GLO_STR4_VALID_V02 ((GnssSvPolyStatusMaskValidity)0x02) +#define GNSS_SV_POLY_DELETE_VALID_V02 ((GnssSvPolyStatusMaskValidity)0x04) +#define GNSS_SV_POLY_SRC_GAL_FNAV_OR_INAV_VALID_V02 ((GnssSvPolyStatusMaskValidity)0x08) + +typedef struct { + /** Specifies GNSS signal type + Mandatory Field*/ + GnssSignalTypeMask gnssSignalType; + /** Specifies GNSS Constellation Type + Mandatory Field*/ + Gnss_LocSvSystemEnumType gnssConstellation; + /** Unique SV Identifier. + * SV Range for supported constellation is specified as below: + * - For GPS: 1 to 32 + * - For GLONASS: 65 to 96 + * - For SBAS: 120 to 158 and 183 to 191 + * - For QZSS: 193 to 197 + * - For BDS: 201 to 263 + * - For GAL: 301 to 336 + * - For NAVIC: 401 to 414 */ + uint16_t gnssSvId; + /** GLONASS frequency number + 7. + Valid only for a GLONASS system and + is to be ignored for all other systems. + Range: 1 to 14 */ + uint8_t gloFrequency; + /** Carrier phase ambiguity type. */ + CarrierPhaseAmbiguityType carrierPhaseAmbiguityType; + /** Validity mask */ + GnssMeasUsageStatusBitMask measUsageStatusMask; + /** Specifies measurement usage status + Mandatory Field*/ + GnssMeasUsageInfoValidityMask validityMask; + /** Computed pseudorange residual. + Unit: Meters */ + float pseudorangeResidual; + /** Computed doppler residual. + Unit: Meters/sec*/ + float dopplerResidual; + /** Computed carrier phase residual. + Unit: Cycles*/ + float carrierPhaseResidual; + /** Carrier phase ambiguity value. + Unit: Cycles*/ + float carrierPhasAmbiguity; +} GpsMeasUsageInfo; + +#define COV_MATRIX_SIZE 12 +/** Represents gps location extended. */ +typedef struct { + /** set to sizeof(GpsLocationExtended) */ + uint32_t size; + /** Contains GpsLocationExtendedFlags bits. */ + uint64_t flags; + /** Contains the Altitude wrt mean sea level */ + float altitudeMeanSeaLevel; + /** Contains Position Dilusion of Precision. */ + float pdop; + /** Contains Horizontal Dilusion of Precision. */ + float hdop; + /** Contains Vertical Dilusion of Precision. */ + float vdop; + /** Contains Magnetic Deviation. */ + float magneticDeviation; + /** vertical uncertainty in meters */ + float vert_unc; + /** speed uncertainty in m/s */ + float speed_unc; + /** heading uncertainty in degrees (0 to 359.999) */ + float bearing_unc; + /** horizontal reliability. */ + LocReliability horizontal_reliability; + /** vertical reliability. */ + LocReliability vertical_reliability; + /* Horizontal Elliptical Uncertainty (Semi-Major Axis) */ + float horUncEllipseSemiMajor; + /* Horizontal Elliptical Uncertainty (Semi-Minor Axis) */ + float horUncEllipseSemiMinor; + /* Elliptical Horizontal Uncertainty Azimuth */ + float horUncEllipseOrientAzimuth; + + Gnss_ApTimeStampStructType timeStamp; + /** Gnss sv used in position data */ + GnssSvUsedInPosition gnss_sv_used_ids; + /** Gnss sv used in position data for multiband */ + GnssSvMbUsedInPosition gnss_mb_sv_used_ids; + /** Nav solution mask to indicate sbas corrections */ + LocNavSolutionMask navSolutionMask; + /** Position technology used in computing this fix */ + LocPosTechMask tech_mask; + /** SV Info source used in computing this fix */ + LocSvInfoSource sv_source; + /** Body Frame Dynamics: 4wayAcceleration and pitch set with validity */ + GnssLocationPositionDynamics bodyFrameData; + /** GPS Time */ + GPSTimeStruct gpsTime; + GnssSystemTime gnssSystemTime; + /** Dilution of precision associated with this position*/ + LocExtDOP extDOP; + /** North standard deviation. + Unit: Meters */ + float northStdDeviation; + /** East standard deviation. + Unit: Meters */ + float eastStdDeviation; + /** North Velocity. + Unit: Meters/sec */ + float northVelocity; + /** East Velocity. + Unit: Meters/sec */ + float eastVelocity; + /** Up Velocity. + Unit: Meters/sec */ + float upVelocity; + /** North Velocity standard deviation. + Unit: Meters/sec */ + float northVelocityStdDeviation; + /** East Velocity standard deviation. + Unit: Meters/sec */ + float eastVelocityStdDeviation; + /** Up Velocity standard deviation + Unit: Meters/sec */ + float upVelocityStdDeviation; + /** Estimated clock bias. Unit: Nano seconds */ + float clockbiasMeter; + /** Estimated clock bias std deviation. Unit: Nano seconds */ + float clockBiasStdDeviationMeter; + /** Estimated clock drift. Unit: Meters/sec */ + float clockDrift; + /** Estimated clock drift std deviation. Unit: Meters/sec */ + float clockDriftStdDeviation; + /** Number of valid reference stations. Range:[0-4] */ + uint8_t numValidRefStations; + /** Reference station(s) number */ + uint16_t referenceStation[4]; + /** Number of measurements received for use in fix. + Shall be used as maximum index in-to svUsageInfo[]. + Set to 0, if svUsageInfo reporting is not supported. + Range: 0-EP_GNSS_MAX_MEAS */ + uint8_t numOfMeasReceived; + /** Measurement Usage Information */ + GpsMeasUsageInfo measUsageInfo[GNSS_SV_MAX]; + /** Leap Seconds */ + uint8_t leapSeconds; + /** Time uncertainty in milliseconds */ + float timeUncMs; + /** Heading Rate is in NED frame. + Range: 0 to 359.999. 946 + Unit: Degrees per Seconds */ + float headingRateDeg; + /** Sensor calibration confidence percent. Range: 0 - 100 */ + uint8_t calibrationConfidence; + DrCalibrationStatusMask calibrationStatus; + /** location engine type. When the fix. when the type is set to + LOC_ENGINE_SRC_FUSED, the fix is the propagated/aggregated + reports from all engines running on the system (e.g.: + DR/SPE/PPE). To check which location engine contributes to + the fused output, check for locOutputEngMask. */ + LocOutputEngineType locOutputEngType; + /** when loc output eng type is set to fused, this field + indicates the set of engines contribute to the fix. */ + PositioningEngineMask locOutputEngMask; + + /** DGNSS Correction Source for position report: RTCM, 3GPP + * etc. */ + LocDgnssCorrectionSourceType dgnssCorrectionSourceType; + + /** If DGNSS is used, the SourceID is a 32bit number identifying + * the DGNSS source ID */ + uint32_t dgnssCorrectionSourceID; + + /** If DGNSS is used, which constellation was DGNSS used for to + * produce the pos report. */ + GnssConstellationTypeMask dgnssConstellationUsage; + + /** If DGNSS is used, DGNSS Reference station ID used for + * position report */ + uint16_t dgnssRefStationId; + + /** If DGNSS is used, DGNSS data age in milli-seconds */ + uint32_t dgnssDataAgeMsec; + + /** When robust location is enabled, this field + * will how well the various input data considered for + * navigation solution conform to expectations. + * Range: 0 (least conforming) to 1 (most conforming) */ + float conformityIndex; + GnssLocationPositionDynamicsExt bodyFrameDataExt; + /** VRR-based latitude/longitude/altitude */ + LLAInfo llaVRPBased; + /** VRR-based east, north, and up velocity */ + float enuVelocityVRPBased[3]; + /** Upper triangle elements of full matrix of position and + velocity estimate in ECEF + + The full covariance matrix of PPE position + (x, y, z in ECEF, in the unit of meters) estimate is a 3x3 matrix + | px,x px,y px,z | + | py,x py,y py,z | + | pz,x pz,y pz,z | + + The full covariance matrix of PPE velocity + (vx,vy, vz in ECEF, in the unit of m/s) estimate is a 3x3 matrix + | pvx,vx pvx,vy pvx,vz | + | pvy,vx pvy,vy pvy,vz | + | pvz,vx pvz,vy pvz,vz | + + upperTriangleFullCovMatrix = + { px,x, px,y, px,z, py,y, py,z, pz,z, pvx,vx, pvx,vy, pvx,vz, pvy,vy, pvy,vz, pvz,vz} + Uint: px,x, px,y, px,z, py,y, py,z, pz,z is in meter + pvx,vx, pvx,vy, pvx,vz, pvy,vy, pvy,vz, pvz,vz is in meters/seconds + */ + float upperTriangleFullCovMatrix[COV_MATRIX_SIZE]; + DrSolutionStatusMask drSolutionStatusMask; + /** When this field is valid, it will indicates whether altitude + * is assumed or calculated. + * false: Altitude is calculated. + * true: Altitude is assumed; there may not be enough + * satellites to determine the precise altitude. */ + bool altitudeAssumed; +} GpsLocationExtended; + +// struct that contains complete position info from engine +typedef struct { + UlpLocation location; + GpsLocationExtended locationExtended; + enum loc_sess_status sessionStatus; +} EngineLocationInfo; + +// Nmea sentence types mask +typedef uint32_t NmeaSentenceTypesMask; +#define LOC_NMEA_MASK_GGA_V02 ((NmeaSentenceTypesMask)0x00000001) /**< Enable GGA type */ +#define LOC_NMEA_MASK_RMC_V02 ((NmeaSentenceTypesMask)0x00000002) /**< Enable RMC type */ +#define LOC_NMEA_MASK_GSV_V02 ((NmeaSentenceTypesMask)0x00000004) /**< Enable GSV type */ +#define LOC_NMEA_MASK_GSA_V02 ((NmeaSentenceTypesMask)0x00000008) /**< Enable GSA type */ +#define LOC_NMEA_MASK_VTG_V02 ((NmeaSentenceTypesMask)0x00000010) /**< Enable VTG type */ +#define LOC_NMEA_MASK_PQXFI_V02 ((NmeaSentenceTypesMask)0x00000020) /**< Enable PQXFI type */ +#define LOC_NMEA_MASK_PSTIS_V02 ((NmeaSentenceTypesMask)0x00000040) /**< Enable PSTIS type */ +#define LOC_NMEA_MASK_GLGSV_V02 ((NmeaSentenceTypesMask)0x00000080) /**< Enable GLGSV type */ +#define LOC_NMEA_MASK_GNGSA_V02 ((NmeaSentenceTypesMask)0x00000100) /**< Enable GNGSA type */ +#define LOC_NMEA_MASK_GNGNS_V02 ((NmeaSentenceTypesMask)0x00000200) /**< Enable GNGNS type */ +#define LOC_NMEA_MASK_GARMC_V02 ((NmeaSentenceTypesMask)0x00000400) /**< Enable GARMC type */ +#define LOC_NMEA_MASK_GAGSV_V02 ((NmeaSentenceTypesMask)0x00000800) /**< Enable GAGSV type */ +#define LOC_NMEA_MASK_GAGSA_V02 ((NmeaSentenceTypesMask)0x00001000) /**< Enable GAGSA type */ +#define LOC_NMEA_MASK_GAVTG_V02 ((NmeaSentenceTypesMask)0x00002000) /**< Enable GAVTG type */ +#define LOC_NMEA_MASK_GAGGA_V02 ((NmeaSentenceTypesMask)0x00004000) /**< Enable GAGGA type */ +#define LOC_NMEA_MASK_PQGSA_V02 ((NmeaSentenceTypesMask)0x00008000) /**< Enable PQGSA type */ +#define LOC_NMEA_MASK_PQGSV_V02 ((NmeaSentenceTypesMask)0x00010000) /**< Enable PQGSV type */ +#define LOC_NMEA_MASK_DEBUG_V02 ((NmeaSentenceTypesMask)0x00020000) /**< Enable DEBUG type */ +#define LOC_NMEA_MASK_GPDTM_V02 ((NmeaSentenceTypesMask)0x00040000) /**< Enable GPDTM type */ +#define LOC_NMEA_MASK_GNGGA_V02 ((NmeaSentenceTypesMask)0x00080000) /**< Enable GNGGA type */ +#define LOC_NMEA_MASK_GNRMC_V02 ((NmeaSentenceTypesMask)0x00100000) /**< Enable GNRMC type */ +#define LOC_NMEA_MASK_GNVTG_V02 ((NmeaSentenceTypesMask)0x00200000) /**< Enable GNVTG type */ +#define LOC_NMEA_MASK_GAGNS_V02 ((NmeaSentenceTypesMask)0x00400000) /**< Enable GAGNS type */ +#define LOC_NMEA_MASK_GBGGA_V02 ((NmeaSentenceTypesMask)0x00800000) /**< Enable GBGGA type */ +#define LOC_NMEA_MASK_GBGSA_V02 ((NmeaSentenceTypesMask)0x01000000) /**< Enable GBGSA type */ +#define LOC_NMEA_MASK_GBGSV_V02 ((NmeaSentenceTypesMask)0x02000000) /**< Enable GBGSV type */ +#define LOC_NMEA_MASK_GBRMC_V02 ((NmeaSentenceTypesMask)0x04000000) /**< Enable GBRMC type */ +#define LOC_NMEA_MASK_GBVTG_V02 ((NmeaSentenceTypesMask)0x08000000) /**< Enable GBVTG type */ +#define LOC_NMEA_MASK_GQGSV_V02 ((NmeaSentenceTypesMask)0x10000000) /**< Enable GQGSV type */ +#define LOC_NMEA_MASK_GIGSV_V02 ((NmeaSentenceTypesMask)0x20000000) /**< Enable GIGSV type */ +#define LOC_NMEA_MASK_GNDTM_V02 ((NmeaSentenceTypesMask)0x40000000) /**< Enable GNDTM type */ +#define LOC_NMEA_MASK_TAGBLOCK_V02 ((NmeaSentenceTypesMask)0x80000000) /**< Enable TAGBLOCK type */ + + +// all bitmasks of general supported NMEA sentenses - debug is not part of this +#define LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK (LOC_NMEA_MASK_GGA_V02 | LOC_NMEA_MASK_RMC_V02 | \ + LOC_NMEA_MASK_GSV_V02 | LOC_NMEA_MASK_GSA_V02 | LOC_NMEA_MASK_VTG_V02 | \ + LOC_NMEA_MASK_PQXFI_V02 | LOC_NMEA_MASK_PSTIS_V02 | LOC_NMEA_MASK_GLGSV_V02 | \ + LOC_NMEA_MASK_GNGSA_V02 | LOC_NMEA_MASK_GNGNS_V02 | LOC_NMEA_MASK_GARMC_V02 | \ + LOC_NMEA_MASK_GAGSV_V02 | LOC_NMEA_MASK_GAGSA_V02 | LOC_NMEA_MASK_GAVTG_V02 | \ + LOC_NMEA_MASK_GAGGA_V02 | LOC_NMEA_MASK_PQGSA_V02 | LOC_NMEA_MASK_PQGSV_V02 | \ + LOC_NMEA_MASK_GPDTM_V02 | LOC_NMEA_MASK_GNGGA_V02 | LOC_NMEA_MASK_GNRMC_V02 | \ + LOC_NMEA_MASK_GNVTG_V02 | LOC_NMEA_MASK_GAGNS_V02 | LOC_NMEA_MASK_GBGGA_V02 | \ + LOC_NMEA_MASK_GBGSA_V02 | LOC_NMEA_MASK_GBGSV_V02 | LOC_NMEA_MASK_GBRMC_V02 | \ + LOC_NMEA_MASK_GBVTG_V02 | LOC_NMEA_MASK_GQGSV_V02 | LOC_NMEA_MASK_GIGSV_V02 | \ + LOC_NMEA_MASK_GNDTM_V02) + +typedef enum { + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + LOC_ENG_IF_REQUEST_SENDER_ID_MODEM, + LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN +} loc_if_req_sender_id_e_type; + + +#define smaller_of(a, b) (((a) > (b)) ? (b) : (a)) +#define MAX_APN_LEN 100 + +// This will be overridden by the individual adapters +// if necessary. +#define DEFAULT_IMPL(rtv) \ +{ \ + LOC_LOGD("%s: default implementation invoked", __func__); \ + return rtv; \ +} + +enum loc_api_adapter_err { + LOC_API_ADAPTER_ERR_SUCCESS = 0, + LOC_API_ADAPTER_ERR_GENERAL_FAILURE = 1, + LOC_API_ADAPTER_ERR_UNSUPPORTED = 2, + LOC_API_ADAPTER_ERR_INVALID_HANDLE = 4, + LOC_API_ADAPTER_ERR_INVALID_PARAMETER = 5, + LOC_API_ADAPTER_ERR_ENGINE_BUSY = 6, + LOC_API_ADAPTER_ERR_PHONE_OFFLINE = 7, + LOC_API_ADAPTER_ERR_TIMEOUT = 8, + LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9, + LOC_API_ADAPTER_ERR_INTERNAL = 10, + + /* equating engine down to phone offline, as they are the same errror */ + LOC_API_ADAPTER_ERR_ENGINE_DOWN = LOC_API_ADAPTER_ERR_PHONE_OFFLINE, + LOC_API_ADAPTER_ERR_FAILURE = 101, + LOC_API_ADAPTER_ERR_UNKNOWN +}; + +enum loc_api_adapter_event_index { + LOC_API_ADAPTER_REPORT_POSITION = 0, // Position report comes in loc_parsed_position_s_type + LOC_API_ADAPTER_REPORT_SATELLITE, // Satellite in view report + LOC_API_ADAPTER_REPORT_NMEA_1HZ, // NMEA report at 1HZ rate + LOC_API_ADAPTER_REPORT_NMEA_POSITION, // NMEA report at position report rate + LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY, // NI notification/verification request + LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA, // Assistance data, eg: time, predicted orbits request + LOC_API_ADAPTER_REQUEST_LOCATION_SERVER, // Request for location server + LOC_API_ADAPTER_REPORT_IOCTL, // Callback report for loc_ioctl + LOC_API_ADAPTER_REPORT_STATUS, // Misc status report: eg, engine state + LOC_API_ADAPTER_REQUEST_WIFI, // + LOC_API_ADAPTER_SENSOR_STATUS, // + LOC_API_ADAPTER_REQUEST_TIME_SYNC, // + LOC_API_ADAPTER_REPORT_SPI, // + LOC_API_ADAPTER_REPORT_NI_GEOFENCE, // + LOC_API_ADAPTER_GEOFENCE_GEN_ALERT, // + LOC_API_ADAPTER_REPORT_GENFENCE_BREACH, // + LOC_API_ADAPTER_PEDOMETER_CTRL, // + LOC_API_ADAPTER_MOTION_CTRL, // + LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA, // Wifi ap data + LOC_API_ADAPTER_BATCH_FULL, // Batching on full + LOC_API_ADAPTER_BATCHED_POSITION_REPORT, // Batching on fix + LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT, // + LOC_API_ADAPTER_GNSS_MEASUREMENT_REPORT, // GNSS Measurement Report + LOC_API_ADAPTER_GNSS_SV_POLYNOMIAL_REPORT, // GNSS SV Polynomial Report + LOC_API_ADAPTER_GDT_UPLOAD_BEGIN_REQ, // GDT upload start request + LOC_API_ADAPTER_GDT_UPLOAD_END_REQ, // GDT upload end request + LOC_API_ADAPTER_GNSS_MEASUREMENT, // GNSS Measurement report + LOC_API_ADAPTER_REQUEST_TIMEZONE, // Timezone injection request + LOC_API_ADAPTER_REPORT_GENFENCE_DWELL_REPORT, // Geofence dwell report + LOC_API_ADAPTER_REQUEST_SRN_DATA, // request srn data from AP + LOC_API_ADAPTER_REQUEST_POSITION_INJECTION, // Position injection request + LOC_API_ADAPTER_BATCH_STATUS, // batch status + LOC_API_ADAPTER_FDCL_SERVICE_REQ, // FDCL service request + LOC_API_ADAPTER_REPORT_UNPROPAGATED_POSITION, // Unpropagated Position report + LOC_API_ADAPTER_BS_OBS_DATA_SERVICE_REQ, // BS observation data request + LOC_API_ADAPTER_GNSS_SV_EPHEMERIS_REPORT, // GNSS SV Ephemeris Report + LOC_API_ADAPTER_LOC_SYSTEM_INFO, // Location system info event + LOC_API_ADAPTER_GNSS_NHZ_MEASUREMENT_REPORT, // GNSS SV nHz measurement report + LOC_API_ADAPTER_EVENT_REPORT_INFO, // Event report info + LOC_API_ADAPTER_LATENCY_INFORMATION_REPORT, // Latency information report + LOC_API_ADAPTER_EVENT_MAX +}; + +#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1ULL< GnssSvTypeConfigCallback; + +/* + * Represents the status of AGNSS augmented to support IPv4. + */ +struct AGnssExtStatusIpV4 { + AGpsExtType type; + LocApnTypeMask apnTypeMask; + LocAGpsStatusValue status; + /* + * 32-bit IPv4 address. + */ + uint32_t ipV4Addr; +}; + +/* + * Represents the status of AGNSS augmented to support IPv6. + */ +struct AGnssExtStatusIpV6 { + AGpsExtType type; + LocApnTypeMask apnTypeMask; + LocAGpsStatusValue status; + /* + * 128-bit IPv6 address. + */ + uint8_t ipV6Addr[16]; +}; + +/* +* Represents the the Nfw Notification structure +*/ +#define GNSS_MAX_NFW_APP_STRING_LEN 64 +#define GNSS_MAX_NFW_STRING_LEN 20 + +typedef enum { + GNSS_NFW_CTRL_PLANE = 0, + GNSS_NFW_SUPL = 1, + GNSS_NFW_IMS = 10, + GNSS_NFW_SIM = 11, + GNSS_NFW_OTHER_PROTOCOL_STACK = 100 +} GnssNfwProtocolStack; + +typedef enum { + GNSS_NFW_CARRIER = 0, + GNSS_NFW_OEM = 10, + GNSS_NFW_MODEM_CHIPSET_VENDOR = 11, + GNSS_NFW_GNSS_CHIPSET_VENDOR = 12, + GNSS_NFW_OTHER_CHIPSET_VENDOR = 13, + GNSS_NFW_AUTOMOBILE_CLIENT = 20, + GNSS_NFW_OTHER_REQUESTOR = 100 +} GnssNfwRequestor; + +typedef enum { + GNSS_NFW_REJECTED = 0, + GNSS_NFW_ACCEPTED_NO_LOCATION_PROVIDED = 1, + GNSS_NFW_ACCEPTED_LOCATION_PROVIDED = 2, +} GnssNfwResponseType; + +typedef struct { + char proxyAppPackageName[GNSS_MAX_NFW_APP_STRING_LEN]; + GnssNfwProtocolStack protocolStack; + char otherProtocolStackName[GNSS_MAX_NFW_STRING_LEN]; + GnssNfwRequestor requestor; + char requestorId[GNSS_MAX_NFW_STRING_LEN]; + GnssNfwResponseType responseType; + bool inEmergencyMode; + bool isCachedLocation; +} GnssNfwNotification; + +typedef uint16_t GnssMeasurementCorrectionsCapabilitiesMask; +typedef enum { + GNSS_MEAS_CORR_LOS_SATS = 1 << 0, + GNSS_MEAS_CORR_EXCESS_PATH_LENGTH = 1 << 1, + GNSS_MEAS_CORR_REFLECTING_PLANE = 1 << 2, +} GnssMeasurementCorrectionsCapabilities; + +/* Represents GNSS NMEA Report Rate Configuration */ +typedef enum { + GNSS_NMEA_REPORT_RATE_UNKNOWN = 0, + GNSS_NMEA_REPORT_RATE_1HZ = 1, + GNSS_NMEA_REPORT_RATE_NHZ = 2 +} GnssNMEARptRate; + +/* ODCPI Request Info */ +enum OdcpiRequestType { + ODCPI_REQUEST_TYPE_START, + ODCPI_REQUEST_TYPE_STOP +}; +struct OdcpiRequestInfo { + uint32_t size; + OdcpiRequestType type; + uint32_t tbfMillis; + bool isEmergencyMode; +}; +/* Callback to send ODCPI request to framework */ +typedef std::function OdcpiRequestCallback; + +/* ODCPI callback priorities*/ +enum OdcpiPrioritytype { + ODCPI_HANDLER_PRIORITY_LOW, + ODCPI_HANDLER_PRIORITY_HIGH +}; + +/* + * Callback with AGNSS(IpV4) status information. + * + * @param status Will be of type AGnssExtStatusIpV4. + */ +typedef void (*AgnssStatusIpV4Cb)(AGnssExtStatusIpV4 status); + +/* +* Callback with AGNSS(IpV6) status information. +* +* @param status Will be of type AGnssExtStatusIpV6. +*/ +typedef void (*AgnssStatusIpV6Cb)(AGnssExtStatusIpV6 status); + +/* +* Callback with NFW information. +*/ +typedef void(*NfwStatusCb)(GnssNfwNotification notification); +typedef bool(*IsInEmergencySession)(void); + +enum AntennaInfoStatus { + ANTENNA_INFO_SUCCESS = 0, + ANTENNA_INFO_ERROR_ALREADY_INIT = 1, + ANTENNA_INFO_ERROR_GENERIC = 2 +}; + +/* +* Callback with Measurement corrections information. +*/ +typedef void(*measCorrSetCapabilitiesCb)(GnssMeasurementCorrectionsCapabilitiesMask capabilities); + +/* + * Callback with AGNSS(IpV6) status information. + * + * @param status Will be of type AGnssExtStatusIpV6. + */ +typedef void (*AgnssStatusIpV6Cb)(AGnssExtStatusIpV6 status); + +/* +* Callback with Antenna information. +*/ +typedef void(*antennaInfoCb)(std::vector gnssAntennaInformations); + +/* Constructs for interaction with loc_net_iface library */ +typedef void (*LocAgpsOpenResultCb)(bool isSuccess, AGpsExtType agpsType, const char* apn, + AGpsBearerType bearerType, void* userDataPtr); + +typedef void (*LocAgpsCloseResultCb)(bool isSuccess, AGpsExtType agpsType, void* userDataPtr); + +enum PowerStateType { + POWER_STATE_UNKNOWN = 0, + POWER_STATE_SUSPEND = 1, + POWER_STATE_RESUME = 2, + POWER_STATE_SHUTDOWN = 3 +}; + +/* Shared resources of LocIpc */ +#define LOC_IPC_HAL "/dev/socket/location/socket_hal" +#define LOC_IPC_XTRA "/dev/socket/location/xtra/socket_xtra" + +#define SOCKET_DIR_LOCATION "/dev/socket/location/" +#define SOCKET_DIR_EHUB "/dev/socket/location/ehub/" +#define SOCKET_TO_LOCATION_HAL_DAEMON "/dev/socket/loc_client/hal_daemon" + +#define SOCKET_LOC_CLIENT_DIR "/dev/socket/loc_client/" +#define EAP_LOC_CLIENT_DIR "/data/vendor/location/extap_locclient/" + +#define LOC_CLIENT_NAME_PREFIX "toclient" +// Please note that the socket name for all location hal daemon client need +// to start with LOC_CLIENT_NAME_PREFIX so that upon hal daemon restarts, +// every client can get the notification that hal daemon has restarted. +#define LOC_INTAPI_NAME_PREFIX LOC_CLIENT_NAME_PREFIX "_intapi" + +typedef uint64_t NetworkHandle; +#define NETWORK_HANDLE_UNKNOWN ~0 +#define MAX_NETWORK_HANDLES 10 + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GPS_EXTENDED_C_H */ diff --git a/gps/utils/linked_list.c b/gps/utils/linked_list.c new file mode 100644 index 0000000..02e1463 --- /dev/null +++ b/gps/utils/linked_list.c @@ -0,0 +1,325 @@ +/* Copyright (c) 2011, 2014, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "LocSvc_utils_ll" + +#include "linked_list.h" +#include +#include +#include +#include +#include +#include + +typedef struct list_element { + struct list_element* next; + struct list_element* prev; + void* data_ptr; + void (*dealloc_func)(void*); +}list_element; + +typedef struct list_state { + list_element* p_head; + list_element* p_tail; +} list_state; + +/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */ + +/*=========================================================================== + + FUNCTION: linked_list_init + + ===========================================================================*/ +linked_list_err_type linked_list_init(void** list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* tmp_list; + tmp_list = (list_state*)calloc(1, sizeof(list_state)); + if( tmp_list == NULL ) + { + LOC_LOGE("%s: Unable to allocate space for list!\n", __FUNCTION__); + return eLINKED_LIST_FAILURE_GENERAL; + } + + tmp_list->p_head = NULL; + tmp_list->p_tail = NULL; + + *list_data = tmp_list; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_destroy + + ===========================================================================*/ +linked_list_err_type linked_list_destroy(void** list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)*list_data; + + linked_list_flush(p_list); + + free(*list_data); + *list_data = NULL; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_add + + ===========================================================================*/ +linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*)) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + if( data_obj == NULL ) + { + LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* p_list = (list_state*)list_data; + list_element* elem = (list_element*)malloc(sizeof(list_element)); + if( elem == NULL ) + { + LOC_LOGE("%s: Memory allocation failed\n", __FUNCTION__); + return eLINKED_LIST_FAILURE_GENERAL; + } + + /* Copy data to newly created element */ + elem->data_ptr = data_obj; + elem->next = NULL; + elem->prev = NULL; + elem->dealloc_func = dealloc; + + /* Replace head element */ + list_element* tmp = p_list->p_head; + p_list->p_head = elem; + /* Point next to the previous head element */ + p_list->p_head->next = tmp; + + if( tmp != NULL ) + { + tmp->prev = p_list->p_head; + } + else + { + p_list->p_tail = p_list->p_head; + } + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_remove + + ===========================================================================*/ +linked_list_err_type linked_list_remove(void* list_data, void **data_obj) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + if( data_obj == NULL ) + { + LOC_LOGE("%s: Invalid input parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_PARAMETER; + } + + list_state* p_list = (list_state*)list_data; + if( p_list->p_tail == NULL ) + { + return eLINKED_LIST_UNAVAILABLE_RESOURCE; + } + + list_element* tmp = p_list->p_tail; + + /* Replace tail element */ + p_list->p_tail = tmp->prev; + + if( p_list->p_tail != NULL ) + { + p_list->p_tail->next = NULL; + } + else + { + p_list->p_head = p_list->p_tail; + } + + /* Copy data to output param */ + *data_obj = tmp->data_ptr; + + /* Free allocated list element */ + free(tmp); + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_empty + + ===========================================================================*/ +int linked_list_empty(void* list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return (int)eLINKED_LIST_INVALID_HANDLE; + } + else + { + list_state* p_list = (list_state*)list_data; + return p_list->p_head == NULL ? 1 : 0; + } +} + +/*=========================================================================== + + FUNCTION: linked_list_flush + + ===========================================================================*/ +linked_list_err_type linked_list_flush(void* list_data) +{ + if( list_data == NULL ) + { + LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)list_data; + + /* Remove all dynamically allocated elements */ + while( p_list->p_head != NULL ) + { + list_element* tmp = p_list->p_head->next; + + /* Free data pointer if told to do so. */ + if( p_list->p_head->dealloc_func != NULL ) + { + p_list->p_head->dealloc_func(p_list->p_head->data_ptr); + } + + /* Free list element */ + free(p_list->p_head); + + p_list->p_head = tmp; + } + + p_list->p_tail = NULL; + + return eLINKED_LIST_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: linked_list_search + + ===========================================================================*/ +linked_list_err_type linked_list_search(void* list_data, void **data_p, + bool (*equal)(void* data_0, void* data), + void* data_0, bool rm_if_found) +{ + if( list_data == NULL || NULL == equal ) + { + LOC_LOGE("%s: Invalid list parameter! list_data %p equal %p\n", + __FUNCTION__, list_data, equal); + return eLINKED_LIST_INVALID_HANDLE; + } + + list_state* p_list = (list_state*)list_data; + if( p_list->p_tail == NULL ) + { + return eLINKED_LIST_UNAVAILABLE_RESOURCE; + } + + list_element* tmp = p_list->p_head; + + if (NULL != data_p) { + *data_p = NULL; + } + + while (NULL != tmp) { + if ((*equal)(data_0, tmp->data_ptr)) { + if (NULL != data_p) { + *data_p = tmp->data_ptr; + } + + if (rm_if_found) { + if (NULL == tmp->prev) { + p_list->p_head = tmp->next; + } else { + tmp->prev->next = tmp->next; + } + + if (NULL == tmp->next) { + p_list->p_tail = tmp->prev; + } else { + tmp->next->prev = tmp->prev; + } + + tmp->prev = tmp->next = NULL; + + // dealloc data if it is not copied out && caller + // has given us a dealloc function pointer. + if (NULL == data_p && NULL != tmp->dealloc_func) { + tmp->dealloc_func(tmp->data_ptr); + } + free(tmp); + } + + tmp = NULL; + } else { + tmp = tmp->next; + } + } + + return eLINKED_LIST_SUCCESS; +} + diff --git a/gps/utils/linked_list.h b/gps/utils/linked_list.h new file mode 100644 index 0000000..0b33ecb --- /dev/null +++ b/gps/utils/linked_list.h @@ -0,0 +1,219 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __LINKED_LIST_H__ +#define __LINKED_LIST_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include + +/** Linked List Return Codes */ +typedef enum +{ + eLINKED_LIST_SUCCESS = 0, + /**< Request was successful. */ + eLINKED_LIST_FAILURE_GENERAL = -1, + /**< Failed because of a general failure. */ + eLINKED_LIST_INVALID_PARAMETER = -2, + /**< Failed because the request contained invalid parameters. */ + eLINKED_LIST_INVALID_HANDLE = -3, + /**< Failed because an invalid handle was specified. */ + eLINKED_LIST_UNAVAILABLE_RESOURCE = -4, + /**< Failed because an there were not enough resources. */ + eLINKED_LIST_INSUFFICIENT_BUFFER = -5, + /**< Failed because an the supplied buffer was too small. */ + eLINKED_LIST_EMPTY = -6 + /**< Failed because list is empty. */ +}linked_list_err_type; + +/*=========================================================================== +FUNCTION linked_list_init + +DESCRIPTION + Initializes internal structures for linked list. + + list_data: State of list to be initialized. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_init(void** list_data); + +/*=========================================================================== +FUNCTION linked_list_destroy + +DESCRIPTION + Destroys internal structures for linked list. + + p_list_data: State of list to be destroyed. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_destroy(void** list_data); + +/*=========================================================================== +FUNCTION linked_list_add + +DESCRIPTION + Adds an element to the head of the linked list. The passed in data pointer + is not modified or freed. Passed in data_obj is expected to live throughout + the use of the linked_list (i.e. data is not allocated internally) + + p_list_data: List to add data to the head of. + data_obj: Pointer to data to add into list + dealloc: Function used to deallocate memory for this element. Pass NULL + if you do not want data deallocated during a flush operation + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*)); + +/*=========================================================================== +FUNCTION linked_list_remove + +DESCRIPTION + Retrieves data from the list tail. data_obj is the tail element from the list + passed in by linked_list_add. + + p_list_data: List to remove the tail from. + data_obj: Pointer to data removed from list + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_remove(void* list_data, void **data_obj); + +/*=========================================================================== +FUNCTION linked_list_empty + +DESCRIPTION + Tells whether the list currently contains any elements + + p_list_data: List to check if empty. + +DEPENDENCIES + N/A + +RETURN VALUE + 0/FALSE : List contains elements + 1/TRUE : List is Empty + Otherwise look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +int linked_list_empty(void* list_data); + +/*=========================================================================== +FUNCTION linked_list_flush + +DESCRIPTION + Removes all elements from the list and deallocates them using the provided + dealloc function while adding elements. + + p_list_data: List to remove all elements from. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_flush(void* list_data); + +/*=========================================================================== +FUNCTION linked_list_search + +DESCRIPTION + Searches for an element in the linked list. + + p_list_data: List handle. + data_p: to be stored with the data found; NUll if no match. + if data_p passed in as NULL, then no write to it. + equal: Function ptr takes in a list element, and returns + indication if this the one looking for. + data_0: The data being compared against. + rm_if_found: Should data be removed if found? + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +linked_list_err_type linked_list_search(void* list_data, void **data_p, + bool (*equal)(void* data_0, void* data), + void* data_0, bool rm_if_found); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LINKED_LIST_H__ */ diff --git a/gps/utils/loc_cfg.cpp b/gps/utils/loc_cfg.cpp new file mode 100644 index 0000000..2a89966 --- /dev/null +++ b/gps/utils/loc_cfg.cpp @@ -0,0 +1,1140 @@ +/* Copyright (c) 2011-2015, 2018-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_utils_cfg" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_GLIB +#include +#endif +#include "log_util.h" + +/*============================================================================= + * + * GLOBAL DATA DECLARATION + * + *============================================================================*/ + +/* Parameter data */ +static uint32_t DEBUG_LEVEL = 0xff; +static uint32_t TIMESTAMP = 0; +static uint32_t DATUM_TYPE = 0; +static bool sVendorEnhanced = true; +static uint32_t sLogBufferEnabled = 0; + +/* Parameter spec table */ +static const loc_param_s_type loc_param_table[] = +{ + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, + {"DATUM_TYPE", &DATUM_TYPE, NULL, 'n'}, + {"LOG_BUFFER_ENABLED", &sLogBufferEnabled, NULL, 'n'}, +}; +static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); + +typedef struct loc_param_v_type +{ + char* param_name; + char* param_str_value; + int param_int_value; + double param_double_value; +}loc_param_v_type; + +// Reference below arrays wherever needed to avoid duplicating +// same conf path string over and again in location code. +const char LOC_PATH_GPS_CONF[] = LOC_PATH_GPS_CONF_STR; +const char LOC_PATH_IZAT_CONF[] = LOC_PATH_IZAT_CONF_STR; +const char LOC_PATH_FLP_CONF[] = LOC_PATH_FLP_CONF_STR; +const char LOC_PATH_LOWI_CONF[] = LOC_PATH_LOWI_CONF_STR; +const char LOC_PATH_SAP_CONF[] = LOC_PATH_SAP_CONF_STR; +const char LOC_PATH_APDR_CONF[] = LOC_PATH_APDR_CONF_STR; +const char LOC_PATH_XTWIFI_CONF[] = LOC_PATH_XTWIFI_CONF_STR; +const char LOC_PATH_QUIPC_CONF[] = LOC_PATH_QUIPC_CONF_STR; +const char LOC_PATH_ANT_CORR[] = LOC_PATH_ANT_CORR_STR; +const char LOC_PATH_SLIM_CONF[] = LOC_PATH_SLIM_CONF_STR; +const char LOC_PATH_VPE_CONF[] = LOC_PATH_VPE_CONF_STR; + +bool isVendorEnhanced() { + return sVendorEnhanced; +} +void setVendorEnhanced(bool vendorEnhanced) { + sVendorEnhanced = vendorEnhanced; +} + +/*=========================================================================== +FUNCTION loc_get_datum_type + +DESCRIPTION + get datum type + +PARAMETERS: + N/A + +DEPENDENCIES + N/A + +RETURN VALUE + DATUM TYPE + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_get_datum_type() +{ + return DATUM_TYPE; +} + +/*=========================================================================== +FUNCTION loc_set_config_entry + +DESCRIPTION + Potentially sets a given configuration table entry based on the passed in + configuration value. This is done by using a string comparison of the + parameter names and those found in the configuration file. + +PARAMETERS: + config_entry: configuration entry in the table to possibly set + config_value: value to store in the entry if the parameter names match + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_set_config_entry(const loc_param_s_type* config_entry, + loc_param_v_type* config_value, + uint16_t string_len = LOC_MAX_PARAM_STRING) +{ + int ret=-1; + if(NULL == config_entry || NULL == config_value) + { + LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); + return ret; + } + + if (strcmp(config_entry->param_name, config_value->param_name) == 0 && + config_entry->param_ptr) + { + switch (config_entry->param_type) + { + case 's': + if (strcmp(config_value->param_str_value, "NULL") == 0) + { + *((char*)config_entry->param_ptr) = '\0'; + } + else { + strlcpy((char*) config_entry->param_ptr, + config_value->param_str_value, + string_len); + } + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, + config_entry->param_name, (char*)config_entry->param_ptr); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'n': + *((int *)config_entry->param_ptr) = config_value->param_int_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, + config_entry->param_name, config_value->param_int_value); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'f': + *((double *)config_entry->param_ptr) = config_value->param_double_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, + config_entry->param_name, config_value->param_double_value); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + default: + LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", + __FUNCTION__, config_entry->param_name); + } + } + return ret; +} + +/*=========================================================================== +FUNCTION loc_fill_conf_item + +DESCRIPTION + Takes a line of configuration item and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + input_buf : buffer contanis config item + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + 0: Number of records in the config_table filled with input_buf + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_fill_conf_item(char* input_buf, + const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len = LOC_MAX_PARAM_STRING) +{ + int ret = 0; + + if (input_buf && config_table) { + char *lasts; + loc_param_v_type config_value; + memset(&config_value, 0, sizeof(config_value)); + + /* Separate variable and value */ + config_value.param_name = strtok_r(input_buf, "=", &lasts); + /* skip lines that do not contain "=" */ + if (config_value.param_name) { + config_value.param_str_value = strtok_r(NULL, "\0", &lasts); + + /* skip lines that do not contain two operands */ + if (config_value.param_str_value) { + /* Trim leading and trailing spaces */ + loc_util_trim_space(config_value.param_name); + loc_util_trim_space(config_value.param_str_value); + + /* Parse numerical value */ + if ((strlen(config_value.param_str_value) >=3) && + (config_value.param_str_value[0] == '0') && + (tolower(config_value.param_str_value[1]) == 'x')) + { + /* hex */ + config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], + (char**) NULL, 16); + } + else { + config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */ + config_value.param_int_value = atoi(config_value.param_str_value); /* dec */ + } + + for(uint32_t i = 0; NULL != config_table && i < table_length; i++) + { + if(!loc_set_config_entry(&config_table[i], &config_value, string_len)) { + ret += 1; + } + } + } + } + } + + return ret; +} + +/*=========================================================================== +FUNCTION loc_read_conf_r_long (repetitive) + +DESCRIPTION + Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + The difference between this and loc_read_conf is that this function returns + the file pointer position at the end of filling a config table. Also, it + reads a fixed number of parameters at a time which is equal to the length + of the configuration table. This functionality enables the caller to + repeatedly call the function to read data from the same file. + +PARAMETERS: + conf_fp : file pointer + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + 0: Table filled successfully + 1: No more parameters to read + -1: Error filling table + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_read_conf_r_long(FILE *conf_fp, const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len) +{ + int ret=0; + char input_buf[string_len]; /* declare a char array */ + unsigned int num_params=table_length; + + if(conf_fp == NULL) { + LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__); + ret = -1; + goto err; + } + + /* Clear all validity bits */ + for(uint32_t i = 0; NULL != config_table && i < table_length; i++) + { + if(NULL != config_table[i].param_set) + { + *(config_table[i].param_set) = 0; + } + } + + LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params); + while(num_params) + { + if(!fgets(input_buf, string_len, conf_fp)) { + LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__); + break; + } + + num_params -= loc_fill_conf_item(input_buf, config_table, table_length, string_len); + } + +err: + return ret; +} + +/*=========================================================================== +FUNCTION loc_udpate_conf_long + +DESCRIPTION + Parses the passed in buffer for configuration items, and update the table + that is also passed in. + +Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + conf_data: configuration items in bufferas a string + length: strlen(conf_data) + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + number of the records in the table that is updated at time of return. + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_update_conf_long(const char* conf_data, int32_t length, + const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len) +{ + int ret = -1; + + if (conf_data && length && config_table && table_length) { + // make a copy, so we do not tokenize the original data + char* conf_copy = (char*)malloc(length+1); + + if (conf_copy != NULL) + { + memcpy(conf_copy, conf_data, length); + // we hard NULL the end of string to be safe + conf_copy[length] = 0; + + // start with one record off + uint32_t num_params = table_length - 1; + char* saveptr = NULL; + char* input_buf = strtok_r(conf_copy, "\n", &saveptr); + ret = 0; + + LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params); + while(num_params && input_buf) { + ret++; + num_params -= + loc_fill_conf_item(input_buf, config_table, table_length, string_len); + input_buf = strtok_r(NULL, "\n", &saveptr); + } + free(conf_copy); + } + } + + return ret; +} + +/*=========================================================================== +FUNCTION loc_read_conf_long + +DESCRIPTION + Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + +PARAMETERS: + conf_file_name: configuration file to read + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_read_conf_long(const char* conf_file_name, const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len) +{ + FILE *conf_fp = NULL; + + log_buffer_init(false); + if((conf_fp = fopen(conf_file_name, "r")) != NULL) + { + LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); + if(table_length && config_table) { + loc_read_conf_r_long(conf_fp, config_table, table_length, string_len); + rewind(conf_fp); + } + loc_read_conf_r_long(conf_fp, loc_param_table, loc_param_num, string_len); + fclose(conf_fp); + } + /* Initialize logging mechanism with parsed data */ + loc_logger_init(DEBUG_LEVEL, TIMESTAMP); + log_buffer_init(sLogBufferEnabled); + log_tag_level_map_init(); +} + +/*============================================================================= + * + * Define and Structures for Parsing Location Process Configuration File + * + *============================================================================*/ +#define MAX_NUM_STRINGS 20 + +//We can have 8 masks for now +#define CONFIG_MASK_TARGET_ALL 0X01 +#define CONFIG_MASK_TARGET_FOUND 0X02 +#define CONFIG_MASK_TARGET_CHECK 0X03 +#define CONFIG_MASK_BASEBAND_ALL 0X04 +#define CONFIG_MASK_BASEBAND_FOUND 0X08 +#define CONFIG_MASK_BASEBAND_CHECK 0x0c +#define CONFIG_MASK_AUTOPLATFORM_ALL 0x10 +#define CONFIG_MASK_AUTOPLATFORM_FOUND 0x20 +#define CONFIG_MASK_AUTOPLATFORM_CHECK 0x30 +#define CONFIG_MASK_SOCID_ALL 0x40 +#define CONFIG_MASK_SOCID_FOUND 0x80 +#define CONFIG_MASK_SOCID_CHECK 0xc0 + +#define LOC_FEATURE_MASK_GTP_WIFI_BASIC 0x01 +#define LOC_FEATURE_MASK_GTP_WIFI_PREMIUM 0X02 +#define LOC_FEATURE_MASK_GTP_CELL_BASIC 0X04 +#define LOC_FEATURE_MASK_GTP_CELL_PREMIUM 0X08 +#define LOC_FEATURE_MASK_SAP_BASIC 0x40 +#define LOC_FEATURE_MASK_SAP_PREMIUM 0X80 +#define LOC_FEATURE_MASK_GTP_WAA_BASIC 0X100 +#define LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC 0X400 +#define LOC_FEATURE_MASK_ODCPI 0x1000 +#define LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT 0x2000 +#define LOC_FEATURE_MASK_SUPL_WIFI 0x4000 +#define LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO 0x8000 + +typedef struct { + char proc_name[LOC_MAX_PARAM_STRING]; + char proc_argument[LOC_MAX_PARAM_STRING]; + char proc_status[LOC_MAX_PARAM_STRING]; + char group_list[LOC_MAX_PARAM_STRING]; + unsigned int premium_feature; + unsigned int loc_feature_mask; + char platform_list[LOC_MAX_PARAM_STRING]; + char baseband[LOC_MAX_PARAM_STRING]; + char low_ram_targets[LOC_MAX_PARAM_STRING]; + char soc_id_list[LOC_MAX_PARAM_STRING]; + unsigned int sglte_target; + char feature_gtp_mode[LOC_MAX_PARAM_STRING]; + char feature_gtp_waa[LOC_MAX_PARAM_STRING]; + char feature_sap[LOC_MAX_PARAM_STRING]; + char feature_odcpi[LOC_MAX_PARAM_STRING]; + char feature_free_wifi_scan_inject[LOC_MAX_PARAM_STRING]; + char feature_supl_wifi[LOC_MAX_PARAM_STRING]; + char feature_wifi_supplicant_info[LOC_MAX_PARAM_STRING]; + char auto_platform[LOC_MAX_PARAM_STRING]; + unsigned int vendor_enhanced_process; +} loc_launcher_conf; + +/* process configuration parameters */ +static loc_launcher_conf conf; + +/* gps.conf Parameter spec table */ +static const loc_param_s_type gps_conf_parameter_table[] = { + {"SGLTE_TARGET", &conf.sglte_target, NULL, 'n'}, +}; + +/* location feature conf, e.g.: izat.conf feature mode table*/ +static const loc_param_s_type loc_feature_conf_table[] = { + {"GTP_MODE", &conf.feature_gtp_mode, NULL, 's'}, + {"GTP_WAA", &conf.feature_gtp_waa, NULL, 's'}, + {"SAP", &conf.feature_sap, NULL, 's'}, + {"ODCPI", &conf.feature_odcpi, NULL, 's'}, + {"FREE_WIFI_SCAN_INJECT", &conf.feature_free_wifi_scan_inject, NULL, 's'}, + {"SUPL_WIFI", &conf.feature_supl_wifi, NULL, 's'}, + {"WIFI_SUPPLICANT_INFO", &conf.feature_wifi_supplicant_info, NULL, 's'}, +}; + +/* location process conf, e.g.: izat.conf Parameter spec table */ +static const loc_param_s_type loc_process_conf_parameter_table[] = { + {"PROCESS_NAME", &conf.proc_name, NULL, 's'}, + {"PROCESS_ARGUMENT", &conf.proc_argument, NULL, 's'}, + {"PROCESS_STATE", &conf.proc_status, NULL, 's'}, + {"PROCESS_GROUPS", &conf.group_list, NULL, 's'}, + {"PREMIUM_FEATURE", &conf.premium_feature, NULL, 'n'}, + {"IZAT_FEATURE_MASK", &conf.loc_feature_mask, NULL, 'n'}, + {"PLATFORMS", &conf.platform_list, NULL, 's'}, + {"SOC_IDS", &conf.soc_id_list, NULL, 's'}, + {"BASEBAND", &conf.baseband, NULL, 's'}, + {"LOW_RAM_TARGETS", &conf.low_ram_targets, NULL, 's'}, + {"HARDWARE_TYPE", &conf.auto_platform, NULL, 's'}, + {"VENDOR_ENHANCED_PROCESS", &conf.vendor_enhanced_process, NULL, 'n'}, +}; + +/*=========================================================================== +FUNCTION loc_read_process_conf + +DESCRIPTION + Parse the specified conf file and return info for the processes defined. + The format of the file should conform with izat.conf. + +PARAMETERS: + conf_file_name: configuration file to read + process_count_ptr: pointer to store number of processes defined in the conf file. + process_info_table_ptr: pointer to store the process info table. + +DEPENDENCIES + The file must be in izat.conf format. + +RETURN VALUE + 0: success + none-zero: failure + +SIDE EFFECTS + N/A + +NOTES: + On success, memory pointed by (*process_info_table_ptr) must be freed. +===========================================================================*/ +int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr, + loc_process_info_s_type** process_info_table_ptr) { + loc_process_info_s_type *child_proc = nullptr; + volatile int i=0; + unsigned int j=0; + gid_t gid_list[LOC_PROCESS_MAX_NUM_GROUPS]; + char *split_strings[MAX_NUM_STRINGS]; + int name_length=0, group_list_length=0, platform_length=0, baseband_length=0, ngroups=0, ret=0; + int auto_platform_length = 0, soc_id_list_length=0; + int group_index=0, nstrings=0, status_length=0; + FILE* conf_fp = nullptr; + char platform_name[PROPERTY_VALUE_MAX], baseband_name[PROPERTY_VALUE_MAX]; + int low_ram_target=0; + char autoplatform_name[PROPERTY_VALUE_MAX], socid_value[PROPERTY_VALUE_MAX]; + unsigned int loc_service_mask=0; + unsigned char config_mask = 0; + unsigned char proc_list_length=0; + int gtp_cell_ap_enabled = 0; + char arg_gtp_waa[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--"; + char arg_gtp_modem_cell[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--"; + char arg_gtp_wifi[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--"; + char arg_sap[LOC_PROCESS_MAX_ARG_STR_LENGTH] = "--"; + char arg_disabled[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_DISABLED; + char arg_basic[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_BASIC; + char arg_premium[LOC_PROCESS_MAX_ARG_STR_LENGTH] = LOC_FEATURE_MODE_PREMIUM; + + if (process_count_ptr == NULL || process_info_table_ptr == NULL) { + return -1; + } + + //Read gps.conf and fill parameter table + UTIL_READ_CONF(LOC_PATH_GPS_CONF, gps_conf_parameter_table); + + //Form argument strings + strlcat(arg_gtp_waa, LOC_FEATURE_GTP_WAA, LOC_PROCESS_MAX_ARG_STR_LENGTH-3); + strlcat(arg_gtp_modem_cell, LOC_FEATURE_GTP_MODEM_CELL, LOC_PROCESS_MAX_ARG_STR_LENGTH-3); + strlcat(arg_gtp_wifi, LOC_FEATURE_GTP_WIFI, LOC_PROCESS_MAX_ARG_STR_LENGTH-3); + strlcat(arg_sap, LOC_FEATURE_SAP, LOC_PROCESS_MAX_ARG_STR_LENGTH-3); + + //Get platform name from ro.board.platform property + loc_get_platform_name(platform_name, sizeof(platform_name)); + //Get baseband name from ro.baseband property + loc_get_target_baseband(baseband_name, sizeof(baseband_name)); + //Identify if this is an automotive platform + loc_get_auto_platform_name(autoplatform_name,sizeof(autoplatform_name)); + //Identify if this is a low ram target from ro.config.low_ram property + low_ram_target = loc_identify_low_ram_target(); + // Get the soc-id for this device. + loc_get_device_soc_id(socid_value, sizeof(socid_value)); + + UTIL_READ_CONF(conf_file_name, loc_feature_conf_table); + + //Set service mask for GTP_MODE + if (strcmp(conf.feature_gtp_mode, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: GTP MODE DISABLED", __func__, __LINE__); + } + else if (strcmp(conf.feature_gtp_mode, "LEGACY_WWAN") == 0) { + LOC_LOGD("%s:%d]: Setting GTP MODE to mode: LEGACY_WWAN", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_GTP_MODEM_CELL_BASIC; + } + else if (strcmp(conf.feature_gtp_mode, "SDK") == 0) { + LOC_LOGD("%s:%d]: Setting GTP MODE to mode: SDK", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC; + } + else if (strcmp(conf.feature_gtp_mode, "SDK_WIFI") == 0) { + LOC_LOGD("%s:%d]: Setting GTP MODE to mode: SDK", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_GTP_WIFI_BASIC; + } + //conf file has a garbage value + else { + LOC_LOGE("%s:%d]: Unrecognized value for GTP MODE Mode."\ + " Setting GTP WIFI to default mode: DISABLED", __func__, __LINE__); + } + //Set service mask for GTP_WAA + if (strcmp(conf.feature_gtp_waa, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting GTP WAA to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_GTP_WAA_BASIC; + } + else if (strcmp(conf.feature_gtp_waa, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: GTP WAA DISABLED", __func__, __LINE__); + } + //conf file has a garbage value + else { + LOC_LOGE("%s:%d]: Unrecognized value for GTP WAA Mode."\ + " Setting GTP WAA to default mode: DISABLED", __func__, __LINE__); + } + + //Set service mask for SAP + if(strcmp(conf.feature_sap, "PREMIUM") == 0 || + strcmp(conf.feature_sap, "PREMIUM_ENV_AIDING") == 0) { + LOC_LOGD("%s:%d]: Setting SAP to mode: PREMIUM", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SAP_PREMIUM; + } + else if (strcmp(conf.feature_sap, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting SAP to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC; + } + else if (strcmp(conf.feature_sap, "MODEM_DEFAULT") == 0) { + LOC_LOGD("%s:%d]: Setting SAP to mode: MODEM_DEFAULT", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC; + } + else if (strcmp(conf.feature_sap, "DISABLED") == 0) { +#ifdef USE_GLIB + /* Enable slim_daemon even when SAP is set to DISABLED*/ + loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC; +#else + LOC_LOGD("%s:%d]: Setting SAP to mode: DISABLED", __func__, __LINE__); +#endif + } + else { + LOC_LOGE("%s:%d]: Unrecognized value for SAP Mode."\ + " Setting SAP to default mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SAP_BASIC; + } + + // Set service mask for ODCPI + if (strcmp(conf.feature_odcpi, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting ODCPI to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_ODCPI; + } + else if (strcmp(conf.feature_odcpi, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: Setting ODCPI to mode: DISABLED", __func__, __LINE__); + } + else if (strcmp(conf.feature_odcpi, "PREMIUM") == 0) { + LOC_LOGD("%s:%d]: Unrecognized value for ODCPI mode."\ + "Setting ODCPI to default mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_ODCPI; + } + + // Set service mask for FREE_WIFI_SCAN_INJECT + if (strcmp(conf.feature_free_wifi_scan_inject, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT; + } + else if (strcmp(conf.feature_free_wifi_scan_inject, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: Setting FREE_WIFI_SCAN_INJECT to mode: DISABLED", __func__, __LINE__); + } + else if (strcmp(conf.feature_free_wifi_scan_inject, "PREMIUM") == 0) { + LOC_LOGD("%s:%d]: Unrecognized value for FREE_WIFI_SCAN_INJECT mode."\ + "Setting FREE_WIFI_SCAN_INJECT to default mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_FREE_WIFI_SCAN_INJECT; + } + + // Set service mask for SUPL_WIFI + if (strcmp(conf.feature_supl_wifi, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI; + } + else if (strcmp(conf.feature_supl_wifi, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: Setting SUPL_WIFI to mode: DISABLED", __func__, __LINE__); + } + else if (strcmp(conf.feature_supl_wifi, "PREMIUM") == 0) { + LOC_LOGD("%s:%d]: Unrecognized value for SUPL_WIFI mode."\ + "Setting SUPL_WIFI to default mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_SUPL_WIFI; + } + + // Set service mask for WIFI_SUPPLICANT_INFO + if (strcmp(conf.feature_wifi_supplicant_info, "BASIC") == 0) { + LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO; + } + else if (strcmp(conf.feature_wifi_supplicant_info, "DISABLED") == 0) { + LOC_LOGD("%s:%d]: Setting WIFI_SUPPLICANT_INFO to mode: DISABLED", __func__, __LINE__); + } + else if (strcmp(conf.feature_wifi_supplicant_info, "PREMIUM") == 0) { + LOC_LOGD("%s:%d]: Unrecognized value for WIFI_SUPPLICANT_INFO mode."\ + "Setting LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO to default mode: BASIC", __func__, __LINE__); + loc_service_mask |= LOC_FEATURE_MASK_WIFI_SUPPLICANT_INFO; + } + + LOC_LOGD("%s:%d]: loc_service_mask: %x\n", __func__, __LINE__, loc_service_mask); + + if((conf_fp = fopen(conf_file_name, "r")) == NULL) { + LOC_LOGE("%s:%d]: Error opening %s %s\n", __func__, + __LINE__, conf_file_name, strerror(errno)); + ret = -1; + goto err; + } + + //Parse through the file to find out how many processes are to be launched + proc_list_length = 0; + do { + conf.proc_name[0] = 0; + //Here note that the 3rd parameter is passed as 1. + //This is so that only the first parameter in the table which is "PROCESS_NAME" + //is read. We do not want to read the entire block of parameters at this time + //since we are only counting the number of processes to launch. + //Therefore, only counting the occurrences of PROCESS_NAME parameter + //should suffice + if(loc_read_conf_r(conf_fp, loc_process_conf_parameter_table, 1)) { + LOC_LOGE("%s:%d]: Unable to read conf file. Failing\n", __func__, __LINE__); + ret = -1; + goto err; + } + name_length=(int)strlen(conf.proc_name); + if(name_length) { + proc_list_length++; + LOC_LOGD("Process name:%s", conf.proc_name); + } + } while(name_length); + LOC_LOGD("Process cnt = %d", proc_list_length); + + child_proc = (loc_process_info_s_type *)calloc(proc_list_length, sizeof(loc_process_info_s_type)); + if(child_proc == NULL) { + LOC_LOGE("%s:%d]: ERROR: Malloc returned NULL\n", __func__, __LINE__); + ret = -1; + goto err; + } + + //Move file descriptor to the beginning of the file + //so that the parameters can be read + rewind(conf_fp); + + for(j=0; j LOC_MAX_PARAM_STRING) { + LOC_LOGE("%s:%d]: i: %d; Length of name parameter too long. Max length: %d", + __func__, __LINE__, i, LOC_MAX_PARAM_STRING); + continue; + } + strlcpy(child_proc[j].name[0], conf.proc_name, sizeof (child_proc[j].name[0])); + + child_proc[j].num_groups = 0; + ngroups = loc_util_split_string(conf.group_list, split_strings, MAX_NUM_STRINGS, ' '); + for(i=0; igr_gid; + child_proc[j].num_groups++; + LOC_LOGd("Group %s = %d", split_strings[i], grp->gr_gid); + } + } + + nstrings = loc_util_split_string(conf.platform_list, split_strings, MAX_NUM_STRINGS, ' '); + if (strcmp("all", split_strings[0]) == 0) { + if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) { + LOC_LOGD("%s:%d]: Enabled for all targets\n", __func__, __LINE__); + config_mask |= CONFIG_MASK_TARGET_ALL; + } + else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) { + config_mask |= CONFIG_MASK_TARGET_FOUND; + for (i=2; i 2 && (strcmp("exclude", split_strings[1]) == 0)) { + config_mask |= CONFIG_MASK_SOCID_FOUND; + for (i = 2; i < nstrings; i++) { + if (strcmp(socid_value, split_strings[i]) == 0) { + LOC_LOGd("Disabled for SOC id %s\n", socid_value); + config_mask &= ~CONFIG_MASK_SOCID_FOUND; + break; + } + } + } + } + else { + for (i = 0; i < nstrings; i++) { + if (strcmp(socid_value, split_strings[i]) == 0) { + LOC_LOGd("Matched SOC id : %s\n", split_strings[i]); + config_mask |= CONFIG_MASK_SOCID_FOUND; + break; + } + } + } + + nstrings = loc_util_split_string(conf.baseband, split_strings, MAX_NUM_STRINGS, ' '); + if (strcmp("all", split_strings[0]) == 0) { + if (nstrings == 1 || (nstrings == 2 && (strcmp("exclude", split_strings[1]) == 0))) { + LOC_LOGD("%s:%d]: Enabled for all basebands\n", __func__, __LINE__); + config_mask |= CONFIG_MASK_BASEBAND_ALL; + } + else if (nstrings > 2 && (strcmp("exclude", split_strings[1]) == 0)) { + config_mask |= CONFIG_MASK_BASEBAND_FOUND; + for (i=2; i +#include +#include +#include +#include + +#define LOC_MAX_PARAM_NAME 80 +#define LOC_MAX_PARAM_STRING 172 +#define LOC_MAX_PARAM_LINE (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING) + +#define LOC_FEATURE_MODE_DISABLED "DISABLED" +#define LOC_FEATURE_MODE_BASIC "BASIC" +#define LOC_FEATURE_MODE_PREMIUM "PREMIUM" + +#define LOC_FEATURE_GTP_AP_CELL "gtp-ap-cell" +#define LOC_FEATURE_GTP_MODEM_CELL "gtp-modem-cell" +#define LOC_FEATURE_GTP_CELL_ENH "gtp-cell-enh" +#define LOC_FEATURE_GTP_WIFI "gtp-wifi" +#define LOC_FEATURE_GTP_WAA "gtp-waa" +#define LOC_FEATURE_SAP "sap" + +#define LOC_PROCESS_MAX_NUM_GROUPS 20 +#define LOC_PROCESS_MAX_NUM_ARGS 25 +#define LOC_PROCESS_MAX_ARG_STR_LENGTH 32 + +#define UTIL_UPDATE_CONF(conf_data, len, config_table) \ + loc_update_conf((conf_data), (len), (&config_table[0]), \ + sizeof(config_table) / sizeof(config_table[0])) + +#define UTIL_READ_CONF_DEFAULT(filename) \ + loc_read_conf((filename), NULL, 0); + +#define UTIL_READ_CONF(filename, config_table) \ + loc_read_conf((filename), (&config_table[0]), sizeof(config_table) / sizeof(config_table[0])) + +#define UTIL_READ_CONF_LONG(filename, config_table, rec_len) \ + loc_read_conf_long((filename), (&config_table[0]), \ + sizeof(config_table) / sizeof(config_table[0]), (rec_len)) + +/*============================================================================= + * + * MODULE TYPE DECLARATION + * + *============================================================================*/ +typedef struct +{ + const char *param_name; + void *param_ptr; /* for string type, buf size need to be LOC_MAX_PARAM_STRING */ + uint8_t *param_set; /* indicate value set by config file */ + char param_type; /* 'n' for number, + 's' for string, NOTE: buf size need to be LOC_MAX_PARAM_STRING + 'f' for double */ +} loc_param_s_type; + +typedef enum { + ENABLED, + RUNNING, + DISABLED, + DISABLED_FROM_CONF, + DISABLED_VIA_VENDOR_ENHANCED_CHECK +} loc_process_e_status; + +typedef struct { + loc_process_e_status proc_status; + pid_t proc_id; + char name[2][LOC_MAX_PARAM_STRING]; + gid_t group_list[LOC_PROCESS_MAX_NUM_GROUPS]; + unsigned char num_groups; + char args[LOC_PROCESS_MAX_NUM_ARGS][LOC_PROCESS_MAX_ARG_STR_LENGTH]; + char argumentString[LOC_MAX_PARAM_STRING]; +} loc_process_info_s_type; + +/*============================================================================= + * + * MODULE EXTERNAL DATA + * + *============================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*============================================================================= + * + * MODULE EXPORTED FUNCTIONS + * + *============================================================================*/ +bool isVendorEnhanced(); +void setVendorEnhanced(bool vendorEnhanced); +void loc_read_conf_long(const char* conf_file_name, + const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len); +int loc_read_conf_r_long(FILE *conf_fp, const loc_param_s_type* config_table, + uint32_t table_length, uint16_t string_len); +int loc_update_conf_long(const char* conf_data, int32_t length, + const loc_param_s_type* config_table, uint32_t table_length, + uint16_t string_len); + +inline void loc_read_conf(const char* conf_file_name, + const loc_param_s_type* config_table, uint32_t table_length) { + loc_read_conf_long(conf_file_name, config_table, table_length, LOC_MAX_PARAM_STRING); +} + +inline int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table, + uint32_t table_length) { + return (loc_read_conf_r_long(conf_fp, config_table, table_length, LOC_MAX_PARAM_STRING)); +} + +inline int loc_update_conf(const char* conf_data, int32_t length, + const loc_param_s_type* config_table, uint32_t table_length) { + return (loc_update_conf_long( + conf_data, length, config_table, table_length, LOC_MAX_PARAM_STRING)); +} + +// Below are the location conf file paths +extern const char LOC_PATH_GPS_CONF[]; +extern const char LOC_PATH_IZAT_CONF[]; +extern const char LOC_PATH_FLP_CONF[]; +extern const char LOC_PATH_LOWI_CONF[]; +extern const char LOC_PATH_SAP_CONF[]; +extern const char LOC_PATH_APDR_CONF[]; +extern const char LOC_PATH_XTWIFI_CONF[]; +extern const char LOC_PATH_QUIPC_CONF[]; +extern const char LOC_PATH_ANT_CORR[]; +extern const char LOC_PATH_SLIM_CONF[]; +extern const char LOC_PATH_VPE_CONF[]; + +int loc_read_process_conf(const char* conf_file_name, uint32_t * process_count_ptr, + loc_process_info_s_type** process_info_table_ptr); +int loc_get_datum_type(); +#ifdef __cplusplus +} +#endif + +#endif /* LOC_CFG_H */ diff --git a/gps/utils/loc_gps.h b/gps/utils/loc_gps.h new file mode 100644 index 0000000..90541c4 --- /dev/null +++ b/gps/utils/loc_gps.h @@ -0,0 +1,2235 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOC_GPS_H +#define LOC_GPS_H + +#include +#include +#include +#include +#include +#include + +__BEGIN_DECLS + +#define LOC_FLP_STATUS_LOCATION_AVAILABLE 0 +#define LOC_FLP_STATUS_LOCATION_UNAVAILABLE 1 +#define LOC_CAPABILITY_GNSS (1U<<0) +#define LOC_CAPABILITY_WIFI (1U<<1) +#define LOC_CAPABILITY_CELL (1U<<3) + +/** Milliseconds since January 1, 1970 */ +typedef int64_t LocGpsUtcTime; + +/** Maximum number of SVs for loc_gps_sv_status_callback(). */ +#define LOC_GPS_MAX_SVS 32 +/** Maximum number of SVs for loc_gps_sv_status_callback(). */ +#define LOC_GNSS_MAX_SVS 64 + +/** Maximum number of Measurements in loc_gps_measurement_callback(). */ +#define LOC_GPS_MAX_MEASUREMENT 32 + +/** Maximum number of Measurements in loc_gnss_measurement_callback(). */ +#define LOC_GNSS_MAX_MEASUREMENT 64 + +/** Requested operational mode for GPS operation. */ +typedef uint32_t LocGpsPositionMode; +/* IMPORTANT: Note that the following values must match + * constants in GpsLocationProvider.java. */ +/** Mode for running GPS standalone (no assistance). */ +#define LOC_GPS_POSITION_MODE_STANDALONE 0 +/** AGPS MS-Based mode. */ +#define LOC_GPS_POSITION_MODE_MS_BASED 1 +/** + * AGPS MS-Assisted mode. This mode is not maintained by the platform anymore. + * It is strongly recommended to use LOC_GPS_POSITION_MODE_MS_BASED instead. + */ +#define LOC_GPS_POSITION_MODE_MS_ASSISTED 2 + +/** Requested recurrence mode for GPS operation. */ +typedef uint32_t LocGpsPositionRecurrence; +/* IMPORTANT: Note that the following values must match + * constants in GpsLocationProvider.java. */ +/** Receive GPS fixes on a recurring basis at a specified period. */ +#define LOC_GPS_POSITION_RECURRENCE_PERIODIC 0 +/** Request a single shot GPS fix. */ +#define LOC_GPS_POSITION_RECURRENCE_SINGLE 1 + +/** GPS status event values. */ +typedef uint16_t LocGpsStatusValue; +/* IMPORTANT: Note that the following values must match + * constants in GpsLocationProvider.java. */ +/** GPS status unknown. */ +#define LOC_GPS_STATUS_NONE 0 +/** GPS has begun navigating. */ +#define LOC_GPS_STATUS_SESSION_BEGIN 1 +/** GPS has stopped navigating. */ +#define LOC_GPS_STATUS_SESSION_END 2 +/** GPS has powered on but is not navigating. */ +#define LOC_GPS_STATUS_ENGINE_ON 3 +/** GPS is powered off. */ +#define LOC_GPS_STATUS_ENGINE_OFF 4 + +/** Flags to indicate which values are valid in a LocGpsLocation. */ +typedef uint16_t LocGpsLocationFlags; +/* IMPORTANT: Note that the following values must match + * constants in GpsLocationProvider.java. */ +/** LocGpsLocation has valid latitude and longitude. */ +#define LOC_GPS_LOCATION_HAS_LAT_LONG 0x0001 +/** LocGpsLocation has valid altitude. */ +#define LOC_GPS_LOCATION_HAS_ALTITUDE 0x0002 +/** LocGpsLocation has valid speed. */ +#define LOC_GPS_LOCATION_HAS_SPEED 0x0004 +/** LocGpsLocation has valid bearing. */ +#define LOC_GPS_LOCATION_HAS_BEARING 0x0008 +/** LocGpsLocation has valid accuracy. */ +#define LOC_GPS_LOCATION_HAS_ACCURACY 0x0010 +/** LocGpsLocation has valid vertical uncertainity */ +#define LOC_GPS_LOCATION_HAS_VERT_UNCERTAINITY 0x0040 +/** LocGpsLocation has valid spoof mask */ +#define LOC_GPS_LOCATION_HAS_SPOOF_MASK 0x0080 +/** LocGpsLocation has valid speed accuracy */ +#define LOC_GPS_LOCATION_HAS_SPEED_ACCURACY 0x0100 +/** LocGpsLocation has valid bearing accuracy */ +#define LOC_GPS_LOCATION_HAS_BEARING_ACCURACY 0x0200 +/** LocGpsLocation has valid Real Time and Real Time Uncertainty */ +#define LOC_GPS_LOCATION_HAS_ELAPSED_REAL_TIME 0x0400 + +/** Spoof mask in LocGpsLocation */ +typedef uint32_t LocGpsSpoofMask; +#define LOC_GPS_LOCATION_NONE_SPOOFED 0x0000 +#define LOC_GPS_LOCATION_POSITION_SPOOFED 0x0001 +#define LOC_GPS_LOCATION_TIME_SPOOFED 0x0002 +#define LOC_GPS_LOCATION_NAVIGATION_DATA_SPOOFED 0x0004 + +/** Flags for the loc_gps_set_capabilities callback. */ + +/** + * GPS HAL schedules fixes for LOC_GPS_POSITION_RECURRENCE_PERIODIC mode. If this is + * not set, then the framework will use 1000ms for min_interval and will start + * and call start() and stop() to schedule the GPS. + */ +#define LOC_GPS_CAPABILITY_SCHEDULING (1 << 0) +/** GPS supports MS-Based AGPS mode */ +#define LOC_GPS_CAPABILITY_MSB (1 << 1) +/** GPS supports MS-Assisted AGPS mode */ +#define LOC_GPS_CAPABILITY_MSA (1 << 2) +/** GPS supports single-shot fixes */ +#define LOC_GPS_CAPABILITY_SINGLE_SHOT (1 << 3) +/** GPS supports on demand time injection */ +#define LOC_GPS_CAPABILITY_ON_DEMAND_TIME (1 << 4) +/** GPS supports Geofencing */ +#define LOC_GPS_CAPABILITY_GEOFENCING (1 << 5) +/** GPS supports Measurements. */ +#define LOC_GPS_CAPABILITY_MEASUREMENTS (1 << 6) +/** GPS supports Navigation Messages */ +#define LOC_GPS_CAPABILITY_NAV_MESSAGES (1 << 7) + +/** + * Flags used to specify which aiding data to delete when calling + * delete_aiding_data(). + */ +typedef uint16_t LocGpsAidingData; +/* IMPORTANT: Note that the following values must match + * constants in GpsLocationProvider.java. */ +#define LOC_GPS_DELETE_EPHEMERIS 0x0001 +#define LOC_GPS_DELETE_ALMANAC 0x0002 +#define LOC_GPS_DELETE_POSITION 0x0004 +#define LOC_GPS_DELETE_TIME 0x0008 +#define LOC_GPS_DELETE_IONO 0x0010 +#define LOC_GPS_DELETE_UTC 0x0020 +#define LOC_GPS_DELETE_HEALTH 0x0040 +#define LOC_GPS_DELETE_SVDIR 0x0080 +#define LOC_GPS_DELETE_SVSTEER 0x0100 +#define LOC_GPS_DELETE_SADATA 0x0200 +#define LOC_GPS_DELETE_RTI 0x0400 +#define LOC_GPS_DELETE_MB_DATA 0x0800 +#define LOC_GPS_DELETE_CELLDB_INFO 0x8000 +#define LOC_GPS_DELETE_ALL 0xFFFF + +/** AGPS type */ +typedef uint16_t LocAGpsType; +#define LOC_AGPS_TYPE_ANY 0 +#define LOC_AGPS_TYPE_SUPL 1 +#define LOC_AGPS_TYPE_C2K 2 +#define LOC_AGPS_TYPE_WWAN_ANY 3 +#define LOC_AGPS_TYPE_WIFI 4 +#define LOC_AGPS_TYPE_SUPL_ES 5 + +typedef uint16_t LocAGpsSetIDType; +#define LOC_AGPS_SETID_TYPE_NONE 0 +#define LOC_AGPS_SETID_TYPE_IMSI 1 +#define LOC_AGPS_SETID_TYPE_MSISDN 2 + +typedef uint16_t LocApnIpType; +#define LOC_APN_IP_INVALID 0 +#define LOC_APN_IP_IPV4 1 +#define LOC_APN_IP_IPV6 2 +#define LOC_APN_IP_IPV4V6 3 + +/** + * String length constants + */ +#define LOC_GPS_NI_SHORT_STRING_MAXLEN 256 +#define LOC_GPS_NI_LONG_STRING_MAXLEN 2048 + +/** + * LocGpsNiType constants + */ +typedef uint32_t LocGpsNiType; +#define LOC_GPS_NI_TYPE_VOICE 1 +#define LOC_GPS_NI_TYPE_UMTS_SUPL 2 +#define LOC_GPS_NI_TYPE_UMTS_CTRL_PLANE 3 +/*Emergency SUPL*/ +#define LOC_GPS_NI_TYPE_EMERGENCY_SUPL 4 + +/** + * LocGpsNiNotifyFlags constants + */ +typedef uint32_t LocGpsNiNotifyFlags; +/** NI requires notification */ +#define LOC_GPS_NI_NEED_NOTIFY 0x0001 +/** NI requires verification */ +#define LOC_GPS_NI_NEED_VERIFY 0x0002 +/** NI requires privacy override, no notification/minimal trace */ +#define LOC_GPS_NI_PRIVACY_OVERRIDE 0x0004 + +/** + * GPS NI responses, used to define the response in + * NI structures + */ +typedef int LocGpsUserResponseType; +#define LOC_GPS_NI_RESPONSE_ACCEPT 1 +#define LOC_GPS_NI_RESPONSE_DENY 2 +#define LOC_GPS_NI_RESPONSE_NORESP 3 + +/** + * NI data encoding scheme + */ +typedef int LocGpsNiEncodingType; +#define LOC_GPS_ENC_NONE 0 +#define LOC_GPS_ENC_SUPL_GSM_DEFAULT 1 +#define LOC_GPS_ENC_SUPL_UTF8 2 +#define LOC_GPS_ENC_SUPL_UCS2 3 +#define LOC_GPS_ENC_UNKNOWN -1 + +/** AGPS status event values. */ +typedef uint8_t LocAGpsStatusValue; +/** GPS requests data connection for AGPS. */ +#define LOC_GPS_REQUEST_AGPS_DATA_CONN 1 +/** GPS releases the AGPS data connection. */ +#define LOC_GPS_RELEASE_AGPS_DATA_CONN 2 +/** AGPS data connection initiated */ +#define LOC_GPS_AGPS_DATA_CONNECTED 3 +/** AGPS data connection completed */ +#define LOC_GPS_AGPS_DATA_CONN_DONE 4 +/** AGPS data connection failed */ +#define LOC_GPS_AGPS_DATA_CONN_FAILED 5 + +typedef uint16_t LocAGpsRefLocationType; +#define LOC_AGPS_REF_LOCATION_TYPE_GSM_CELLID 1 +#define LOC_AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2 +#define LOC_AGPS_REF_LOCATION_TYPE_MAC 3 +#define LOC_AGPS_REF_LOCATION_TYPE_LTE_CELLID 4 + +/* Deprecated, to be removed in the next Android release. */ +#define LOC_AGPS_REG_LOCATION_TYPE_MAC 3 + +/** Network types for update_network_state "type" parameter */ +#define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE 0 +#define LOC_AGPS_RIL_NETWORK_TYPE_WIFI 1 +#define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2 +#define LOC_AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3 +#define LOC_AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4 +#define LOC_AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5 +#define LOC_AGPS_RIL_NETWORK_TTYPE_WIMAX 6 + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint16_t LocGpsClockFlags; +#define LOC_GPS_CLOCK_HAS_LEAP_SECOND (1<<0) +#define LOC_GPS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1) +#define LOC_GPS_CLOCK_HAS_FULL_BIAS (1<<2) +#define LOC_GPS_CLOCK_HAS_BIAS (1<<3) +#define LOC_GPS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4) +#define LOC_GPS_CLOCK_HAS_DRIFT (1<<5) +#define LOC_GPS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6) + +/** + * Flags to indicate what fields in LocGnssClock are valid. + */ +typedef uint16_t LocGnssClockFlags; +/** A valid 'leap second' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_LEAP_SECOND (1<<0) +/** A valid 'time uncertainty' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY (1<<1) +/** A valid 'full bias' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_FULL_BIAS (1<<2) +/** A valid 'bias' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_BIAS (1<<3) +/** A valid 'bias uncertainty' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY (1<<4) +/** A valid 'drift' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_DRIFT (1<<5) +/** A valid 'drift uncertainty' is stored in the data structure. */ +#define LOC_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY (1<<6) + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint8_t LocGpsClockType; +#define LOC_GPS_CLOCK_TYPE_UNKNOWN 0 +#define LOC_GPS_CLOCK_TYPE_LOCAL_HW_TIME 1 +#define LOC_GPS_CLOCK_TYPE_GPS_TIME 2 + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint32_t LocGpsMeasurementFlags; +#define LOC_GPS_MEASUREMENT_HAS_SNR (1<<0) +#define LOC_GPS_MEASUREMENT_HAS_ELEVATION (1<<1) +#define LOC_GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY (1<<2) +#define LOC_GPS_MEASUREMENT_HAS_AZIMUTH (1<<3) +#define LOC_GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY (1<<4) +#define LOC_GPS_MEASUREMENT_HAS_PSEUDORANGE (1<<5) +#define LOC_GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY (1<<6) +#define LOC_GPS_MEASUREMENT_HAS_CODE_PHASE (1<<7) +#define LOC_GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY (1<<8) +#define LOC_GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9) +#define LOC_GPS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10) +#define LOC_GPS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11) +#define LOC_GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12) +#define LOC_GPS_MEASUREMENT_HAS_BIT_NUMBER (1<<13) +#define LOC_GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT (1<<14) +#define LOC_GPS_MEASUREMENT_HAS_DOPPLER_SHIFT (1<<15) +#define LOC_GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY (1<<16) +#define LOC_GPS_MEASUREMENT_HAS_USED_IN_FIX (1<<17) +#define LOC_GPS_MEASUREMENT_HAS_UNCORRECTED_PSEUDORANGE_RATE (1<<18) + +/** + * Flags to indicate what fields in LocGnssMeasurement are valid. + */ +typedef uint32_t LocGnssMeasurementFlags; +/** A valid 'snr' is stored in the data structure. */ +#define LOC_GNSS_MEASUREMENT_HAS_SNR (1<<0) +/** A valid 'carrier frequency' is stored in the data structure. */ +#define LOC_GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY (1<<9) +/** A valid 'carrier cycles' is stored in the data structure. */ +#define LOC_GNSS_MEASUREMENT_HAS_CARRIER_CYCLES (1<<10) +/** A valid 'carrier phase' is stored in the data structure. */ +#define LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE (1<<11) +/** A valid 'carrier phase uncertainty' is stored in the data structure. */ +#define LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY (1<<12) + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint8_t LocGpsLossOfLock; +#define LOC_GPS_LOSS_OF_LOCK_UNKNOWN 0 +#define LOC_GPS_LOSS_OF_LOCK_OK 1 +#define LOC_GPS_LOSS_OF_LOCK_CYCLE_SLIP 2 + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. Use LocGnssMultipathIndicator instead. + */ +typedef uint8_t LocGpsMultipathIndicator; +#define LOC_GPS_MULTIPATH_INDICATOR_UNKNOWN 0 +#define LOC_GPS_MULTIPATH_INDICATOR_DETECTED 1 +#define LOC_GPS_MULTIPATH_INDICATOR_NOT_USED 2 + +/** + * Enumeration of available values for the GNSS Measurement's multipath + * indicator. + */ +typedef uint8_t LocGnssMultipathIndicator; +/** The indicator is not available or unknown. */ +#define LOC_GNSS_MULTIPATH_INDICATOR_UNKNOWN 0 +/** The measurement is indicated to be affected by multipath. */ +#define LOC_GNSS_MULTIPATH_INDICATOR_PRESENT 1 +/** The measurement is indicated to be not affected by multipath. */ +#define LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT 2 + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint16_t LocGpsMeasurementState; +#define LOC_GPS_MEASUREMENT_STATE_UNKNOWN 0 +#define LOC_GPS_MEASUREMENT_STATE_CODE_LOCK (1<<0) +#define LOC_GPS_MEASUREMENT_STATE_BIT_SYNC (1<<1) +#define LOC_GPS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2) +#define LOC_GPS_MEASUREMENT_STATE_TOW_DECODED (1<<3) +#define LOC_GPS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4) + +/** + * Flags indicating the GNSS measurement state. + * + * The expected behavior here is for GPS HAL to set all the flags that applies. + * For example, if the state for a satellite is only C/A code locked and bit + * synchronized, and there is still millisecond ambiguity, the state should be + * set as: + * + * LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK | LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC | + * LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS + * + * If GNSS is still searching for a satellite, the corresponding state should be + * set to LOC_GNSS_MEASUREMENT_STATE_UNKNOWN(0). + */ +typedef uint32_t LocGnssMeasurementState; +#define LOC_GNSS_MEASUREMENT_STATE_UNKNOWN 0 +#define LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK (1<<0) +#define LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC (1<<1) +#define LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC (1<<2) +#define LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED (1<<3) +#define LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS (1<<4) +#define LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC (1<<5) +#define LOC_GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC (1<<6) +#define LOC_GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED (1<<7) +#define LOC_GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC (1<<8) +#define LOC_GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC (1<<9) +#define LOC_GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK (1<<10) +#define LOC_GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK (1<<11) +#define LOC_GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC (1<<12) +#define LOC_GNSS_MEASUREMENT_STATE_SBAS_SYNC (1<<13) + +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint16_t LocGpsAccumulatedDeltaRangeState; +#define LOC_GPS_ADR_STATE_UNKNOWN 0 +#define LOC_GPS_ADR_STATE_VALID (1<<0) +#define LOC_GPS_ADR_STATE_RESET (1<<1) +#define LOC_GPS_ADR_STATE_CYCLE_SLIP (1<<2) + +/** + * Flags indicating the Accumulated Delta Range's states. + */ +typedef uint16_t LocGnssAccumulatedDeltaRangeState; +#define LOC_GNSS_ADR_STATE_UNKNOWN 0 +#define LOC_GNSS_ADR_STATE_VALID (1<<0) +#define LOC_GNSS_ADR_STATE_RESET (1<<1) +#define LOC_GNSS_ADR_STATE_CYCLE_SLIP (1<<2) + +#if 0 +/* The following typedef together with its constants below are deprecated, and + * will be removed in the next release. */ +typedef uint8_t GpsNavigationMessageType; +#define GPS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0 +#define GPS_NAVIGATION_MESSAGE_TYPE_L1CA 1 +#define GPS_NAVIGATION_MESSAGE_TYPE_L2CNAV 2 +#define GPS_NAVIGATION_MESSAGE_TYPE_L5CNAV 3 +#define GPS_NAVIGATION_MESSAGE_TYPE_CNAV2 4 + +/** + * Enumeration of available values to indicate the GNSS Navigation message + * types. + * + * For convenience, first byte is the LocGnssConstellationType on which that signal + * is typically transmitted + */ +typedef int16_t GnssNavigationMessageType; + +#define GNSS_NAVIGATION_MESSAGE_TYPE_UNKNOWN 0 +/** GPS L1 C/A message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L1CA 0x0101 +/** GPS L2-CNAV message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L2CNAV 0x0102 +/** GPS L5-CNAV message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L5CNAV 0x0103 +/** GPS CNAV-2 message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_CNAV2 0x0104 +/** Glonass L1 CA message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GLO_L1CA 0x0301 +/** Beidou D1 message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D1 0x0501 +/** Beidou D2 message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_BDS_D2 0x0502 +/** Galileo I/NAV message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_I 0x0601 +/** Galileo F/NAV message contained in the structure. */ +#define GNSS_NAVIGATION_MESSAGE_TYPE_GAL_F 0x0602 + +/** + * Status of Navigation Message + * When a message is received properly without any parity error in its navigation words, the + * status should be set to NAV_MESSAGE_STATUS_PARITY_PASSED. But if a message is received + * with words that failed parity check, but GPS is able to correct those words, the status + * should be set to NAV_MESSAGE_STATUS_PARITY_REBUILT. + * No need to send any navigation message that contains words with parity error and cannot be + * corrected. + */ +typedef uint16_t NavigationMessageStatus; +#define NAV_MESSAGE_STATUS_UNKNOWN 0 +#define NAV_MESSAGE_STATUS_PARITY_PASSED (1<<0) +#define NAV_MESSAGE_STATUS_PARITY_REBUILT (1<<1) + +/* This constant is deprecated, and will be removed in the next release. */ +#define NAV_MESSAGE_STATUS_UNKONW 0 +#endif + +/** + * Flags that indicate information about the satellite + */ +typedef uint8_t LocGnssSvFlags; +#define LOC_GNSS_SV_FLAGS_NONE 0 +#define LOC_GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA (1 << 0) +#define LOC_GNSS_SV_FLAGS_HAS_ALMANAC_DATA (1 << 1) +#define LOC_GNSS_SV_FLAGS_USED_IN_FIX (1 << 2) + +/** + * Constellation type of LocGnssSvInfo + */ +typedef uint8_t LocGnssConstellationType; +#define LOC_GNSS_CONSTELLATION_UNKNOWN 0 +#define LOC_GNSS_CONSTELLATION_GPS 1 +#define LOC_GNSS_CONSTELLATION_SBAS 2 +#define LOC_GNSS_CONSTELLATION_GLONASS 3 +#define LOC_GNSS_CONSTELLATION_QZSS 4 +#define LOC_GNSS_CONSTELLATION_BEIDOU 5 +#define LOC_GNSS_CONSTELLATION_GALILEO 6 + +/** + * Name for the GPS XTRA interface. + */ +#define LOC_GPS_XTRA_INTERFACE "gps-xtra" + +/** + * Name for the GPS DEBUG interface. + */ +#define LOC_GPS_DEBUG_INTERFACE "gps-debug" + +/** + * Name for the AGPS interface. + */ + +#define LOC_AGPS_INTERFACE "agps" + +/** + * Name of the Supl Certificate interface. + */ +#define LOC_SUPL_CERTIFICATE_INTERFACE "supl-certificate" + +/** + * Name for NI interface + */ +#define LOC_GPS_NI_INTERFACE "gps-ni" + +/** + * Name for the AGPS-RIL interface. + */ +#define LOC_AGPS_RIL_INTERFACE "agps_ril" + +/** + * Name for the GPS_Geofencing interface. + */ +#define LOC_GPS_GEOFENCING_INTERFACE "gps_geofencing" + +/** + * Name of the GPS Measurements interface. + */ +#define LOC_GPS_MEASUREMENT_INTERFACE "gps_measurement" + +/** + * Name of the GPS navigation message interface. + */ +#define LOC_GPS_NAVIGATION_MESSAGE_INTERFACE "gps_navigation_message" + +/** + * Name of the GNSS/GPS configuration interface. + */ +#define LOC_GNSS_CONFIGURATION_INTERFACE "gnss_configuration" + +/** Represents a location. */ +typedef struct { + /** set to sizeof(LocGpsLocation) */ + uint32_t size; + /** Contains LocGpsLocationFlags bits. */ + uint16_t flags; + /** The spoof mask */ + LocGpsSpoofMask spoof_mask; + /** Represents latitude in degrees. */ + double latitude; + /** Represents longitude in degrees. */ + double longitude; + /** + * Represents altitude in meters above the WGS 84 reference ellipsoid. + */ + double altitude; + /** Represents horizontal speed in meters per second. */ + float speed; + /** Represents heading in degrees. */ + float bearing; + /** Represents expected accuracy in meters. */ + float accuracy; + /** Represents the expected vertical uncertainity in meters*/ + float vertUncertainity; + /** Timestamp for the location fix. */ + LocGpsUtcTime timestamp; + /** Elapsed RealTime in nanosends */ + uint64_t elapsedRealTime; + /** Elapsed Real Time Uncertainty in nanosends */ + uint64_t elapsedRealTimeUnc; +} LocGpsLocation; + +/** Represents the status. */ +typedef struct { + /** set to sizeof(LocGpsStatus) */ + size_t size; + LocGpsStatusValue status; +} LocGpsStatus; + +/** + * Legacy struct to represents SV information. + * Deprecated, to be removed in the next Android release. + * Use LocGnssSvInfo instead. + */ +typedef struct { + /** set to sizeof(LocGpsSvInfo) */ + size_t size; + /** Pseudo-random number for the SV. */ + int prn; + /** Signal to noise ratio. */ + float snr; + /** Elevation of SV in degrees. */ + float elevation; + /** Azimuth of SV in degrees. */ + float azimuth; +} LocGpsSvInfo; + +typedef struct { + /** set to sizeof(LocGnssSvInfo) */ + size_t size; + + /** + * Pseudo-random number for the SV, or FCN/OSN number for Glonass. The + * distinction is made by looking at constellation field. Values should be + * in the range of: + * + * - GPS: 1-32 + * - SBAS: 120-151, 183-192 + * - GLONASS: 1-24, the orbital slot number (OSN), if known. Or, if not: + * 93-106, the frequency channel number (FCN) (-7 to +6) offset by + 100 + * i.e. report an FCN of -7 as 93, FCN of 0 as 100, and FCN of +6 as 106. + * - QZSS: 193-200 + * - Galileo: 1-36 + * - Beidou: 1-37 + */ + int16_t svid; + + /** + * Defines the constellation of the given SV. Value should be one of those + * LOC_GNSS_CONSTELLATION_* constants + */ + LocGnssConstellationType constellation; + + /** + * Carrier-to-noise density in dB-Hz, typically in the range [0, 63]. + * It contains the measured C/N0 value for the signal at the antenna port. + * + * This is a mandatory value. + */ + float c_n0_dbhz; + + /** Elevation of SV in degrees. */ + float elevation; + + /** Azimuth of SV in degrees. */ + float azimuth; + + /** + * Contains additional data about the given SV. Value should be one of those + * LOC_GNSS_SV_FLAGS_* constants + */ + LocGnssSvFlags flags; + +} LocGnssSvInfo; + +/** + * Legacy struct to represents SV status. + * Deprecated, to be removed in the next Android release. + * Use LocGnssSvStatus instead. + */ +typedef struct { + /** set to sizeof(LocGpsSvStatus) */ + size_t size; + int num_svs; + LocGpsSvInfo sv_list[LOC_GPS_MAX_SVS]; + uint32_t ephemeris_mask; + uint32_t almanac_mask; + uint32_t used_in_fix_mask; +} LocGpsSvStatus; + +/** + * Represents SV status. + */ +typedef struct { + /** set to sizeof(LocGnssSvStatus) */ + size_t size; + + /** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */ + int num_svs; + /** + * Pointer to an array of SVs information for all GNSS constellations, + * except GPS, which is reported using sv_list + */ + LocGnssSvInfo gnss_sv_list[LOC_GNSS_MAX_SVS]; + +} LocGnssSvStatus; + +/* CellID for 2G, 3G and LTE, used in AGPS. */ +typedef struct { + LocAGpsRefLocationType type; + /** Mobile Country Code. */ + uint16_t mcc; + /** Mobile Network Code .*/ + uint16_t mnc; + /** Location Area Code in 2G, 3G and LTE. In 3G lac is discarded. In LTE, + * lac is populated with tac, to ensure that we don't break old clients that + * might rely in the old (wrong) behavior. + */ + uint16_t lac; + /** Cell id in 2G. Utran Cell id in 3G. Cell Global Id EUTRA in LTE. */ + uint32_t cid; + /** Tracking Area Code in LTE. */ + uint16_t tac; + /** Physical Cell id in LTE (not used in 2G and 3G) */ + uint16_t pcid; +} LocAGpsRefLocationCellID; + +typedef struct { + uint8_t mac[6]; +} LocAGpsRefLocationMac; + +/** Represents ref locations */ +typedef struct { + LocAGpsRefLocationType type; + union { + LocAGpsRefLocationCellID cellID; + LocAGpsRefLocationMac mac; + } u; +} LocAGpsRefLocation; + +/** + * Callback with location information. Can only be called from a thread created + * by create_thread_cb. + */ +typedef void (* loc_gps_location_callback)(LocGpsLocation* location); + +/** + * Callback with status information. Can only be called from a thread created by + * create_thread_cb. + */ +typedef void (* loc_gps_status_callback)(LocGpsStatus* status); +/** + * Legacy callback with SV status information. + * Can only be called from a thread created by create_thread_cb. + * + * This callback is deprecated, and will be removed in the next release. Use + * loc_gnss_sv_status_callback() instead. + */ +typedef void (* loc_gps_sv_status_callback)(LocGpsSvStatus* sv_info); + +/** + * Callback with SV status information. + * Can only be called from a thread created by create_thread_cb. + */ +typedef void (* loc_gnss_sv_status_callback)(LocGnssSvStatus* sv_info); + +/** + * Callback for reporting NMEA sentences. Can only be called from a thread + * created by create_thread_cb. + */ +typedef void (* loc_gps_nmea_callback)(LocGpsUtcTime timestamp, const char* nmea, int length); + +/** + * Callback to inform framework of the GPS engine's capabilities. Capability + * parameter is a bit field of LOC_GPS_CAPABILITY_* flags. + */ +typedef void (* loc_gps_set_capabilities)(uint32_t capabilities); + +/** + * Callback utility for acquiring the GPS wakelock. This can be used to prevent + * the CPU from suspending while handling GPS events. + */ +typedef void (* loc_gps_acquire_wakelock)(); + +/** Callback utility for releasing the GPS wakelock. */ +typedef void (* loc_gps_release_wakelock)(); + +/** Callback for requesting NTP time */ +typedef void (* loc_gps_request_utc_time)(); + +/** + * Callback for creating a thread that can call into the Java framework code. + * This must be used to create any threads that report events up to the + * framework. + */ +typedef pthread_t (* loc_gps_create_thread)(const char* name, void (*start)(void *), void* arg); + +/** + * Provides information about how new the underlying GPS/GNSS hardware and + * software is. + * + * This information will be available for Android Test Applications. If a GPS + * HAL does not provide this information, it will be considered "2015 or + * earlier". + * + * If a GPS HAL does provide this information, then newer years will need to + * meet newer CTS standards. E.g. if the date are 2016 or above, then N+ level + * LocGpsMeasurement support will be verified. + */ +typedef struct { + /** Set to sizeof(LocGnssSystemInfo) */ + size_t size; + /* year in which the last update was made to the underlying hardware/firmware + * used to capture GNSS signals, e.g. 2016 */ + uint16_t year_of_hw; +} LocGnssSystemInfo; + +/** + * Callback to inform framework of the engine's hardware version information. + */ +typedef void (*loc_gnss_set_system_info)(const LocGnssSystemInfo* info); + +/** New GPS callback structure. */ +typedef struct { + /** set to sizeof(LocGpsCallbacks) */ + size_t size; + loc_gps_location_callback location_cb; + loc_gps_status_callback status_cb; + loc_gps_sv_status_callback sv_status_cb; + loc_gps_nmea_callback nmea_cb; + loc_gps_set_capabilities set_capabilities_cb; + loc_gps_acquire_wakelock acquire_wakelock_cb; + loc_gps_release_wakelock release_wakelock_cb; + loc_gps_create_thread create_thread_cb; + loc_gps_request_utc_time request_utc_time_cb; + + loc_gnss_set_system_info set_system_info_cb; + loc_gnss_sv_status_callback gnss_sv_status_cb; +} LocGpsCallbacks; + +/** Represents the standard GPS interface. */ +typedef struct { + /** set to sizeof(LocGpsInterface) */ + size_t size; + /** + * Opens the interface and provides the callback routines + * to the implementation of this interface. + */ + int (*init)( LocGpsCallbacks* callbacks ); + + /** Starts navigating. */ + int (*start)( void ); + + /** Stops navigating. */ + int (*stop)( void ); + + /** Closes the interface. */ + void (*cleanup)( void ); + + /** Injects the current time. */ + int (*inject_time)(LocGpsUtcTime time, int64_t timeReference, + int uncertainty); + + /** + * Injects current location from another location provider (typically cell + * ID). Latitude and longitude are measured in degrees expected accuracy is + * measured in meters + */ + int (*inject_location)(double latitude, double longitude, float accuracy); + + /** + * Specifies that the next call to start will not use the + * information defined in the flags. LOC_GPS_DELETE_ALL is passed for + * a cold start. + */ + void (*delete_aiding_data)(LocGpsAidingData flags); + + /** + * min_interval represents the time between fixes in milliseconds. + * preferred_accuracy represents the requested fix accuracy in meters. + * preferred_time represents the requested time to first fix in milliseconds. + * + * 'mode' parameter should be one of LOC_GPS_POSITION_MODE_MS_BASED + * or LOC_GPS_POSITION_MODE_STANDALONE. + * It is allowed by the platform (and it is recommended) to fallback to + * LOC_GPS_POSITION_MODE_MS_BASED if LOC_GPS_POSITION_MODE_MS_ASSISTED is passed in, and + * LOC_GPS_POSITION_MODE_MS_BASED is supported. + */ + int (*set_position_mode)(LocGpsPositionMode mode, LocGpsPositionRecurrence recurrence, + uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time); + + /** Get a pointer to extension information. */ + const void* (*get_extension)(const char* name); +} LocGpsInterface; + +/** + * Callback to request the client to download XTRA data. The client should + * download XTRA data and inject it by calling inject_xtra_data(). Can only be + * called from a thread created by create_thread_cb. + */ +typedef void (* loc_gps_xtra_download_request)(); + +/** Callback structure for the XTRA interface. */ +typedef struct { + loc_gps_xtra_download_request download_request_cb; + loc_gps_create_thread create_thread_cb; +} LocGpsXtraCallbacks; + +/** Extended interface for XTRA support. */ +typedef struct { + /** set to sizeof(LocGpsXtraInterface) */ + size_t size; + /** + * Opens the XTRA interface and provides the callback routines + * to the implementation of this interface. + */ + int (*init)( LocGpsXtraCallbacks* callbacks ); + /** Injects XTRA data into the GPS. */ + int (*inject_xtra_data)( char* data, int length ); +} LocGpsXtraInterface; + +#if 0 +/** Extended interface for DEBUG support. */ +typedef struct { + /** set to sizeof(LocGpsDebugInterface) */ + size_t size; + + /** + * This function should return any information that the native + * implementation wishes to include in a bugreport. + */ + size_t (*get_internal_state)(char* buffer, size_t bufferSize); +} LocGpsDebugInterface; +#endif + +/* + * Represents the status of AGPS augmented to support IPv4 and IPv6. + */ +typedef struct { + /** set to sizeof(LocAGpsStatus) */ + size_t size; + + LocAGpsType type; + LocAGpsStatusValue status; + + /** + * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4 + * address, or set to INADDR_NONE otherwise. + */ + uint32_t ipaddr; + + /** + * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report. + * Any other value of addr.ss_family will be rejected. + */ + struct sockaddr_storage addr; +} LocAGpsStatus; + +/** + * Callback with AGPS status information. Can only be called from a thread + * created by create_thread_cb. + */ +typedef void (* loc_agps_status_callback)(LocAGpsStatus* status); + +/** Callback structure for the AGPS interface. */ +typedef struct { + loc_agps_status_callback status_cb; + loc_gps_create_thread create_thread_cb; +} LocAGpsCallbacks; + +/** + * Extended interface for AGPS support, it is augmented to enable to pass + * extra APN data. + */ +typedef struct { + /** set to sizeof(LocAGpsInterface) */ + size_t size; + + /** + * Opens the AGPS interface and provides the callback routines to the + * implementation of this interface. + */ + void (*init)(LocAGpsCallbacks* callbacks); + /** + * Deprecated. + * If the HAL supports LocAGpsInterface_v2 this API will not be used, see + * data_conn_open_with_apn_ip_type for more information. + */ + int (*data_conn_open)(const char* apn); + /** + * Notifies that the AGPS data connection has been closed. + */ + int (*data_conn_closed)(); + /** + * Notifies that a data connection is not available for AGPS. + */ + int (*data_conn_failed)(); + /** + * Sets the hostname and port for the AGPS server. + */ + int (*set_server)(LocAGpsType type, const char* hostname, int port); + + /** + * Notifies that a data connection is available and sets the name of the + * APN, and its IP type, to be used for SUPL connections. + */ + int (*data_conn_open_with_apn_ip_type)( + const char* apn, + LocApnIpType apnIpType); +} LocAGpsInterface; + +/** Error codes associated with certificate operations */ +#define LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS 0 +#define LOC_AGPS_CERTIFICATE_ERROR_GENERIC -100 +#define LOC_AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES -101 + +/** A data structure that represents an X.509 certificate using DER encoding */ +typedef struct { + size_t length; + u_char* data; +} LocDerEncodedCertificate; + +/** + * A type definition for SHA1 Fingerprints used to identify X.509 Certificates + * The Fingerprint is a digest of the DER Certificate that uniquely identifies it. + */ +typedef struct { + u_char data[20]; +} LocSha1CertificateFingerprint; + +/** AGPS Interface to handle SUPL certificate operations */ +typedef struct { + /** set to sizeof(LocSuplCertificateInterface) */ + size_t size; + + /** + * Installs a set of Certificates used for SUPL connections to the AGPS server. + * If needed the HAL should find out internally any certificates that need to be removed to + * accommodate the certificates to install. + * The certificates installed represent a full set of valid certificates needed to connect to + * AGPS SUPL servers. + * The list of certificates is required, and all must be available at the same time, when trying + * to establish a connection with the AGPS Server. + * + * Parameters: + * certificates - A pointer to an array of DER encoded certificates that are need to be + * installed in the HAL. + * length - The number of certificates to install. + * Returns: + * LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully + * LOC_AGPS_CERTIFICATE_ERROR_TOO_MANY_CERTIFICATES if the HAL cannot store the number of + * certificates attempted to be installed, the state of the certificates stored should + * remain the same as before on this error case. + * + * IMPORTANT: + * If needed the HAL should find out internally the set of certificates that need to be + * removed to accommodate the certificates to install. + */ + int (*install_certificates) ( const LocDerEncodedCertificate* certificates, size_t length ); + + /** + * Notifies the HAL that a list of certificates used for SUPL connections are revoked. It is + * expected that the given set of certificates is removed from the internal store of the HAL. + * + * Parameters: + * fingerprints - A pointer to an array of SHA1 Fingerprints to identify the set of + * certificates to revoke. + * length - The number of fingerprints provided. + * Returns: + * LOC_AGPS_CERTIFICATE_OPERATION_SUCCESS if the operation is completed successfully. + * + * IMPORTANT: + * If any of the certificates provided (through its fingerprint) is not known by the HAL, + * it should be ignored and continue revoking/deleting the rest of them. + */ + int (*revoke_certificates) ( const LocSha1CertificateFingerprint* fingerprints, size_t length ); +} LocSuplCertificateInterface; + +/** Represents an NI request */ +typedef struct { + /** set to sizeof(LocGpsNiNotification) */ + size_t size; + + /** + * An ID generated by HAL to associate NI notifications and UI + * responses + */ + int notification_id; + + /** + * An NI type used to distinguish different categories of NI + * events, such as LOC_GPS_NI_TYPE_VOICE, LOC_GPS_NI_TYPE_UMTS_SUPL, ... + */ + LocGpsNiType ni_type; + + /** + * Notification/verification options, combinations of LocGpsNiNotifyFlags constants + */ + LocGpsNiNotifyFlags notify_flags; + + /** + * Timeout period to wait for user response. + * Set to 0 for no time out limit. + */ + int timeout; + + /** + * Default response when time out. + */ + LocGpsUserResponseType default_response; + + /** + * Requestor ID + */ + char requestor_id[LOC_GPS_NI_SHORT_STRING_MAXLEN]; + + /** + * Notification message. It can also be used to store client_id in some cases + */ + char text[LOC_GPS_NI_LONG_STRING_MAXLEN]; + + /** + * Client name decoding scheme + */ + LocGpsNiEncodingType requestor_id_encoding; + + /** + * Client name decoding scheme + */ + LocGpsNiEncodingType text_encoding; + + /** + * A pointer to extra data. Format: + * key_1 = value_1 + * key_2 = value_2 + */ + char extras[LOC_GPS_NI_LONG_STRING_MAXLEN]; + +} LocGpsNiNotification; + +/** + * Callback with NI notification. Can only be called from a thread created by + * create_thread_cb. + */ +typedef void (*loc_gps_ni_notify_callback)(LocGpsNiNotification *notification); + +/** GPS NI callback structure. */ +typedef struct +{ + /** + * Sends the notification request from HAL to GPSLocationProvider. + */ + loc_gps_ni_notify_callback notify_cb; + loc_gps_create_thread create_thread_cb; +} LocGpsNiCallbacks; + +/** + * Extended interface for Network-initiated (NI) support. + */ +typedef struct +{ + /** set to sizeof(LocGpsNiInterface) */ + size_t size; + + /** Registers the callbacks for HAL to use. */ + void (*init) (LocGpsNiCallbacks *callbacks); + + /** Sends a response to HAL. */ + void (*respond) (int notif_id, LocGpsUserResponseType user_response); +} LocGpsNiInterface; + +#define LOC_AGPS_RIL_REQUEST_SETID_IMSI (1<<0L) +#define LOC_AGPS_RIL_REQUEST_SETID_MSISDN (1<<1L) + +#define LOC_AGPS_RIL_REQUEST_REFLOC_CELLID (1<<0L) +#define LOC_AGPS_RIL_REQUEST_REFLOC_MAC (1<<1L) + +typedef void (*loc_agps_ril_request_set_id)(uint32_t flags); +typedef void (*loc_agps_ril_request_ref_loc)(uint32_t flags); + +typedef struct { + loc_agps_ril_request_set_id request_setid; + loc_agps_ril_request_ref_loc request_refloc; + loc_gps_create_thread create_thread_cb; +} LocAGpsRilCallbacks; + +/** Extended interface for AGPS_RIL support. */ +typedef struct { + /** set to sizeof(LocAGpsRilInterface) */ + size_t size; + /** + * Opens the AGPS interface and provides the callback routines + * to the implementation of this interface. + */ + void (*init)( LocAGpsRilCallbacks* callbacks ); + + /** + * Sets the reference location. + */ + void (*set_ref_location) (const LocAGpsRefLocation *agps_reflocation, size_t sz_struct); + /** + * Sets the set ID. + */ + void (*set_set_id) (LocAGpsSetIDType type, const char* setid); + + /** + * Send network initiated message. + */ + void (*ni_message) (uint8_t *msg, size_t len); + + /** + * Notify GPS of network status changes. + * These parameters match values in the android.net.NetworkInfo class. + */ + void (*update_network_state) (int connected, int type, int roaming, const char* extra_info); + + /** + * Notify GPS of network status changes. + * These parameters match values in the android.net.NetworkInfo class. + */ + void (*update_network_availability) (int avaiable, const char* apn); +} LocAGpsRilInterface; + +/** + * GPS Geofence. + * There are 3 states associated with a Geofence: Inside, Outside, Unknown. + * There are 3 transitions: ENTERED, EXITED, UNCERTAIN. + * + * An example state diagram with confidence level: 95% and Unknown time limit + * set as 30 secs is shown below. (confidence level and Unknown time limit are + * explained latter) + * ____________________________ + * | Unknown (30 secs) | + * """""""""""""""""""""""""""" + * ^ | | ^ + * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN + * | v v | + * ________ EXITED _________ + * | Inside | -----------> | Outside | + * | | <----------- | | + * """""""" ENTERED """"""""" + * + * Inside state: We are 95% confident that the user is inside the geofence. + * Outside state: We are 95% confident that the user is outside the geofence + * Unknown state: Rest of the time. + * + * The Unknown state is better explained with an example: + * + * __________ + * | c| + * | ___ | _______ + * | |a| | | b | + * | """ | """"""" + * | | + * """""""""" + * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy + * circle reported by the GPS subsystem. Now with regard to "b", the system is + * confident that the user is outside. But with regard to "a" is not confident + * whether it is inside or outside the geofence. If the accuracy remains the + * same for a sufficient period of time, the UNCERTAIN transition would be + * triggered with the state set to Unknown. If the accuracy improves later, an + * appropriate transition should be triggered. This "sufficient period of time" + * is defined by the parameter in the add_geofence_area API. + * In other words, Unknown state can be interpreted as a state in which the + * GPS subsystem isn't confident enough that the user is either inside or + * outside the Geofence. It moves to Unknown state only after the expiry of the + * timeout. + * + * The geofence callback needs to be triggered for the ENTERED and EXITED + * transitions, when the GPS system is confident that the user has entered + * (Inside state) or exited (Outside state) the Geofence. An implementation + * which uses a value of 95% as the confidence is recommended. The callback + * should be triggered only for the transitions requested by the + * add_geofence_area call. + * + * Even though the diagram and explanation talks about states and transitions, + * the callee is only interested in the transistions. The states are mentioned + * here for illustrative purposes. + * + * Startup Scenario: When the device boots up, if an application adds geofences, + * and then we get an accurate GPS location fix, it needs to trigger the + * appropriate (ENTERED or EXITED) transition for every Geofence it knows about. + * By default, all the Geofences will be in the Unknown state. + * + * When the GPS system is unavailable, loc_gps_geofence_status_callback should be + * called to inform the upper layers of the same. Similarly, when it becomes + * available the callback should be called. This is a global state while the + * UNKNOWN transition described above is per geofence. + * + * An important aspect to note is that users of this API (framework), will use + * other subsystems like wifi, sensors, cell to handle Unknown case and + * hopefully provide a definitive state transition to the third party + * application. GPS Geofence will just be a signal indicating what the GPS + * subsystem knows about the Geofence. + * + */ +#define LOC_GPS_GEOFENCE_ENTERED (1<<0L) +#define LOC_GPS_GEOFENCE_EXITED (1<<1L) +#define LOC_GPS_GEOFENCE_UNCERTAIN (1<<2L) + +#define LOC_GPS_GEOFENCE_UNAVAILABLE (1<<0L) +#define LOC_GPS_GEOFENCE_AVAILABLE (1<<1L) + +#define LOC_GPS_GEOFENCE_OPERATION_SUCCESS 0 +#define LOC_GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100 +#define LOC_GPS_GEOFENCE_ERROR_ID_EXISTS -101 +#define LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN -102 +#define LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103 +#define LOC_GPS_GEOFENCE_ERROR_GENERIC -149 + +/** + * The callback associated with the geofence. + * Parameters: + * geofence_id - The id associated with the add_geofence_area. + * location - The current GPS location. + * transition - Can be one of LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED, + * LOC_GPS_GEOFENCE_UNCERTAIN. + * timestamp - Timestamp when the transition was detected. + * + * The callback should only be called when the caller is interested in that + * particular transition. For instance, if the caller is interested only in + * ENTERED transition, then the callback should NOT be called with the EXITED + * transition. + * + * IMPORTANT: If a transition is triggered resulting in this callback, the GPS + * subsystem will wake up the application processor, if its in suspend state. + */ +typedef void (*loc_gps_geofence_transition_callback) (int32_t geofence_id, LocGpsLocation* location, + int32_t transition, LocGpsUtcTime timestamp); + +/** + * The callback associated with the availability of the GPS system for geofencing + * monitoring. If the GPS system determines that it cannot monitor geofences + * because of lack of reliability or unavailability of the GPS signals, it will + * call this callback with LOC_GPS_GEOFENCE_UNAVAILABLE parameter. + * + * Parameters: + * status - LOC_GPS_GEOFENCE_UNAVAILABLE or LOC_GPS_GEOFENCE_AVAILABLE. + * last_location - Last known location. + */ +typedef void (*loc_gps_geofence_status_callback) (int32_t status, LocGpsLocation* last_location); + +/** + * The callback associated with the add_geofence call. + * + * Parameter: + * geofence_id - Id of the geofence. + * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS + * LOC_GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached. + * LOC_GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists + * LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an + * invalid transition + * LOC_GPS_GEOFENCE_ERROR_GENERIC - for other errors. + */ +typedef void (*loc_gps_geofence_add_callback) (int32_t geofence_id, int32_t status); + +/** + * The callback associated with the remove_geofence call. + * + * Parameter: + * geofence_id - Id of the geofence. + * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS + * LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id + * LOC_GPS_GEOFENCE_ERROR_GENERIC for others. + */ +typedef void (*loc_gps_geofence_remove_callback) (int32_t geofence_id, int32_t status); + + +/** + * The callback associated with the pause_geofence call. + * + * Parameter: + * geofence_id - Id of the geofence. + * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS + * LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id + * LOC_GPS_GEOFENCE_ERROR_INVALID_TRANSITION - + * when monitor_transitions is invalid + * LOC_GPS_GEOFENCE_ERROR_GENERIC for others. + */ +typedef void (*loc_gps_geofence_pause_callback) (int32_t geofence_id, int32_t status); + +/** + * The callback associated with the resume_geofence call. + * + * Parameter: + * geofence_id - Id of the geofence. + * status - LOC_GPS_GEOFENCE_OPERATION_SUCCESS + * LOC_GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id + * LOC_GPS_GEOFENCE_ERROR_GENERIC for others. + */ +typedef void (*loc_gps_geofence_resume_callback) (int32_t geofence_id, int32_t status); + +typedef struct { + loc_gps_geofence_transition_callback geofence_transition_callback; + loc_gps_geofence_status_callback geofence_status_callback; + loc_gps_geofence_add_callback geofence_add_callback; + loc_gps_geofence_remove_callback geofence_remove_callback; + loc_gps_geofence_pause_callback geofence_pause_callback; + loc_gps_geofence_resume_callback geofence_resume_callback; + loc_gps_create_thread create_thread_cb; +} LocGpsGeofenceCallbacks; + +/** Extended interface for GPS_Geofencing support */ +typedef struct { + /** set to sizeof(LocGpsGeofencingInterface) */ + size_t size; + + /** + * Opens the geofence interface and provides the callback routines + * to the implementation of this interface. + */ + void (*init)( LocGpsGeofenceCallbacks* callbacks ); + + /** + * Add a geofence area. This api currently supports circular geofences. + * Parameters: + * geofence_id - The id for the geofence. If a geofence with this id + * already exists, an error value (LOC_GPS_GEOFENCE_ERROR_ID_EXISTS) + * should be returned. + * latitude, longtitude, radius_meters - The lat, long and radius + * (in meters) for the geofence + * last_transition - The current state of the geofence. For example, if + * the system already knows that the user is inside the geofence, + * this will be set to LOC_GPS_GEOFENCE_ENTERED. In most cases, it + * will be LOC_GPS_GEOFENCE_UNCERTAIN. + * monitor_transition - Which transitions to monitor. Bitwise OR of + * LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED and + * LOC_GPS_GEOFENCE_UNCERTAIN. + * notification_responsiveness_ms - Defines the best-effort description + * of how soon should the callback be called when the transition + * associated with the Geofence is triggered. For instance, if set + * to 1000 millseconds with LOC_GPS_GEOFENCE_ENTERED, the callback + * should be called 1000 milliseconds within entering the geofence. + * This parameter is defined in milliseconds. + * NOTE: This is not to be confused with the rate that the GPS is + * polled at. It is acceptable to dynamically vary the rate of + * sampling the GPS for power-saving reasons; thus the rate of + * sampling may be faster or slower than this. + * unknown_timer_ms - The time limit after which the UNCERTAIN transition + * should be triggered. This parameter is defined in milliseconds. + * See above for a detailed explanation. + */ + void (*add_geofence_area) (int32_t geofence_id, double latitude, double longitude, + double radius_meters, int last_transition, int monitor_transitions, + int notification_responsiveness_ms, int unknown_timer_ms); + + /** + * Pause monitoring a particular geofence. + * Parameters: + * geofence_id - The id for the geofence. + */ + void (*pause_geofence) (int32_t geofence_id); + + /** + * Resume monitoring a particular geofence. + * Parameters: + * geofence_id - The id for the geofence. + * monitor_transitions - Which transitions to monitor. Bitwise OR of + * LOC_GPS_GEOFENCE_ENTERED, LOC_GPS_GEOFENCE_EXITED and + * LOC_GPS_GEOFENCE_UNCERTAIN. + * This supersedes the value associated provided in the + * add_geofence_area call. + */ + void (*resume_geofence) (int32_t geofence_id, int monitor_transitions); + + /** + * Remove a geofence area. After the function returns, no notifications + * should be sent. + * Parameter: + * geofence_id - The id for the geofence. + */ + void (*remove_geofence_area) (int32_t geofence_id); +} LocGpsGeofencingInterface; + +/** + * Legacy struct to represent an estimate of the GPS clock time. + * Deprecated, to be removed in the next Android release. + * Use LocGnssClock instead. + */ +typedef struct { + /** set to sizeof(LocGpsClock) */ + size_t size; + LocGpsClockFlags flags; + int16_t leap_second; + LocGpsClockType type; + int64_t time_ns; + double time_uncertainty_ns; + int64_t full_bias_ns; + double bias_ns; + double bias_uncertainty_ns; + double drift_nsps; + double drift_uncertainty_nsps; +} LocGpsClock; + +/** + * Represents an estimate of the GPS clock time. + */ +typedef struct { + /** set to sizeof(LocGnssClock) */ + size_t size; + + /** + * A set of flags indicating the validity of the fields in this data + * structure. + */ + LocGnssClockFlags flags; + + /** + * Leap second data. + * The sign of the value is defined by the following equation: + * utc_time_ns = time_ns - (full_bias_ns + bias_ns) - leap_second * + * 1,000,000,000 + * + * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_LEAP_SECOND. + */ + int16_t leap_second; + + /** + * The GNSS receiver internal clock value. This is the local hardware clock + * value. + * + * For local hardware clock, this value is expected to be monotonically + * increasing while the hardware clock remains power on. (For the case of a + * HW clock that is not continuously on, see the + * hw_clock_discontinuity_count field). The receiver's estimate of GPS time + * can be derived by substracting the sum of full_bias_ns and bias_ns (when + * available) from this value. + * + * This GPS time is expected to be the best estimate of current GPS time + * that GNSS receiver can achieve. + * + * Sub-nanosecond accuracy can be provided by means of the 'bias_ns' field. + * The value contains the 'time uncertainty' in it. + * + * This field is mandatory. + */ + int64_t time_ns; + + /** + * 1-Sigma uncertainty associated with the clock's time in nanoseconds. + * The uncertainty is represented as an absolute (single sided) value. + * + * If the data is available, 'flags' must contain + * LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY. This value is effectively zero (it is + * the reference local clock, by which all other times and time + * uncertainties are measured.) (And thus this field can be not provided, + * per LOC_GNSS_CLOCK_HAS_TIME_UNCERTAINTY flag, or provided & set to 0.) + */ + double time_uncertainty_ns; + + /** + * The difference between hardware clock ('time' field) inside GPS receiver + * and the true GPS time since 0000Z, January 6, 1980, in nanoseconds. + * + * The sign of the value is defined by the following equation: + * local estimate of GPS time = time_ns - (full_bias_ns + bias_ns) + * + * This value is mandatory if the receiver has estimated GPS time. If the + * computed time is for a non-GPS constellation, the time offset of that + * constellation to GPS has to be applied to fill this value. The error + * estimate for the sum of this and the bias_ns is the bias_uncertainty_ns, + * and the caller is responsible for using this uncertainty (it can be very + * large before the GPS time has been solved for.) If the data is available + * 'flags' must contain LOC_GNSS_CLOCK_HAS_FULL_BIAS. + */ + int64_t full_bias_ns; + + /** + * Sub-nanosecond bias. + * The error estimate for the sum of this and the full_bias_ns is the + * bias_uncertainty_ns + * + * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_BIAS. If GPS + * has computed a position fix. This value is mandatory if the receiver has + * estimated GPS time. + */ + double bias_ns; + + /** + * 1-Sigma uncertainty associated with the local estimate of GPS time (clock + * bias) in nanoseconds. The uncertainty is represented as an absolute + * (single sided) value. + * + * If the data is available 'flags' must contain + * LOC_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY. This value is mandatory if the receiver + * has estimated GPS time. + */ + double bias_uncertainty_ns; + + /** + * The clock's drift in nanoseconds (per second). + * + * A positive value means that the frequency is higher than the nominal + * frequency, and that the (full_bias_ns + bias_ns) is growing more positive + * over time. + * + * The value contains the 'drift uncertainty' in it. + * If the data is available 'flags' must contain LOC_GNSS_CLOCK_HAS_DRIFT. + * + * This value is mandatory if the receiver has estimated GNSS time + */ + double drift_nsps; + + /** + * 1-Sigma uncertainty associated with the clock's drift in nanoseconds (per second). + * The uncertainty is represented as an absolute (single sided) value. + * + * If the data is available 'flags' must contain + * LOC_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY. If GPS has computed a position fix this + * field is mandatory and must be populated. + */ + double drift_uncertainty_nsps; + + /** + * When there are any discontinuities in the HW clock, this field is + * mandatory. + * + * A "discontinuity" is meant to cover the case of a switch from one source + * of clock to another. A single free-running crystal oscillator (XO) + * should generally not have any discontinuities, and this can be set and + * left at 0. + * + * If, however, the time_ns value (HW clock) is derived from a composite of + * sources, that is not as smooth as a typical XO, or is otherwise stopped & + * restarted, then this value shall be incremented each time a discontinuity + * occurs. (E.g. this value may start at zero at device boot-up and + * increment each time there is a change in clock continuity. In the + * unlikely event that this value reaches full scale, rollover (not + * clamping) is required, such that this value continues to change, during + * subsequent discontinuity events.) + * + * While this number stays the same, between LocGnssClock reports, it can be + * safely assumed that the time_ns value has been running continuously, e.g. + * derived from a single, high quality clock (XO like, or better, that's + * typically used during continuous GNSS signal sampling.) + * + * It is expected, esp. during periods where there are few GNSS signals + * available, that the HW clock be discontinuity-free as long as possible, + * as this avoids the need to use (waste) a GNSS measurement to fully + * re-solve for the GPS clock bias and drift, when using the accompanying + * measurements, from consecutive LocGnssData reports. + */ + uint32_t hw_clock_discontinuity_count; + +} LocGnssClock; + +/** + * Legacy struct to represent a GPS Measurement, it contains raw and computed + * information. + * Deprecated, to be removed in the next Android release. + * Use LocGnssMeasurement instead. + */ +typedef struct { + /** set to sizeof(LocGpsMeasurement) */ + size_t size; + LocGpsMeasurementFlags flags; + int8_t prn; + double time_offset_ns; + LocGpsMeasurementState state; + int64_t received_gps_tow_ns; + int64_t received_gps_tow_uncertainty_ns; + double c_n0_dbhz; + double pseudorange_rate_mps; + double pseudorange_rate_uncertainty_mps; + LocGpsAccumulatedDeltaRangeState accumulated_delta_range_state; + double accumulated_delta_range_m; + double accumulated_delta_range_uncertainty_m; + double pseudorange_m; + double pseudorange_uncertainty_m; + double code_phase_chips; + double code_phase_uncertainty_chips; + float carrier_frequency_hz; + int64_t carrier_cycles; + double carrier_phase; + double carrier_phase_uncertainty; + LocGpsLossOfLock loss_of_lock; + int32_t bit_number; + int16_t time_from_last_bit_ms; + double doppler_shift_hz; + double doppler_shift_uncertainty_hz; + LocGpsMultipathIndicator multipath_indicator; + double snr_db; + double elevation_deg; + double elevation_uncertainty_deg; + double azimuth_deg; + double azimuth_uncertainty_deg; + bool used_in_fix; +} LocGpsMeasurement; + +/** + * Represents a GNSS Measurement, it contains raw and computed information. + * + * Independence - All signal measurement information (e.g. sv_time, + * pseudorange_rate, multipath_indicator) reported in this struct should be + * based on GNSS signal measurements only. You may not synthesize measurements + * by calculating or reporting expected measurements based on known or estimated + * position, velocity, or time. + */ +typedef struct { + /** set to sizeof(LocGnssMeasurement) */ + size_t size; + + /** A set of flags indicating the validity of the fields in this data structure. */ + LocGnssMeasurementFlags flags; + + /** + * Satellite vehicle ID number, as defined in LocGnssSvInfo::svid + * This is a mandatory value. + */ + int16_t svid; + + /** + * Defines the constellation of the given SV. Value should be one of those + * LOC_GNSS_CONSTELLATION_* constants + */ + LocGnssConstellationType constellation; + + /** + * Time offset at which the measurement was taken in nanoseconds. + * The reference receiver's time is specified by LocGpsData::clock::time_ns and should be + * interpreted in the same way as indicated by LocGpsClock::type. + * + * The sign of time_offset_ns is given by the following equation: + * measurement time = LocGpsClock::time_ns + time_offset_ns + * + * It provides an individual time-stamp for the measurement, and allows sub-nanosecond accuracy. + * This is a mandatory value. + */ + double time_offset_ns; + + /** + * Per satellite sync state. It represents the current sync state for the associated satellite. + * Based on the sync state, the 'received GPS tow' field should be interpreted accordingly. + * + * This is a mandatory value. + */ + LocGnssMeasurementState state; + + /** + * The received GNSS Time-of-Week at the measurement time, in nanoseconds. + * Ensure that this field is independent (see comment at top of + * LocGnssMeasurement struct.) + * + * For GPS & QZSS, this is: + * Received GPS Time-of-Week at the measurement time, in nanoseconds. + * The value is relative to the beginning of the current GPS week. + * + * Given the highest sync state that can be achieved, per each satellite, valid range + * for this field can be: + * Searching : [ 0 ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN + * C/A code lock : [ 0 1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set + * Bit sync : [ 0 20ms ] : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set + * Subframe sync : [ 0 6s ] : LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set + * TOW decoded : [ 0 1week ] : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set + * + * Note well: if there is any ambiguity in integer millisecond, + * LOC_GNSS_MEASUREMENT_STATE_MSEC_AMBIGUOUS should be set accordingly, in the 'state' field. + * + * This value must be populated if 'state' != LOC_GNSS_MEASUREMENT_STATE_UNKNOWN. + * + * For Glonass, this is: + * Received Glonass time of day, at the measurement time in nanoseconds. + * + * Given the highest sync state that can be achieved, per each satellite, valid range for + * this field can be: + * Searching : [ 0 ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN + * C/A code lock : [ 0 1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set + * Symbol sync : [ 0 10ms ] : LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set + * Bit sync : [ 0 20ms ] : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set + * String sync : [ 0 2s ] : LOC_GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC is set + * Time of day : [ 0 1day ] : LOC_GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED is set + * + * For Beidou, this is: + * Received Beidou time of week, at the measurement time in nanoseconds. + * + * Given the highest sync state that can be achieved, per each satellite, valid range for + * this field can be: + * Searching : [ 0 ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN + * C/A code lock: [ 0 1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set + * Bit sync (D2): [ 0 2ms ] : LOC_GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC is set + * Bit sync (D1): [ 0 20ms ] : LOC_GNSS_MEASUREMENT_STATE_BIT_SYNC is set + * Subframe (D2): [ 0 0.6s ] : LOC_GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC is set + * Subframe (D1): [ 0 6s ] : LOC_GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC is set + * Time of week : [ 0 1week ] : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set + * + * For Galileo, this is: + * Received Galileo time of week, at the measurement time in nanoseconds. + * + * E1BC code lock : [ 0 4ms ] : LOC_GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK is set + * E1C 2nd code lock: [ 0 100ms ] : + * LOC_GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK is set + * + * E1B page : [ 0 2s ] : LOC_GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC is set + * Time of week: [ 0 1week ] : LOC_GNSS_MEASUREMENT_STATE_TOW_DECODED is set + * + * For SBAS, this is: + * Received SBAS time, at the measurement time in nanoseconds. + * + * Given the highest sync state that can be achieved, per each satellite, + * valid range for this field can be: + * Searching : [ 0 ] : LOC_GNSS_MEASUREMENT_STATE_UNKNOWN + * C/A code lock: [ 0 1ms ] : LOC_GNSS_MEASUREMENT_STATE_CODE_LOCK is set + * Symbol sync : [ 0 2ms ] : LOC_GNSS_MEASUREMENT_STATE_SYMBOL_SYNC is set + * Message : [ 0 1s ] : LOC_GNSS_MEASUREMENT_STATE_SBAS_SYNC is set + */ + int64_t received_sv_time_in_ns; + + /** + * 1-Sigma uncertainty of the Received GPS Time-of-Week in nanoseconds. + * + * This value must be populated if 'state' != LOC_GPS_MEASUREMENT_STATE_UNKNOWN. + */ + int64_t received_sv_time_uncertainty_in_ns; + + /** + * Carrier-to-noise density in dB-Hz, typically in the range [0, 63]. + * It contains the measured C/N0 value for the signal at the antenna port. + * + * This is a mandatory value. + */ + double c_n0_dbhz; + + /** + * Pseudorange rate at the timestamp in m/s. The correction of a given + * Pseudorange Rate value includes corrections for receiver and satellite + * clock frequency errors. Ensure that this field is independent (see + * comment at top of LocGnssMeasurement struct.) + * + * It is mandatory to provide the 'uncorrected' 'pseudorange rate', and provide LocGpsClock's + * 'drift' field as well (When providing the uncorrected pseudorange rate, do not apply the + * corrections described above.) + * + * The value includes the 'pseudorange rate uncertainty' in it. + * A positive 'uncorrected' value indicates that the SV is moving away from the receiver. + * + * The sign of the 'uncorrected' 'pseudorange rate' and its relation to the sign of 'doppler + * shift' is given by the equation: + * pseudorange rate = -k * doppler shift (where k is a constant) + * + * This should be the most accurate pseudorange rate available, based on + * fresh signal measurements from this channel. + * + * It is mandatory that this value be provided at typical carrier phase PRR + * quality (few cm/sec per second of uncertainty, or better) - when signals + * are sufficiently strong & stable, e.g. signals from a GPS simulator at >= + * 35 dB-Hz. + */ + double pseudorange_rate_mps; + + /** + * 1-Sigma uncertainty of the pseudorange_rate_mps. + * The uncertainty is represented as an absolute (single sided) value. + * + * This is a mandatory value. + */ + double pseudorange_rate_uncertainty_mps; + + /** + * Accumulated delta range's state. It indicates whether ADR is reset or there is a cycle slip + * (indicating loss of lock). + * + * This is a mandatory value. + */ + LocGnssAccumulatedDeltaRangeState accumulated_delta_range_state; + + /** + * Accumulated delta range since the last channel reset in meters. + * A positive value indicates that the SV is moving away from the receiver. + * + * The sign of the 'accumulated delta range' and its relation to the sign of 'carrier phase' + * is given by the equation: + * accumulated delta range = -k * carrier phase (where k is a constant) + * + * This value must be populated if 'accumulated delta range state' != LOC_GPS_ADR_STATE_UNKNOWN. + * However, it is expected that the data is only accurate when: + * 'accumulated delta range state' == LOC_GPS_ADR_STATE_VALID. + */ + double accumulated_delta_range_m; + + /** + * 1-Sigma uncertainty of the accumulated delta range in meters. + * This value must be populated if 'accumulated delta range state' != LOC_GPS_ADR_STATE_UNKNOWN. + */ + double accumulated_delta_range_uncertainty_m; + + /** + * Carrier frequency at which codes and messages are modulated, it can be L1 or L2. + * If the field is not set, the carrier frequency is assumed to be L1. + * + * If the data is available, 'flags' must contain + * LOC_GNSS_MEASUREMENT_HAS_CARRIER_FREQUENCY. + */ + float carrier_frequency_hz; + + /** + * The number of full carrier cycles between the satellite and the receiver. + * The reference frequency is given by the field 'carrier_frequency_hz'. + * Indications of possible cycle slips and resets in the accumulation of + * this value can be inferred from the accumulated_delta_range_state flags. + * + * If the data is available, 'flags' must contain + * LOC_GNSS_MEASUREMENT_HAS_CARRIER_CYCLES. + */ + int64_t carrier_cycles; + + /** + * The RF phase detected by the receiver, in the range [0.0, 1.0]. + * This is usually the fractional part of the complete carrier phase measurement. + * + * The reference frequency is given by the field 'carrier_frequency_hz'. + * The value contains the 'carrier-phase uncertainty' in it. + * + * If the data is available, 'flags' must contain + * LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE. + */ + double carrier_phase; + + /** + * 1-Sigma uncertainty of the carrier-phase. + * If the data is available, 'flags' must contain + * LOC_GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY. + */ + double carrier_phase_uncertainty; + + /** + * An enumeration that indicates the 'multipath' state of the event. + * + * The multipath Indicator is intended to report the presence of overlapping + * signals that manifest as distorted correlation peaks. + * + * - if there is a distorted correlation peak shape, report that multipath + * is LOC_GNSS_MULTIPATH_INDICATOR_PRESENT. + * - if there is not a distorted correlation peak shape, report + * LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT + * - if signals are too weak to discern this information, report + * LOC_GNSS_MULTIPATH_INDICATOR_UNKNOWN + * + * Example: when doing the standardized overlapping Multipath Performance + * test (3GPP TS 34.171) the Multipath indicator should report + * LOC_GNSS_MULTIPATH_INDICATOR_PRESENT for those signals that are tracked, and + * contain multipath, and LOC_GNSS_MULTIPATH_INDICATOR_NOT_PRESENT for those + * signals that are tracked and do not contain multipath. + */ + LocGnssMultipathIndicator multipath_indicator; + + /** + * Signal-to-noise ratio at correlator output in dB. + * If the data is available, 'flags' must contain LOC_GNSS_MEASUREMENT_HAS_SNR. + * This is the power ratio of the "correlation peak height above the + * observed noise floor" to "the noise RMS". + */ + double snr_db; +} LocGnssMeasurement; + +/** + * Legacy struct to represents a reading of GPS measurements. + * Deprecated, to be removed in the next Android release. + * Use LocGnssData instead. + */ +typedef struct { + /** set to sizeof(LocGpsData) */ + size_t size; + size_t measurement_count; + LocGpsMeasurement measurements[LOC_GPS_MAX_MEASUREMENT]; + + /** The GPS clock time reading. */ + LocGpsClock clock; +} LocGpsData; + +/** + * Represents a reading of GNSS measurements. For devices where LocGnssSystemInfo's + * year_of_hw is set to 2016+, it is mandatory that these be provided, on + * request, when the GNSS receiver is searching/tracking signals. + * + * - Reporting of GPS constellation measurements is mandatory. + * - Reporting of all tracked constellations are encouraged. + */ +typedef struct { + /** set to sizeof(LocGnssData) */ + size_t size; + + /** Number of measurements. */ + size_t measurement_count; + + /** The array of measurements. */ + LocGnssMeasurement measurements[LOC_GNSS_MAX_MEASUREMENT]; + + /** The GPS clock time reading. */ + LocGnssClock clock; +} LocGnssData; + +/** + * The legacy callback for to report measurements from the HAL. + * + * This callback is deprecated, and will be removed in the next release. Use + * loc_gnss_measurement_callback() instead. + * + * Parameters: + * data - A data structure containing the measurements. + */ +typedef void (*loc_gps_measurement_callback) (LocGpsData* data); + +/** + * The callback for to report measurements from the HAL. + * + * Parameters: + * data - A data structure containing the measurements. + */ +typedef void (*loc_gnss_measurement_callback) (LocGnssData* data); + +typedef struct { + /** set to sizeof(LocGpsMeasurementCallbacks) */ + size_t size; + loc_gps_measurement_callback measurement_callback; + loc_gnss_measurement_callback loc_gnss_measurement_callback; +} LocGpsMeasurementCallbacks; + +#define LOC_GPS_MEASUREMENT_OPERATION_SUCCESS 0 +#define LOC_GPS_MEASUREMENT_ERROR_ALREADY_INIT -100 +#define LOC_GPS_MEASUREMENT_ERROR_GENERIC -101 + +/** + * Extended interface for GPS Measurements support. + */ +typedef struct { + /** Set to sizeof(LocGpsMeasurementInterface) */ + size_t size; + + /** + * Initializes the interface and registers the callback routines with the HAL. + * After a successful call to 'init' the HAL must begin to provide updates at its own phase. + * + * Status: + * LOC_GPS_MEASUREMENT_OPERATION_SUCCESS + * LOC_GPS_MEASUREMENT_ERROR_ALREADY_INIT - if a callback has already been registered without a + * corresponding call to 'close' + * LOC_GPS_MEASUREMENT_ERROR_GENERIC - if any other error occurred, it is expected that the HAL + * will not generate any updates upon returning this error code. + */ + int (*init) (LocGpsMeasurementCallbacks* callbacks); + + /** + * Stops updates from the HAL, and unregisters the callback routines. + * After a call to stop, the previously registered callbacks must be considered invalid by the + * HAL. + * If stop is invoked without a previous 'init', this function should perform no work. + */ + void (*close) (); + +} LocGpsMeasurementInterface; + +#if 0 +/** + * Legacy struct to represents a GPS navigation message (or a fragment of it). + * Deprecated, to be removed in the next Android release. + * Use GnssNavigationMessage instead. + */ +typedef struct { + /** set to sizeof(GpsNavigationMessage) */ + size_t size; + int8_t prn; + GpsNavigationMessageType type; + NavigationMessageStatus status; + int16_t message_id; + int16_t submessage_id; + size_t data_length; + uint8_t* data; +} GpsNavigationMessage; + +/** Represents a GPS navigation message (or a fragment of it). */ +typedef struct { + /** set to sizeof(GnssNavigationMessage) */ + size_t size; + + /** + * Satellite vehicle ID number, as defined in LocGnssSvInfo::svid + * This is a mandatory value. + */ + int16_t svid; + + /** + * The type of message contained in the structure. + * This is a mandatory value. + */ + GnssNavigationMessageType type; + + /** + * The status of the received navigation message. + * No need to send any navigation message that contains words with parity error and cannot be + * corrected. + */ + NavigationMessageStatus status; + + /** + * Message identifier. It provides an index so the complete Navigation + * Message can be assembled. + * + * - For GPS L1 C/A subframe 4 and 5, this value corresponds to the 'frame + * id' of the navigation message, in the range of 1-25 (Subframe 1, 2, 3 + * does not contain a 'frame id' and this value can be set to -1.) + * + * - For Glonass L1 C/A, this refers to the frame ID, in the range of 1-5. + * + * - For BeiDou D1, this refers to the frame number in the range of 1-24 + * + * - For Beidou D2, this refers to the frame number, in the range of 1-120 + * + * - For Galileo F/NAV nominal frame structure, this refers to the subframe + * number, in the range of 1-12 + * + * - For Galileo I/NAV nominal frame structure, this refers to the subframe + * number in the range of 1-24 + */ + int16_t message_id; + + /** + * Sub-message identifier. If required by the message 'type', this value + * contains a sub-index within the current message (or frame) that is being + * transmitted. + * + * - For GPS L1 C/A, BeiDou D1 & BeiDou D2, the submessage id corresponds to + * the subframe number of the navigation message, in the range of 1-5. + * + * - For Glonass L1 C/A, this refers to the String number, in the range from + * 1-15 + * + * - For Galileo F/NAV, this refers to the page type in the range 1-6 + * + * - For Galileo I/NAV, this refers to the word type in the range 1-10+ + */ + int16_t submessage_id; + + /** + * The length of the data (in bytes) contained in the current message. + * If this value is different from zero, 'data' must point to an array of the same size. + * e.g. for L1 C/A the size of the sub-frame will be 40 bytes (10 words, 30 bits/word). + * + * This is a mandatory value. + */ + size_t data_length; + + /** + * The data of the reported GPS message. The bytes (or words) specified + * using big endian format (MSB first). + * + * - For GPS L1 C/A, Beidou D1 & Beidou D2, each subframe contains 10 30-bit + * words. Each word (30 bits) should be fit into the last 30 bits in a + * 4-byte word (skip B31 and B32), with MSB first, for a total of 40 + * bytes, covering a time period of 6, 6, and 0.6 seconds, respectively. + * + * - For Glonass L1 C/A, each string contains 85 data bits, including the + * checksum. These bits should be fit into 11 bytes, with MSB first (skip + * B86-B88), covering a time period of 2 seconds. + * + * - For Galileo F/NAV, each word consists of 238-bit (sync & tail symbols + * excluded). Each word should be fit into 30-bytes, with MSB first (skip + * B239, B240), covering a time period of 10 seconds. + * + * - For Galileo I/NAV, each page contains 2 page parts, even and odd, with + * a total of 2x114 = 228 bits, (sync & tail excluded) that should be fit + * into 29 bytes, with MSB first (skip B229-B232). + */ + uint8_t* data; + +} GnssNavigationMessage; + +/** + * The legacy callback to report an available fragment of a GPS navigation + * messages from the HAL. + * + * This callback is deprecated, and will be removed in the next release. Use + * gnss_navigation_message_callback() instead. + * + * Parameters: + * message - The GPS navigation submessage/subframe representation. + */ +typedef void (*gps_navigation_message_callback) (GpsNavigationMessage* message); + +/** + * The callback to report an available fragment of a GPS navigation messages from the HAL. + * + * Parameters: + * message - The GPS navigation submessage/subframe representation. + */ +typedef void (*gnss_navigation_message_callback) (GnssNavigationMessage* message); + +typedef struct { + /** set to sizeof(GpsNavigationMessageCallbacks) */ + size_t size; + gps_navigation_message_callback navigation_message_callback; + gnss_navigation_message_callback gnss_navigation_message_callback; +} GpsNavigationMessageCallbacks; + +#define GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS 0 +#define GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT -100 +#define GPS_NAVIGATION_MESSAGE_ERROR_GENERIC -101 + +/** + * Extended interface for GPS navigation message reporting support. + */ +typedef struct { + /** Set to sizeof(GpsNavigationMessageInterface) */ + size_t size; + + /** + * Initializes the interface and registers the callback routines with the HAL. + * After a successful call to 'init' the HAL must begin to provide updates as they become + * available. + * + * Status: + * GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS + * GPS_NAVIGATION_MESSAGE_ERROR_ALREADY_INIT - if a callback has already been registered + * without a corresponding call to 'close'. + * GPS_NAVIGATION_MESSAGE_ERROR_GENERIC - if any other error occurred, it is expected that + * the HAL will not generate any updates upon returning this error code. + */ + int (*init) (GpsNavigationMessageCallbacks* callbacks); + + /** + * Stops updates from the HAL, and unregisters the callback routines. + * After a call to stop, the previously registered callbacks must be considered invalid by the + * HAL. + * If stop is invoked without a previous 'init', this function should perform no work. + */ + void (*close) (); + +} GpsNavigationMessageInterface; +#endif + +/** + * Interface for passing GNSS configuration contents from platform to HAL. + */ +typedef struct { + /** Set to sizeof(LocGnssConfigurationInterface) */ + size_t size; + + /** + * Deliver GNSS configuration contents to HAL. + * Parameters: + * config_data - a pointer to a char array which holds what usually is expected from + file(/vendor/etc/gps.conf), i.e., a sequence of UTF8 strings separated by '\n'. + * length - total number of UTF8 characters in configuraiton data. + * + * IMPORTANT: + * GPS HAL should expect this function can be called multiple times. And it may be + * called even when GpsLocationProvider is already constructed and enabled. GPS HAL + * should maintain the existing requests for various callback regardless the change + * in configuration data. + */ + void (*configuration_update) (const char* config_data, int32_t length); +} LocGnssConfigurationInterface; + +__END_DECLS + +#endif /* LOC_GPS_H */ + diff --git a/gps/utils/loc_log.cpp b/gps/utils/loc_log.cpp new file mode 100644 index 0000000..2110683 --- /dev/null +++ b/gps/utils/loc_log.cpp @@ -0,0 +1,282 @@ +/* Copyright (c) 2011-2012, 2015, 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 + +#include +#include +#include +#include +#include "log_util.h" +#include "loc_log.h" +#include "msg_q.h" +#include +#include "LogBuffer.h" +#include +#include +#include +#include +#include +#define BUFFER_SIZE 120 +#define LOG_TAG_LEVEL_CONF_FILE_PATH "/data/vendor/location/gps.prop" + +// Logging Improvements +const char *loc_logger_boolStr[]={"False","True"}; +const char VOID_RET[] = "None"; +const char FROM_AFW[] = "===>"; +const char TO_MODEM[] = "--->"; +const char FROM_MODEM[] = "<---"; +const char TO_AFW[] = "<==="; +const char EXIT_TAG[] = "Exiting"; +const char ENTRY_TAG[] = "Entering"; +const char EXIT_ERROR_TAG[] = "Exiting with error"; + +int build_type_prop = BUILD_TYPE_PROP_NA; + +const string gEmptyStr = ""; +const string gUnknownStr = "UNKNOWN"; +/* Logging Mechanism */ +loc_logger_s_type loc_logger; + +/* tag base logging control map*/ +static std::unordered_map tag_level_map; +static bool tag_map_inited = false; + +/* returns the least signification bit that is set in the mask + Param + mask - bit mask. + clearTheBit - if true, mask gets modified upon return. + returns 0 if mask is 0. +*/ +uint64_t loc_get_least_bit(uint64_t& mask, bool clearTheBit) { + uint64_t bit = 0; + + if (mask > 0) { + uint64_t less1 = mask - 1; + bit = mask & ~(less1); + if (clearTheBit) { + mask &= less1; + } + } + + return bit; +} + +string loc_get_bit_defs(uint64_t mask, const NameValTbl& tbl) { + string out; + while (mask > 0) { + out += loc_get_name_from_tbl(tbl, loc_get_least_bit(mask)); + if (mask > 0) { + out += " | "; + } + } + return out; +} + +DECLARE_TBL(loc_msg_q_status) = +{ + NAME_VAL( eMSG_Q_SUCCESS ), + NAME_VAL( eMSG_Q_FAILURE_GENERAL ), + NAME_VAL( eMSG_Q_INVALID_PARAMETER ), + NAME_VAL( eMSG_Q_INVALID_HANDLE ), + NAME_VAL( eMSG_Q_UNAVAILABLE_RESOURCE ), + NAME_VAL( eMSG_Q_INSUFFICIENT_BUFFER ) +}; + +/* Find msg_q status name */ +const char* loc_get_msg_q_status(int status) +{ + return loc_get_name_from_val(loc_msg_q_status_tbl, (int64_t) status); +} + +//Target names +DECLARE_TBL(target_name) = +{ + NAME_VAL(GNSS_NONE), + NAME_VAL(GNSS_MSM), + NAME_VAL(GNSS_GSS), + NAME_VAL(GNSS_MDM), + NAME_VAL(GNSS_AUTO), + NAME_VAL(GNSS_UNKNOWN) +}; + +/*=========================================================================== + +FUNCTION loc_get_target_name + +DESCRIPTION + Returns pointer to a string that contains name of the target + + XX:XX:XX.000\0 + +RETURN VALUE + The target name string + +===========================================================================*/ +const char *loc_get_target_name(unsigned int target) +{ + int64_t index = 0; + static char ret[BUFFER_SIZE]; + + snprintf(ret, sizeof(ret), " %s with%s SSC", + loc_get_name_from_val(target_name_tbl, getTargetGnssType(target)), + ((target & HAS_SSC) == HAS_SSC) ? gEmptyStr.c_str() : "out"); + + return ret; +} + + +/*=========================================================================== + +FUNCTION loc_get_time + +DESCRIPTION + Logs a callback event header. + The pointer time_string should point to a buffer of at least 13 bytes: + + XX:XX:XX.000\0 + +RETURN VALUE + The time string + +===========================================================================*/ +char *loc_get_time(char *time_string, size_t buf_size) +{ + struct timeval now; /* sec and usec */ + struct tm now_tm; /* broken-down time */ + char hms_string[80]; /* HH:MM:SS */ + + gettimeofday(&now, NULL); + localtime_r(&now.tv_sec, &now_tm); + + strftime(hms_string, sizeof hms_string, "%H:%M:%S", &now_tm); + snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_usec / 1000)); + + return time_string; +} + +/*=========================================================================== +FUNCTION get_timestamp + +DESCRIPTION + Generates a timestamp using the current system time + +DEPENDENCIES + N/A + +RETURN VALUE + Char pointer to the parameter str + +SIDE EFFECTS + N/A +===========================================================================*/ +char * get_timestamp(char *str, unsigned long buf_size) +{ + struct timeval tv; + struct timezone tz; + int hh, mm, ss; + gettimeofday(&tv, &tz); + hh = tv.tv_sec/3600%24; + mm = (tv.tv_sec%3600)/60; + ss = tv.tv_sec%60; + snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec); + return str; +} + +/*=========================================================================== + +FUNCTION log_buffer_insert + +DESCRIPTION + Insert a log sentence with specific level to the log buffer. + +RETURN VALUE + N/A + +===========================================================================*/ +void log_buffer_insert(char *str, unsigned long buf_size, int level) +{ + timespec tv; + clock_gettime(CLOCK_BOOTTIME, &tv); + uint64_t elapsedTime = (uint64_t)tv.tv_sec + (uint64_t)tv.tv_nsec/1000000000; + string ss = str; + loc_util::LogBuffer::getInstance()->append(ss, level, elapsedTime); +} + +void log_tag_level_map_init() +{ + if (tag_map_inited) { + return; + } + + std::string filename = LOG_TAG_LEVEL_CONF_FILE_PATH; + + std::ifstream s(filename); + if (!s.is_open()) { + ALOGE("cannot open file:%s", LOG_TAG_LEVEL_CONF_FILE_PATH); + } else { + std::string line; + while (std::getline(s, line)) { + line.erase(std::remove(line.begin(), line.end(), ' '), line.end()); + int pos = line.find('='); + if (pos <= 0 || pos >= (line.size() - 1)) { + ALOGE("wrong format in gps.prop"); + continue; + } + std::string tag = line.substr(0, pos); + std::string level = line.substr(pos+1, 1); + if (!std::isdigit(*(level.begin()))) { + ALOGE("wrong format in gps.prop"); + continue; + } + tag_level_map[tag] = (uint8_t)std::stoul(level); + } + } + tag_map_inited = true; +} + +int get_tag_log_level(const char* tag) +{ + if (!tag_map_inited) { + return -1; + } + + // in case LOG_TAG isn't defined in a source file, use the global log level + if (tag == NULL) { + return loc_logger.DEBUG_LEVEL; + } + int log_level; + auto search = tag_level_map.find(std::string(tag)); + if (tag_level_map.end() != search) { + log_level = search->second; + } else { + log_level = loc_logger.DEBUG_LEVEL; + } + return log_level; +} diff --git a/gps/utils/loc_log.h b/gps/utils/loc_log.h new file mode 100644 index 0000000..b750932 --- /dev/null +++ b/gps/utils/loc_log.h @@ -0,0 +1,122 @@ +/* Copyright (c) 2011-2012, 2015, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_LOG_H +#define LOC_LOG_H + +#include +#include +#include +#include +#include "loc_target.h" +#include "loc_misc_utils.h" + +using std::string; +using std::unordered_map; + +typedef unordered_map NameValTbl; + +#define NAME_VAL(x) {x, "" #x ""} +#define DECLARE_TBL(T) static const NameValTbl T##_tbl + +extern const string gEmptyStr; +extern const string gUnknownStr; + +#define CHECK_MASK(type, value, mask_var, mask) \ + (((mask_var) & (mask)) ? (type) (value) : (type) (-1)) + +#define LOC_TABLE_SIZE(table) (sizeof(table)/sizeof((table)[0])) + +#define FIELDVAL_DEC(field) \ + loc_put_tag_val(#field, to_string(field)) +#define FIELDVAL_DEC_ARR(field) \ + loc_put_tag_val(#field, \ + loc_parenthesize(loc_prim_arr_to_string(field, \ + sizeof(field)/sizeof(field[0])))) +#define FIELDVAL_HEX(field) \ + loc_put_tag_val(#field, to_string_hex(field)) +#define FIELDVAL_HEX_ARR(field) \ + loc_put_tag_val(#field, \ + loc_parenthesize(loc_prim_arr_to_string(field, \ + sizeof(field)/sizeof(field[0]), \ + false))) +#define FIELDVAL_ENUM(field, tbl) \ + loc_put_tag_val(#field, \ + loc_get_name_from_tbl(tbl, field, gUnknownStr)) +#define FIELDVAL_MASK(field, tbl) \ + loc_put_tag_val(#field, \ + to_string_hex((uint64_t)field) + " " + \ + loc_parenthesize(loc_get_bit_defs(field, tbl))) + +/* get from a table of strings with index */ +/* tbl - map of entries + key - key to the matching entry + defalt - default pointer in case of incorrect parameters + */ +inline static const string& loc_get_name_from_tbl(const NameValTbl& tbl, int64_t key, + const string& defalt = gEmptyStr) { + auto item = tbl.find(key); + if (item != tbl.end()) { + return item->second; + } else { + return defalt; + } +} + +/* puts to string formatted "TAG: VAL" with option ending string, default to newline */ +inline string loc_put_tag_val(const string& tag, const string& val, const string& eol = "\n") { + return tag + ": " + val + eol; +} + +inline string loc_parenthesize(const string& str) { + return "(" + str + ")"; +} + +/* Get names from value */ +inline const char* loc_get_name_from_val(const NameValTbl& table, int64_t value) { + return loc_get_name_from_tbl(table, value, gUnknownStr).c_str(); +} + +inline const char* log_succ_fail_string(int is_succ) { + return is_succ? "successful" : "failed"; +} + +/* prints mask into a string with bit definitions from tbl */ +/* mask - bit mask, to be expanded into " BIT_NAMEx | BIT_NAMEy ... " + tbl - a table with defs for each bit, defined as entries + {{bit0, "BIT0_NAME"}, {bit1, "BIT1_NAME"}, .... {bitn, "BITn_NAME"} } + entries - number of strings in the table + */ +string loc_get_bit_defs(uint64_t mask, const NameValTbl& tbl); +uint64_t loc_get_least_bit(uint64_t& mask, bool clearThebit = true); +const char* loc_get_msg_q_status(int status); +const char* loc_get_target_name(unsigned int target); +char *loc_get_time(char *time_string, size_t buf_size); + +#endif /* LOC_LOG_H */ diff --git a/gps/utils/loc_misc_utils.cpp b/gps/utils/loc_misc_utils.cpp new file mode 100644 index 0000000..fbcaef4 --- /dev/null +++ b/gps/utils/loc_misc_utils.cpp @@ -0,0 +1,351 @@ +/* Copyright (c) 2014, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_misc_utils" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef MSEC_IN_ONE_SEC +#define MSEC_IN_ONE_SEC 1000ULL +#endif +#define GET_MSEC_FROM_TS(ts) ((ts.tv_sec * MSEC_IN_ONE_SEC) + (ts.tv_nsec + 500000)/1000000) + +int loc_util_split_string(char *raw_string, char **split_strings_ptr, + int max_num_substrings, char delimiter) +{ + int raw_string_index=0; + int num_split_strings=0; + unsigned char end_string=0; + int raw_string_length=0; + + if(!raw_string || !split_strings_ptr) { + LOC_LOGE("%s:%d]: NULL parameters", __func__, __LINE__); + num_split_strings = -1; + goto err; + } + LOC_LOGD("%s:%d]: raw string: %s\n", __func__, __LINE__, raw_string); + raw_string_length = strlen(raw_string) + 1; + split_strings_ptr[num_split_strings] = &raw_string[raw_string_index]; + for(raw_string_index=0; raw_string_index < raw_string_length; raw_string_index++) { + if(raw_string[raw_string_index] == '\0') + end_string=1; + if((raw_string[raw_string_index] == delimiter) || end_string) { + raw_string[raw_string_index] = '\0'; + if (num_split_strings < max_num_substrings) { + LOC_LOGD("%s:%d]: split string: %s\n", + __func__, __LINE__, split_strings_ptr[num_split_strings]); + } + num_split_strings++; + if(((raw_string_index + 1) < raw_string_length) && + (num_split_strings < max_num_substrings)) { + split_strings_ptr[num_split_strings] = &raw_string[raw_string_index+1]; + } + else { + break; + } + } + if(end_string) + break; + } +err: + LOC_LOGD("%s:%d]: num_split_strings: %d\n", __func__, __LINE__, num_split_strings); + return num_split_strings; +} + +void loc_util_trim_space(char *org_string) +{ + char *scan_ptr, *write_ptr; + char *first_nonspace = NULL, *last_nonspace = NULL; + + if(org_string == NULL) { + LOC_LOGE("%s:%d]: NULL parameter", __func__, __LINE__); + goto err; + } + + scan_ptr = write_ptr = org_string; + + while (*scan_ptr) { + //Find the first non-space character + if ( !isspace(*scan_ptr) && first_nonspace == NULL) { + first_nonspace = scan_ptr; + } + //Once the first non-space character is found in the + //above check, keep shifting the characters to the left + //to replace the spaces + if (first_nonspace != NULL) { + *(write_ptr++) = *scan_ptr; + //Keep track of which was the last non-space character + //encountered + //last_nonspace will not be updated in the case where + //the string ends with spaces + if ( !isspace(*scan_ptr)) { + last_nonspace = write_ptr; + } + } + scan_ptr++; + } + //Add NULL terminator after the last non-space character + if (last_nonspace) { *last_nonspace = '\0'; } +err: + return; +} + +inline void logDlError(const char* failedCall) { + const char * err = dlerror(); + LOC_LOGe("%s error: %s", failedCall, (nullptr == err) ? "unknown" : err); +} + +void* dlGetSymFromLib(void*& libHandle, const char* libName, const char* symName) +{ + void* sym = nullptr; + if ((nullptr != libHandle || nullptr != libName) && nullptr != symName) { + if (nullptr == libHandle) { + libHandle = dlopen(libName, RTLD_NOW); + if (nullptr == libHandle) { + logDlError("dlopen"); + } + } + // NOT else, as libHandle gets assigned 5 line above + if (nullptr != libHandle) { + sym = dlsym(libHandle, symName); + if (nullptr == sym) { + logDlError("dlsym"); + } + } + } else { + LOC_LOGe("Either libHandle (%p) or libName (%p) must not be null; " + "symName (%p) can not be null.", libHandle, libName, symName); + } + + return sym; +} + +uint64_t getQTimerTickCount() +{ + uint64_t qTimerCount = 0; +#if __aarch64__ + asm volatile("mrs %0, cntvct_el0" : "=r" (qTimerCount)); +#elif defined (__i386__) || defined (__x86_64__) + /* Qtimer not supported in x86 architecture */ + qTimerCount = 0; +#else + asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (qTimerCount)); +#endif + + return qTimerCount; +} + +uint64_t getQTimerDeltaNanos() +{ + char qtimer_val_string[100]; + char *temp; + uint64_t local_qtimer = 0, remote_qtimer = 0; + int mdm_fd = -1, wlan_fd = -1, ret = 0; + uint64_t delta = 0; + + memset(qtimer_val_string, '\0', sizeof(qtimer_val_string)); + + char devNode[] = "/sys/bus/mhi/devices/0306_00.01.00/time_us"; + for (; devNode[27] < 3 && mdm_fd < 0; devNode[27]++) { + mdm_fd = ::open(devNode, O_RDONLY); + if (mdm_fd < 0) { + LOC_LOGe("MDM open file: %s error: %s", devNode, strerror(errno)); + } + } + if (mdm_fd > 0) { + ret = read(mdm_fd, qtimer_val_string, sizeof(qtimer_val_string)-1); + ::close(mdm_fd); + if (ret < 0) { + LOC_LOGe("MDM read time_us file error: %s", strerror(errno)); + } else { + temp = qtimer_val_string; + temp = strchr(temp, ':'); + temp = temp + 2; + local_qtimer = atoll(temp); + + temp = strchr(temp, ':'); + temp = temp + 2; + remote_qtimer = atoll(temp); + + if (local_qtimer >= remote_qtimer) { + delta = (local_qtimer - remote_qtimer) * 1000; + } + LOC_LOGv("qtimer values in microseconds: local:%" PRIi64 " remote:%" PRIi64 "" + " delta in nanoseconds:%" PRIi64 "", + local_qtimer, remote_qtimer, delta); + } + } + return delta; +} + +uint64_t getQTimerFreq() +{ +#if __aarch64__ + uint64_t val = 0; + asm volatile("mrs %0, cntfrq_el0" : "=r" (val)); +#elif defined (__i386__) || defined (__x86_64__) + /* Qtimer not supported in x86 architecture */ + uint64_t val = 0; +#else + uint32_t val = 0; + asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (val)); +#endif + return val; +} + +uint64_t getBootTimeMilliSec() +{ + struct timespec curTs; + clock_gettime(CLOCK_BOOTTIME, &curTs); + return (uint64_t)GET_MSEC_FROM_TS(curTs); +} + +// Used for convert position/velocity from GSNS antenna based to VRP based +void Matrix_MxV(float a[3][3], float b[3], float c[3]) { + int i, j; + + for (i=0; i<3; i++) { + c[i] = 0.0f; + for (j=0; j<3; j++) + c[i] += a[i][j] * b[j]; + } +} + +// Used for convert position/velocity from GNSS antenna based to VRP based +void Matrix_Skew(float a[3], float c[3][3]) { + c[0][0] = 0.0f; + c[0][1] = -a[2]; + c[0][2] = a[1]; + c[1][0] = a[2]; + c[1][1] = 0.0f; + c[1][2] = -a[0]; + c[2][0] = -a[1]; + c[2][1] = a[0]; + c[2][2] = 0.0f; +} + +// Used for convert position/velocity from GNSS antenna based to VRP based +void Euler2Dcm(float euler[3], float dcm[3][3]) { + float cr = 0.0, sr = 0.0, cp = 0.0, sp = 0.0, ch = 0.0, sh = 0.0; + + cr = cosf(euler[0]); + sr = sinf(euler[0]); + cp = cosf(euler[1]); + sp = sinf(euler[1]); + ch = cosf(euler[2]); + sh = sinf(euler[2]); + + dcm[0][0] = cp * ch; + dcm[0][1] = (sp*sr*ch) - (cr*sh); + dcm[0][2] = (cr*sp*ch) + (sh*sr); + + dcm[1][0] = cp * sh; + dcm[1][1] = (sr*sp*sh) + (cr*ch); + dcm[1][2] = (cr*sp*sh) - (sr*ch); + + dcm[2][0] = -sp; + dcm[2][1] = sr * cp; + dcm[2][2] = cr * cp; +} + +// Used for convert position from GSNS based to VRP based +// The converted position will be stored in the llaInfo parameter. +#define A6DOF_WGS_A (6378137.0f) +#define A6DOF_WGS_B (6335439.0f) +#define A6DOF_WGS_E2 (0.00669437999014f) +void loc_convert_lla_gnss_to_vrp(double lla[3], float rollPitchYaw[3], + float leverArm[3]) { + LOC_LOGv("lla: %f, %f, %f, lever arm: %f %f %f, " + "rollpitchyaw: %f %f %f", + lla[0], lla[1], lla[2], + leverArm[0], leverArm[1], leverArm[2], + rollPitchYaw[0], rollPitchYaw[1], rollPitchYaw[2]); + + float cnb[3][3]; + memset(cnb, 0, sizeof(cnb)); + Euler2Dcm(rollPitchYaw, cnb); + + float sl = sin(lla[0]); + float cl = cos(lla[0]); + float sf = 1.0f / (1.0f - A6DOF_WGS_E2 * sl* sl); + float sfr = sqrtf(sf); + + float rn = A6DOF_WGS_B * sf * sfr + lla[2]; + float re = A6DOF_WGS_A * sfr + lla[2]; + + float deltaNEU[3]; + + // gps_pos_lla = imu_pos_lla + Cbn*la_b .* [1/geo.Rn; 1/(geo.Re*geo.cL); -1]; + Matrix_MxV(cnb, leverArm, deltaNEU); + + // NED to lla conversion + lla[0] = lla[0] + deltaNEU[0] / rn; + lla[1] = lla[1] + deltaNEU[1] / (re * cl); + lla[2] = lla[2] + deltaNEU[2]; +} + +// Used for convert velocity from GSNS based to VRP based +// The converted velocity will be stored in the enuVelocity parameter. +void loc_convert_velocity_gnss_to_vrp(float enuVelocity[3], float rollPitchYaw[3], + float rollPitchYawRate[3], float leverArm[3]) { + + LOC_LOGv("enu velocity: %f, %f, %f, lever arm: %f %f %f, roll pitch yaw: %f %f %f," + "rollpitchyawRate: %f %f %f", + enuVelocity[0], enuVelocity[1], enuVelocity[2], + leverArm[0], leverArm[1], leverArm[2], + rollPitchYaw[0], rollPitchYaw[1], rollPitchYaw[2], + rollPitchYawRate[0], rollPitchYawRate[1], rollPitchYawRate[2]); + + float cnb[3][3]; + memset(cnb, 0, sizeof(cnb)); + Euler2Dcm(rollPitchYaw, cnb); + + float skewLA[3][3]; + memset(skewLA, 0, sizeof(skewLA)); + Matrix_Skew(leverArm, skewLA); + + float tmp[3]; + float deltaEnuVelocity[3]; + memset(tmp, 0, sizeof(tmp)); + memset(deltaEnuVelocity, 0, sizeof(deltaEnuVelocity)); + Matrix_MxV(skewLA, rollPitchYawRate, tmp); + Matrix_MxV(cnb, tmp, deltaEnuVelocity); + + enuVelocity[0] = enuVelocity[0] - deltaEnuVelocity[0]; + enuVelocity[1] = enuVelocity[1] - deltaEnuVelocity[1]; + enuVelocity[2] = enuVelocity[2] - deltaEnuVelocity[2]; +} diff --git a/gps/utils/loc_misc_utils.h b/gps/utils/loc_misc_utils.h new file mode 100644 index 0000000..2335e57 --- /dev/null +++ b/gps/utils/loc_misc_utils.h @@ -0,0 +1,321 @@ +/* Copyright (c) 2014, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _LOC_MISC_UTILS_H_ +#define _LOC_MISC_UTILS_H_ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +/*=========================================================================== +FUNCTION loc_split_string + +DESCRIPTION: + This function is used to split a delimiter separated string into + sub-strings. This function does not allocate new memory to store the split + strings. Instead, it places '\0' in places of delimiters and assings the + starting address of the substring within the raw string as the string address + The input raw_string no longer remains to be a collection of sub-strings + after this function is executed. + Please make a copy of the input string before calling this function if + necessary + +PARAMETERS: + char *raw_string: is the original string with delimiter separated substrings + char **split_strings_ptr: is the arraw of pointers which will hold the addresses + of individual substrings + int max_num_substrings: is the maximum number of substrings that are expected + by the caller. The array of pointers in the above parameter + is usually this long + char delimiter: is the delimiter that separates the substrings. Examples: ' ', ';' + +DEPENDENCIES + N/A + +RETURN VALUE + int Number of split strings + +SIDE EFFECTS + The input raw_string no longer remains a delimiter separated single string. + +EXAMPLE + delimiter = ' ' //space + raw_string = "hello new user" //delimiter is space ' ' + addresses = 0123456789abcd + split_strings_ptr[0] = &raw_string[0]; //split_strings_ptr[0] contains "hello" + split_strings_ptr[1] = &raw_string[6]; //split_strings_ptr[1] contains "new" + split_strings_ptr[2] = &raw_string[a]; //split_strings_ptr[2] contains "user" + +===========================================================================*/ +int loc_util_split_string(char *raw_string, char **split_strings_ptr, int max_num_substrings, + char delimiter); + +/*=========================================================================== +FUNCTION trim_space + +DESCRIPTION + Removes leading and trailing spaces of the string + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_util_trim_space(char *org_string); + +/*=========================================================================== +FUNCTION dlGetSymFromLib + +DESCRIPTION + Handy function to get a pointer to a symbol from a library. + + If libHandle is not null, it will be used as the handle to the library. In + that case libName wll not be used; + libHandle is an in / out parameter. + If libHandle is null, libName will be used to dlopen. + Either libHandle or libName must not be nullptr. + symName must not be null. + +DEPENDENCIES + N/A + +RETURN VALUE + pointer to symName. Could be nullptr if + Parameters are incorrect; or + libName can not be opened; or + symName can not be found. + +SIDE EFFECTS + N/A +===========================================================================*/ +void* dlGetSymFromLib(void*& libHandle, const char* libName, const char* symName); + +/*=========================================================================== +FUNCTION getQTimerTickCount + +DESCRIPTION + This function is used to read the QTimer ticks count. This value is globally maintained and + must be the same across all processors on a target. + +DEPENDENCIES + N/A + +RETURN VALUE + uint64_t QTimer tick count + +SIDE EFFECTS + N/A +===========================================================================*/ +uint64_t getQTimerTickCount(); + +/*=========================================================================== +FUNCTION getQTimerDeltaNanos + +DESCRIPTION +This function is used to read the the difference in nanoseconds between +Qtimer on AP side and Qtimer on MP side for dual-SoC architectures such as Kona + +DEPENDENCIES +N/A + +RETURN VALUE +uint64_t QTimer difference in nanoseconds + +SIDE EFFECTS +N/A +===========================================================================*/ +uint64_t getQTimerDeltaNanos(); + +/*=========================================================================== +FUNCTION getQTimerFreq + +DESCRIPTION + This function is used to read the QTimer frequency in hz. This value is globally maintained and + must be the same across all processors on a target. + +DEPENDENCIES + N/A + +RETURN VALUE + uint64_t QTimer frequency + +SIDE EFFECTS + N/A +===========================================================================*/ +uint64_t getQTimerFreq(); + +/*=========================================================================== +FUNCTION getBootTimeMilliSec + +DESCRIPTION + This function is used to get boot time in milliseconds. + +DEPENDENCIES + N/A + +RETURN VALUE + uint64_t boot time in milliseconds + +SIDE EFFECTS + N/A +===========================================================================*/ +uint64_t getBootTimeMilliSec(); + +#ifdef __cplusplus +} +#endif + +using std::hex; +using std::string; +using std::stringstream; + +/*=========================================================================== +FUNCTION to_string_hex + +DESCRIPTION + This function works similar to std::to_string, but puts only in hex format. + +DEPENDENCIES + N/A + +RETURN VALUE + string, of input val in hex format + +SIDE EFFECTS + N/A +===========================================================================*/ +template +string to_string_hex(T val) { + stringstream ss; + if (val < 0) { + val = -val; + ss << "-"; + } + ss << hex << "0x" << val; + return ss.str(); +} + +/*=========================================================================== +FUNCTION loc_prim_arr_to_string + +DESCRIPTION + This function puts out primitive array in DEC or EHX format. + +DEPENDENCIES + N/A + +RETURN VALUE + string, space separated string of values in the input array, either + in decimal or hex format, depending on the value of decIfTrue + +SIDE EFFECTS + N/A +===========================================================================*/ +template +static string loc_prim_arr_to_string(T* arr, uint32_t size, bool decIfTrue = true) { + stringstream ss; + for (uint32_t i = 0; i < size; i++) { + ss << (decIfTrue ? to_string(arr[i]) : to_string_hex(arr[i])); + if (i != size - 1) { + ss << " "; + } + } + return ss.str(); +} + +/*=========================================================================== +FUNCTION qTimerTicksToNanos + +DESCRIPTION + Transform from ticks to nanoseconds, clock is 19.2 MHz + so the formula would be qtimer(ns) = (ticks * 1000000000) / 19200000 + or simplified qtimer(ns) = (ticks * 10000) / 192. + +DEPENDENCIES + N/A + +RETURN VALUE + Qtimer value in nanoseconds + +SIDE EFFECTS + N/A +===========================================================================*/ +inline uint64_t qTimerTicksToNanos(double qTimer) { + return (uint64_t((qTimer * double(10000ull)) / (double)192ull)); +} + +/*=========================================================================== +FUNCTION loc_convert_lla_gnss_to_vrp + +DESCRIPTION + This function converts lat/long/altitude from GNSS antenna based + to vehicle reference point based. + +DEPENDENCIES + N/A + +RETURN VALUE + The converted lat/long/altitude will be stored in the parameter of llaInfo. + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_convert_lla_gnss_to_vrp(double lla[3], float rollPitchYaw[3], + float leverArm[3]); + +/*=========================================================================== +FUNCTION loc_convert_velocity_gnss_to_vrp + +DESCRIPTION + This function converts east/north/up velocity from GNSS antenna based + to vehicle reference point based. + +DEPENDENCIES + N/A + +RETURN VALUE + The converted east/north/up velocity will be stored in the parameter of + enuVelocity. + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_convert_velocity_gnss_to_vrp(float enuVelocity[3], float rollPitchYaw[3], + float rollPitchYawRate[3], float leverArm[3]); + +#endif //_LOC_MISC_UTILS_H_ diff --git a/gps/utils/loc_nmea.cpp b/gps/utils/loc_nmea.cpp new file mode 100644 index 0000000..6b5e60e --- /dev/null +++ b/gps/utils/loc_nmea.cpp @@ -0,0 +1,2347 @@ +/* Copyright (c) 2012-2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "LocSvc_nmea" +#include +#include +#include +#include +#include + +#define GLONASS_SV_ID_OFFSET 64 +#define SBAS_SV_ID_OFFSET (87) +#define QZSS_SV_ID_OFFSET (192) +#define BDS_SV_ID_OFFSET (200) +#define GALILEO_SV_ID_OFFSET (300) +#define NAVIC_SV_ID_OFFSET (400) +#define MAX_SV_COUNT_SUPPORTED_IN_ONE_CONSTELLATION 64 +#define MAX_SATELLITES_IN_USE 12 +#define MSEC_IN_ONE_WEEK 604800000ULL +#define UTC_GPS_OFFSET_MSECS 315964800000ULL +#define MAX_TAG_BLOCK_GROUP_CODE (99999) + +// GNSS system id according to NMEA spec +#define SYSTEM_ID_GPS 1 +#define SYSTEM_ID_GLONASS 2 +#define SYSTEM_ID_GALILEO 3 +#define SYSTEM_ID_BDS 4 +#define SYSTEM_ID_QZSS 5 +#define SYSTEM_ID_NAVIC 6 + +//GNSS signal id according to NMEA spec +#define SIGNAL_ID_ALL_SIGNALS 0 +#define SIGNAL_ID_GPS_L1CA 1 +#define SIGNAL_ID_GPS_L1P 2 +#define SIGNAL_ID_GPS_L1M 3 +#define SIGNAL_ID_GPS_L2P 4 +#define SIGNAL_ID_GPS_L2CM 5 +#define SIGNAL_ID_GPS_L2CL 6 +#define SIGNAL_ID_GPS_L5I 7 +#define SIGNAL_ID_GPS_L5Q 8 + + +#define SIGNAL_ID_GLO_G1CA 1 +#define SIGNAL_ID_GLO_G1P 2 +#define SIGNAL_ID_GLO_G2CA 3 +#define SIGNAL_ID_GLO_G2P 4 + + +#define SIGNAL_ID_GAL_E5A 1 +#define SIGNAL_ID_GAL_E5B 2 +#define SIGNAL_ID_GAL_E5AB 3 +#define SIGNAL_ID_GAL_E6A 4 +#define SIGNAL_ID_GAL_E6BC 5 +#define SIGNAL_ID_GAL_L1A 6 +#define SIGNAL_ID_GAL_L1BC 7 + +#define SIGNAL_ID_BDS_B1I 1 +#define SIGNAL_ID_BDS_B1Q 2 +#define SIGNAL_ID_BDS_B1C 3 +#define SIGNAL_ID_BDS_B1A 4 +#define SIGNAL_ID_BDS_B2A 5 +#define SIGNAL_ID_BDS_B2B 6 +#define SIGNAL_ID_BDS_B2AB 7 +#define SIGNAL_ID_BDS_B3I 8 +#define SIGNAL_ID_BDS_B3Q 9 +#define SIGNAL_ID_BDS_B3A 0xA +#define SIGNAL_ID_BDS_B2I 0xB +#define SIGNAL_ID_BDS_B2Q 0xC + +#define SIGNAL_ID_QZSS_L1CA 1 +#define SIGNAL_ID_QZSS_L1CD 2 +#define SIGNAL_ID_QZSS_L1CP 3 +#define SIGNAL_ID_QZSS_LIS 4 +#define SIGNAL_ID_QZSS_L2CM 5 +#define SIGNAL_ID_QZSS_L2CL 6 +#define SIGNAL_ID_QZSS_L5I 7 +#define SIGNAL_ID_QZSS_L5Q 8 +#define SIGNAL_ID_QZSS_L6D 9 +#define SIGNAL_ID_QZSS_L6E 0xA + +#define SIGNAL_ID_NAVIC_L5SPS 1 +#define SIGNAL_ID_NAVIC_SSPS 2 +#define SIGNAL_ID_NAVIC_L5RS 3 +#define SIGNAL_ID_NAVIC_SRS 4 +#define SIGNAL_ID_NAVIC_L1SPS 5 + + +typedef struct loc_nmea_sv_meta_s +{ + char talker[3]; + uint32_t svTypeMask; + uint64_t mask; + uint32_t svCount; + uint32_t totalSvUsedCount; + uint32_t svIdOffset; + uint32_t signalId; + uint32_t systemId; +} loc_nmea_sv_meta; + +typedef struct loc_sv_cache_info_s +{ + uint64_t gps_used_mask; + uint64_t glo_used_mask; + uint64_t gal_used_mask; + uint64_t qzss_used_mask; + uint64_t bds_used_mask; + uint64_t navic_used_mask; + uint32_t gps_l1_count; + uint32_t gps_l2_count; + uint32_t gps_l5_count; + uint32_t glo_g1_count; + uint32_t glo_g2_count; + uint32_t gal_e1_count; + uint32_t gal_e5_count; + uint32_t gal_e5b_count; + uint32_t qzss_l1_count; + uint32_t qzss_l2_count; + uint32_t qzss_l5_count; + uint32_t bds_b1i_count; + uint32_t bds_b1c_count; + uint32_t bds_b2_count; + uint32_t navic_l5_count; + float hdop; + float pdop; + float vdop; +} loc_sv_cache_info; + +/*=========================================================================== +FUNCTION convert_Lla_to_Ecef + +DESCRIPTION + Convert LLA to ECEF + +DEPENDENCIES + NONE + +RETURN VALUE + NONE + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void convert_Lla_to_Ecef(const LocLla& plla, LocEcef& pecef) +{ + double r; + + r = MAJA / sqrt(1.0 - ESQR * sin(plla.lat) * sin(plla.lat)); + pecef.X = (r + plla.alt) * cos(plla.lat) * cos(plla.lon); + pecef.Y = (r + plla.alt) * cos(plla.lat) * sin(plla.lon); + pecef.Z = (r * OMES + plla.alt) * sin(plla.lat); +} + +/*=========================================================================== +FUNCTION convert_WGS84_to_PZ90 + +DESCRIPTION + Convert datum from WGS84 to PZ90 + +DEPENDENCIES + NONE + +RETURN VALUE + NONE + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void convert_WGS84_to_PZ90(const LocEcef& pWGS84, LocEcef& pPZ90) +{ + double deltaX = DatumConstFromWGS84[0]; + double deltaY = DatumConstFromWGS84[1]; + double deltaZ = DatumConstFromWGS84[2]; + double deltaScale = DatumConstFromWGS84[3]; + double rotX = DatumConstFromWGS84[4]; + double rotY = DatumConstFromWGS84[5]; + double rotZ = DatumConstFromWGS84[6]; + + pPZ90.X = deltaX + deltaScale * (pWGS84.X + rotZ * pWGS84.Y - rotY * pWGS84.Z); + pPZ90.Y = deltaY + deltaScale * (pWGS84.Y - rotZ * pWGS84.X + rotX * pWGS84.Z); + pPZ90.Z = deltaZ + deltaScale * (pWGS84.Z + rotY * pWGS84.X - rotX * pWGS84.Y); +} + +/*=========================================================================== +FUNCTION convert_Ecef_to_Lla + +DESCRIPTION + Convert ECEF to LLA + +DEPENDENCIES + NONE + +RETURN VALUE + NONE + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void convert_Ecef_to_Lla(const LocEcef& pecef, LocLla& plla) +{ + double p, r; + double EcefA = C_PZ90A; + double EcefB = C_PZ90B; + double Ecef1Mf; + double EcefE2; + double Mu; + double Smu; + double Cmu; + double Phi; + double Sphi; + double N; + + p = sqrt(pecef.X * pecef.X + pecef.Y * pecef.Y); + r = sqrt(p * p + pecef.Z * pecef.Z); + if (r < 1.0) { + plla.lat = 1.0; + plla.lon = 1.0; + plla.alt = 1.0; + } + Ecef1Mf = 1.0 - (EcefA - EcefB) / EcefA; + EcefE2 = 1.0 - (EcefB * EcefB) / (EcefA * EcefA); + if (p > 1.0) { + Mu = atan2(pecef.Z * (Ecef1Mf + EcefE2 * EcefA / r), p); + } else { + if (pecef.Z > 0.0) { + Mu = M_PI / 2.0; + } else { + Mu = -M_PI / 2.0; + } + } + Smu = sin(Mu); + Cmu = cos(Mu); + Phi = atan2(pecef.Z * Ecef1Mf + EcefE2 * EcefA * Smu * Smu * Smu, + Ecef1Mf * (p - EcefE2 * EcefA * Cmu * Cmu * Cmu)); + Sphi = sin(Phi); + N = EcefA / sqrt(1.0 - EcefE2 * Sphi * Sphi); + plla.alt = p * cos(Phi) + pecef.Z * Sphi - EcefA * EcefA/N; + plla.lat = Phi; + if ( p > 1.0) { + plla.lon = atan2(pecef.Y, pecef.X); + } else { + plla.lon = 0.0; + } +} + +/*=========================================================================== +FUNCTION convert_signalType_to_signalId + +DESCRIPTION + convert signalType to signal ID + +DEPENDENCIES + NONE + +RETURN VALUE + value of signal ID + +SIDE EFFECTS + N/A + +===========================================================================*/ +static uint32_t convert_signalType_to_signalId(GnssSignalTypeMask signalType) +{ + uint32_t signalId = SIGNAL_ID_ALL_SIGNALS; + + switch (signalType) { + case GNSS_SIGNAL_GPS_L1CA: + case GNSS_SIGNAL_SBAS_L1: + signalId = SIGNAL_ID_GPS_L1CA; + break; + case GNSS_SIGNAL_GPS_L2: + signalId = SIGNAL_ID_GPS_L2CL; + break; + case GNSS_SIGNAL_GPS_L5: + signalId = SIGNAL_ID_GPS_L5Q; + break; + case GNSS_SIGNAL_GLONASS_G1: + signalId = SIGNAL_ID_GLO_G1CA; + break; + case GNSS_SIGNAL_GLONASS_G2: + signalId = SIGNAL_ID_GLO_G2CA; + break; + case GNSS_SIGNAL_GALILEO_E1: + signalId = SIGNAL_ID_GAL_L1BC; + break; + case GNSS_SIGNAL_GALILEO_E5A: + signalId = SIGNAL_ID_GAL_E5A; + break; + case GNSS_SIGNAL_GALILEO_E5B: + signalId = SIGNAL_ID_GAL_E5B; + break; + case GNSS_SIGNAL_QZSS_L1CA: + signalId = SIGNAL_ID_QZSS_L1CA; + break; + case GNSS_SIGNAL_QZSS_L2: + signalId = SIGNAL_ID_QZSS_L2CL; + break; + case GNSS_SIGNAL_QZSS_L5: + signalId = SIGNAL_ID_QZSS_L5Q; + break; + case GNSS_SIGNAL_BEIDOU_B1I: + signalId = SIGNAL_ID_BDS_B1I; + break; + case GNSS_SIGNAL_BEIDOU_B1C: + signalId = SIGNAL_ID_BDS_B1C; + break; + case GNSS_SIGNAL_BEIDOU_B2I: + signalId = SIGNAL_ID_BDS_B2I; + break; + case GNSS_SIGNAL_BEIDOU_B2AI: + case GNSS_SIGNAL_BEIDOU_B2AQ: + signalId = SIGNAL_ID_BDS_B2A; + break; + case GNSS_SIGNAL_NAVIC_L5: + signalId = SIGNAL_ID_NAVIC_L5SPS; + break; + default: + signalId = SIGNAL_ID_ALL_SIGNALS; + } + + return signalId; + +} + +/*=========================================================================== +FUNCTION get_sv_count_from_mask + +DESCRIPTION + get the sv count from bit mask + +DEPENDENCIES + NONE + +RETURN VALUE + value of sv count + +SIDE EFFECTS + N/A + +===========================================================================*/ +static uint32_t get_sv_count_from_mask(uint64_t svMask, int totalSvCount) +{ + int index = 0; + uint32_t svCount = 0; + + if(totalSvCount > MAX_SV_COUNT_SUPPORTED_IN_ONE_CONSTELLATION) { + LOC_LOGE("total SV count in this constellation %d exceeded limit %d", + totalSvCount, MAX_SV_COUNT_SUPPORTED_IN_ONE_CONSTELLATION); + } + for(index = 0; index < totalSvCount; index++) { + if(svMask & 0x1) + svCount += 1; + svMask >>= 1; + } + return svCount; +} + +/*=========================================================================== +FUNCTION loc_nmea_sv_meta_init + +DESCRIPTION + Init loc_nmea_sv_meta passed in + +DEPENDENCIES + NONE + +RETURN VALUE + Pointer to loc_nmea_sv_meta + +SIDE EFFECTS + N/A + +===========================================================================*/ +static loc_nmea_sv_meta* loc_nmea_sv_meta_init(loc_nmea_sv_meta& sv_meta, + loc_sv_cache_info& sv_cache_info, + GnssSvType svType, + GnssSignalTypeMask signalType, + bool needCombine) +{ + memset(&sv_meta, 0, sizeof(sv_meta)); + sv_meta.svTypeMask = (1 << svType); + + switch (svType) + { + case GNSS_SV_TYPE_GPS: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'P'; + sv_meta.mask = sv_cache_info.gps_used_mask; + sv_meta.systemId = SYSTEM_ID_GPS; + sv_meta.svTypeMask |= (1 << GNSS_SV_TYPE_SBAS); + switch (signalType) { + case GNSS_SIGNAL_GPS_L1CA: + sv_meta.svCount = sv_cache_info.gps_l1_count; + break; + case GNSS_SIGNAL_GPS_L5: + sv_meta.svCount = sv_cache_info.gps_l5_count; + break; + case GNSS_SIGNAL_GPS_L2: + sv_meta.svCount = sv_cache_info.gps_l2_count; + break; + } + break; + case GNSS_SV_TYPE_GLONASS: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'L'; + sv_meta.mask = sv_cache_info.glo_used_mask; + // GLONASS SV ids are from 65-96 + sv_meta.svIdOffset = GLONASS_SV_ID_OFFSET; + sv_meta.systemId = SYSTEM_ID_GLONASS; + switch (signalType) { + case GNSS_SIGNAL_GLONASS_G1: + sv_meta.svCount = sv_cache_info.glo_g1_count; + break; + case GNSS_SIGNAL_GLONASS_G2: + sv_meta.svCount = sv_cache_info.glo_g2_count; + break; + } + break; + case GNSS_SV_TYPE_GALILEO: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'A'; + sv_meta.mask = sv_cache_info.gal_used_mask; + // GALILEO SV ids are from 301-336, So keep svIdOffset 300 + sv_meta.svIdOffset = GALILEO_SV_ID_OFFSET; + sv_meta.systemId = SYSTEM_ID_GALILEO; + switch (signalType) { + case GNSS_SIGNAL_GALILEO_E1: + sv_meta.svCount = sv_cache_info.gal_e1_count; + break; + case GNSS_SIGNAL_GALILEO_E5A: + sv_meta.svCount = sv_cache_info.gal_e5_count; + break; + case GNSS_SIGNAL_GALILEO_E5B: + sv_meta.svCount = sv_cache_info.gal_e5b_count; + break; + } + break; + case GNSS_SV_TYPE_QZSS: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'Q'; + sv_meta.mask = sv_cache_info.qzss_used_mask; + // QZSS SV ids are from 193-199. So keep svIdOffset 192 + sv_meta.svIdOffset = QZSS_SV_ID_OFFSET; + sv_meta.systemId = SYSTEM_ID_QZSS; + switch (signalType) { + case GNSS_SIGNAL_QZSS_L1CA: + sv_meta.svCount = sv_cache_info.qzss_l1_count; + break; + case GNSS_SIGNAL_QZSS_L2: + sv_meta.svCount = sv_cache_info.qzss_l2_count; + break; + case GNSS_SIGNAL_QZSS_L5: + sv_meta.svCount = sv_cache_info.qzss_l5_count; + break; + } + break; + case GNSS_SV_TYPE_BEIDOU: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'B'; + sv_meta.mask = sv_cache_info.bds_used_mask; + // BDS SV ids are from 201-237. So keep svIdOffset 200 + sv_meta.svIdOffset = BDS_SV_ID_OFFSET; + sv_meta.systemId = SYSTEM_ID_BDS; + switch (signalType) { + case GNSS_SIGNAL_BEIDOU_B1I: + sv_meta.svCount = sv_cache_info.bds_b1i_count; + break; + case GNSS_SIGNAL_BEIDOU_B1C: + sv_meta.svCount = sv_cache_info.bds_b1c_count; + break; + case GNSS_SIGNAL_BEIDOU_B2AI: + sv_meta.svCount = sv_cache_info.bds_b2_count; + break; + } + break; + case GNSS_SV_TYPE_NAVIC: + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'I'; + sv_meta.mask = sv_cache_info.navic_used_mask; + // NAVIC SV ids are from 401-414. So keep svIdOffset 400 + sv_meta.svIdOffset = NAVIC_SV_ID_OFFSET; + sv_meta.systemId = SYSTEM_ID_NAVIC; + switch (signalType) { + case GNSS_SIGNAL_NAVIC_L5: + sv_meta.svCount = sv_cache_info.navic_l5_count; + break; + } + break; + default: + LOC_LOGE("NMEA Error unknow constellation type: %d", svType); + return NULL; + } + sv_meta.signalId = convert_signalType_to_signalId(signalType); + sv_meta.totalSvUsedCount = + get_sv_count_from_mask(sv_cache_info.gps_used_mask, + GPS_SV_PRN_MAX - GPS_SV_PRN_MIN + 1) + + get_sv_count_from_mask(sv_cache_info.glo_used_mask, + GLO_SV_PRN_MAX - GLO_SV_PRN_MIN + 1) + + get_sv_count_from_mask(sv_cache_info.gal_used_mask, + GAL_SV_PRN_MAX - GAL_SV_PRN_MIN + 1) + + get_sv_count_from_mask(sv_cache_info.qzss_used_mask, + QZSS_SV_PRN_MAX - QZSS_SV_PRN_MIN + 1) + + get_sv_count_from_mask(sv_cache_info.bds_used_mask, + BDS_SV_PRN_MAX - BDS_SV_PRN_MIN + 1) + + get_sv_count_from_mask(sv_cache_info.navic_used_mask, + NAVIC_SV_PRN_MAX - NAVIC_SV_PRN_MIN + 1); + if (needCombine && + (sv_cache_info.gps_used_mask ? 1 : 0) + + (sv_cache_info.glo_used_mask ? 1 : 0) + + (sv_cache_info.gal_used_mask ? 1 : 0) + + (sv_cache_info.qzss_used_mask ? 1 : 0) + + (sv_cache_info.bds_used_mask ? 1 : 0) + + (sv_cache_info.navic_used_mask ? 1 : 0) > 1) + { + // If GPS, GLONASS, Galileo, QZSS, BDS etc. are combined + // to obtain the reported position solution, + // talker shall be set to GN, to indicate that + // the satellites are used in a combined solution + sv_meta.talker[0] = 'G'; + sv_meta.talker[1] = 'N'; + } + return &sv_meta; +} + +/*=========================================================================== +FUNCTION loc_nmea_put_checksum + +DESCRIPTION + Generate NMEA sentences generated based on position report + +DEPENDENCIES + NONE + +RETURN VALUE + Total length of the nmea sentence + +SIDE EFFECTS + N/A + +===========================================================================*/ +static int loc_nmea_put_checksum(char *pNmea, int maxSize, bool isTagBlock) +{ + uint8_t checksum = 0; + int length = 0; + int checksumLength = 0; + if(NULL == pNmea) + return 0; + + pNmea++; //skip the $ or / for Tag Block + while (*pNmea != '\0') + { + checksum ^= *pNmea++; + length++; + } + + if (isTagBlock) { + // length now contains tag block sentence string length not including / sign. + checksumLength = snprintf(pNmea, (maxSize-length-1), "*%02X\\", checksum); + } else { + // length now contains nmea sentence string length not including $ sign. + checksumLength = snprintf(pNmea, (maxSize-length-1), "*%02X\r\n", checksum); + } + // total length of nmea sentence is length of nmea sentence inc $ sign plus + // length of checksum (+1 is to cover the $ character in the length). + return (length + checksumLength + 1); +} + +/*=========================================================================== +FUNCTION loc_nmea_generate_GSA + +DESCRIPTION + Generate NMEA GSA sentences generated based on position report + Currently below sentences are generated: + - $GPGSA : GPS DOP and active SVs + - $GLGSA : GLONASS DOP and active SVs + - $GAGSA : GALILEO DOP and active SVs + - $GNGSA : GNSS DOP and active SVs + +DEPENDENCIES + NONE + +RETURN VALUE + Number of SVs used + +SIDE EFFECTS + N/A + +===========================================================================*/ +static uint32_t loc_nmea_generate_GSA(const GpsLocationExtended &locationExtended, + char* sentence, + int bufSize, + loc_nmea_sv_meta* sv_meta_p, + std::vector &nmeaArraystr, + bool isTagBlockGroupingEnabled) +{ + if (!sentence || bufSize <= 0 || !sv_meta_p) + { + LOC_LOGE("NMEA Error invalid arguments."); + return 0; + } + + char* pMarker = sentence; + int lengthRemaining = bufSize; + int length = 0; + int lengthTagBlock = 0; + + uint32_t svUsedCount = 0; + uint32_t svUsedList[64] = {0}; + uint32_t sentenceCount = 0; + uint32_t sentenceNumber = 1; + size_t svNumber = 1; + static uint32_t code = 1; + + char fixType = '\0'; + + const char* talker = sv_meta_p->talker; + uint32_t svIdOffset = sv_meta_p->svIdOffset; + uint64_t mask = sv_meta_p->mask; + + if (!(sv_meta_p->svTypeMask & (1 << GNSS_SV_TYPE_GLONASS))) { + svIdOffset = 0; + } + + for (uint8_t i = 1; mask > 0 && svUsedCount < 64; i++) + { + if (mask & 1) + svUsedList[svUsedCount++] = i + svIdOffset; + mask = mask >> 1; + } + + if (svUsedCount == 0) { + return 0; + } else { + sentenceNumber = 1; + sentenceCount = svUsedCount / 12 + (svUsedCount % 12 != 0); + svNumber = 1; + } + while (sentenceNumber <= sentenceCount) { + pMarker = sentence; + lengthRemaining = bufSize; + if (svUsedCount > 12 && isTagBlockGroupingEnabled) { + lengthTagBlock = snprintf(pMarker, lengthRemaining, "\\g:%d-%d-%d", sentenceNumber, + sentenceCount, code); + if (MAX_TAG_BLOCK_GROUP_CODE == code) { + code = 1; + } + lengthTagBlock = loc_nmea_put_checksum(sentence, bufSize, true); + pMarker += lengthTagBlock; + lengthRemaining -= lengthTagBlock; + } + if (sv_meta_p->totalSvUsedCount == 0) + fixType = '1'; // no fix + else if (sv_meta_p->totalSvUsedCount <= 3) + fixType = '2'; // 2D fix + else + fixType = '3'; // 3D fix + + // Start printing the sentence + // Format: $--GSA,a,x,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,p.p,h.h,v.v,s*cc + // a : Mode : A : Automatic, allowed to automatically switch 2D/3D + // x : Fixtype : 1 (no fix), 2 (2D fix), 3 (3D fix) + // xx : 12 SV ID + // p.p : Position DOP (Dilution of Precision) + // h.h : Horizontal DOP + // v.v : Vertical DOP + // s : GNSS System Id + // cc : Checksum value + length = snprintf(pMarker, lengthRemaining, "$%sGSA,A,%c,", talker, fixType); + if (length < 0 || length >= lengthRemaining) { + LOC_LOGE("NMEA Error in string formatting"); + return 0; + } + pMarker += length; + lengthRemaining -= length; + + // Add 12 satellite IDs + for (uint8_t i = 0; i < 12; i++, svNumber++) + { + if (svNumber <= svUsedCount) + length = snprintf(pMarker, lengthRemaining, "%02d,", svUsedList[svNumber - 1]); + else + length = snprintf(pMarker, lengthRemaining, ","); + + if (length < 0 || length >= lengthRemaining) { + LOC_LOGE("NMEA Error in string formatting"); + return 0; + } + pMarker += length; + lengthRemaining -= length; + } + + // Add the position/horizontal/vertical DOP values + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) + { + length = snprintf(pMarker, lengthRemaining, "%.1f,%.1f,%.1f,", + locationExtended.pdop, + locationExtended.hdop, + locationExtended.vdop); + } + else + { // no dop + length = snprintf(pMarker, lengthRemaining, ",,,"); + } + pMarker += length; + lengthRemaining -= length; + + // system id + length = snprintf(pMarker, lengthRemaining, "%d", sv_meta_p->systemId); + pMarker += length; + lengthRemaining -= length; + + /* Sentence is ready, add checksum and broadcast */ + length = loc_nmea_put_checksum(sentence + lengthTagBlock, bufSize - lengthTagBlock, false); + nmeaArraystr.push_back(sentence); + sentenceNumber++; + if (!isTagBlockGroupingEnabled) { + break; + } + } + if (svUsedCount > 12 && isTagBlockGroupingEnabled) { + code++; + } + return svUsedCount; +} + +/*=========================================================================== +FUNCTION loc_nmea_generate_GSV + +DESCRIPTION + Generate NMEA GSV sentences generated based on sv report + Currently below sentences are generated: + - $GPGSV: GPS Satellites in View + - $GLGSV: GLONASS Satellites in View + - $GAGSV: GALILEO Satellites in View + +DEPENDENCIES + NONE + +RETURN VALUE + NONE + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_nmea_generate_GSV(const GnssSvNotification &svNotify, + char* sentence, + int bufSize, + loc_nmea_sv_meta* sv_meta_p, + std::vector &nmeaArraystr) +{ + if (!sentence || bufSize <= 0) + { + LOC_LOGE("NMEA Error invalid argument."); + return; + } + + char* pMarker = sentence; + int lengthRemaining = bufSize; + int length = 0; + int sentenceCount = 0; + int sentenceNumber = 1; + size_t svNumber = 1; + + const char* talker = sv_meta_p->talker; + uint32_t svIdOffset = sv_meta_p->svIdOffset; + int svCount = sv_meta_p->svCount; + if (svCount <= 0) + { + LOC_LOGV("No SV in view for talker ID:%s, signal ID:%X", talker, sv_meta_p->signalId); + return; + } + + if ((1 << GNSS_SV_TYPE_GLONASS) & sv_meta_p->svTypeMask) { + svIdOffset = 0; + } + svNumber = 1; + sentenceNumber = 1; + sentenceCount = svCount / 4 + (svCount % 4 != 0); + + while (sentenceNumber <= sentenceCount) + { + pMarker = sentence; + lengthRemaining = bufSize; + + length = snprintf(pMarker, lengthRemaining, "$%sGSV,%d,%d,%02d", + talker, sentenceCount, sentenceNumber, svCount); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + for (int i=0; (svNumber <= svNotify.count) && (i < 4); svNumber++) + { + GnssSignalTypeMask signalType = svNotify.gnssSvs[svNumber-1].gnssSignalTypeMask; + if (0 == signalType) { + // If no signal type in report, it means default L1,G1,E1,B1I + switch (svNotify.gnssSvs[svNumber - 1].type) + { + case GNSS_SV_TYPE_GPS: + signalType = GNSS_SIGNAL_GPS_L1CA; + break; + case GNSS_SV_TYPE_GLONASS: + signalType = GNSS_SIGNAL_GLONASS_G1; + break; + case GNSS_SV_TYPE_GALILEO: + signalType = GNSS_SIGNAL_GALILEO_E1; + break; + case GNSS_SV_TYPE_QZSS: + signalType = GNSS_SIGNAL_QZSS_L1CA; + break; + case GNSS_SV_TYPE_BEIDOU: + signalType = GNSS_SIGNAL_BEIDOU_B1I; + break; + case GNSS_SV_TYPE_SBAS: + signalType = GNSS_SIGNAL_SBAS_L1; + break; + case GNSS_SV_TYPE_NAVIC: + signalType = GNSS_SIGNAL_NAVIC_L5; + break; + default: + LOC_LOGE("NMEA Error unknow constellation type: %d", + svNotify.gnssSvs[svNumber - 1].type); + continue; + } + } + + if ((sv_meta_p->svTypeMask & (1 << svNotify.gnssSvs[svNumber - 1].type)) && + sv_meta_p->signalId == convert_signalType_to_signalId(signalType)) + { + if (GNSS_SV_TYPE_SBAS == svNotify.gnssSvs[svNumber - 1].type) { + svIdOffset = SBAS_SV_ID_OFFSET; + } + if (GNSS_SV_TYPE_GLONASS == svNotify.gnssSvs[svNumber - 1].type && + GLO_SV_PRN_SLOT_UNKNOWN == svNotify.gnssSvs[svNumber - 1].svId) { + length = snprintf(pMarker, lengthRemaining, ",,%02d,%03d,", + (int)(0.5 + svNotify.gnssSvs[svNumber - 1].elevation), //float to int + (int)(0.5 + svNotify.gnssSvs[svNumber - 1].azimuth)); //float to int + } else { + length = snprintf(pMarker, lengthRemaining, ",%02d,%02d,%03d,", + svNotify.gnssSvs[svNumber - 1].svId - svIdOffset, + (int)(0.5 + svNotify.gnssSvs[svNumber - 1].elevation), //float to int + (int)(0.5 + svNotify.gnssSvs[svNumber - 1].azimuth)); //float to int + } + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (svNotify.gnssSvs[svNumber - 1].cN0Dbhz > 0) + { + length = snprintf(pMarker, lengthRemaining,"%02d", + (int)(0.5 + svNotify.gnssSvs[svNumber - 1].cN0Dbhz)); //float to int + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + i++; + } + + } + + // append signalId + length = snprintf(pMarker, lengthRemaining,",%X",sv_meta_p->signalId); + pMarker += length; + lengthRemaining -= length; + + length = loc_nmea_put_checksum(sentence, bufSize, false); + nmeaArraystr.push_back(sentence); + sentenceNumber++; + + } //while +} + +/*=========================================================================== +FUNCTION loc_nmea_generate_DTM + +DESCRIPTION + Generate NMEA DTM sentences generated based on position report + +DEPENDENCIES + NONE + +RETURN VALUE + NONE + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_nmea_generate_DTM(const LocLla &ref_lla, + const LocLla &local_lla, + char *talker, + char *sentence, + int bufSize) +{ + char* pMarker = sentence; + int lengthRemaining = bufSize; + int length = 0; + int datum_type; + char ref_datum[4] = {0}; + char local_datum[4] = {0}; + double lla_offset[3] = {0}; + char latHem, longHem; + double latMins, longMins; + + + + datum_type = loc_get_datum_type(); + switch (datum_type) { + case LOC_GNSS_DATUM_WGS84: + ref_datum[0] = 'W'; + ref_datum[1] = '8'; + ref_datum[2] = '4'; + local_datum[0] = 'P'; + local_datum[1] = '9'; + local_datum[2] = '0'; + break; + case LOC_GNSS_DATUM_PZ90: + ref_datum[0] = 'P'; + ref_datum[1] = '9'; + ref_datum[2] = '0'; + local_datum[0] = 'W'; + local_datum[1] = '8'; + local_datum[2] = '4'; + break; + default: + break; + } + length = snprintf(pMarker , lengthRemaining , "$%sDTM,%s,," , talker, local_datum); + if (length < 0 || length >= lengthRemaining) { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + lla_offset[0] = local_lla.lat - ref_lla.lat; + lla_offset[1] = fmod(local_lla.lon - ref_lla.lon, 360.0); + if (lla_offset[1] < -180.0) { + lla_offset[1] += 360.0; + } else if ( lla_offset[1] > 180.0) { + lla_offset[1] -= 360.0; + } + lla_offset[2] = local_lla.alt - ref_lla.alt; + if (lla_offset[0] > 0.0) { + latHem = 'N'; + } else { + latHem = 'S'; + lla_offset[0] *= -1.0; + } + latMins = fmod(lla_offset[0] * 60.0, 60.0); + if (lla_offset[1] < 0.0) { + longHem = 'W'; + lla_offset[1] *= -1.0; + }else { + longHem = 'E'; + } + longMins = fmod(lla_offset[1] * 60.0, 60.0); + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,%.3lf,", + (uint8_t)floor(lla_offset[0]), latMins, latHem, + (uint8_t)floor(lla_offset[1]), longMins, longHem, lla_offset[2]); + if (length < 0 || length >= lengthRemaining) { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + length = snprintf(pMarker , lengthRemaining , "%s" , ref_datum); + if (length < 0 || length >= lengthRemaining) { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = loc_nmea_put_checksum(sentence, bufSize, false); +} + +/*=========================================================================== +FUNCTION get_utctime_with_leapsecond_transition + +DESCRIPTION + This function returns true if the position report is generated during + leap second transition period. If not, then the utc timestamp returned + will be set to the timestamp in the position report. If it is, + then the utc timestamp returned will need to take into account + of the leap second transition so that proper calendar year/month/date + can be calculated from the returned utc timestamp. + +DEPENDENCIES + NONE + +RETURN VALUE + true: position report is generated in leap second transition period. + +SIDE EFFECTS + N/A + +===========================================================================*/ +static bool get_utctime_with_leapsecond_transition( + const UlpLocation &location, + const GpsLocationExtended &locationExtended, + const LocationSystemInfo &systemInfo, + LocGpsUtcTime &utcPosTimestamp) +{ + bool inTransition = false; + + // position report is not generated during leap second transition, + // we can use the UTC timestamp from position report as is + utcPosTimestamp = location.gpsLocation.timestamp; + + // Check whether we are in leap second transition. + // If so, per NMEA spec, we need to display the extra second in format of 23:59:60 + // with year/month/date not getting advanced. + if ((locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_GPS_TIME) && + ((systemInfo.systemInfoMask & LOCATION_SYS_INFO_LEAP_SECOND) && + (systemInfo.leapSecondSysInfo.leapSecondInfoMask & + LEAP_SECOND_SYS_INFO_LEAP_SECOND_CHANGE_BIT))) { + + const LeapSecondChangeInfo &leapSecondChangeInfo = + systemInfo.leapSecondSysInfo.leapSecondChangeInfo; + const GnssSystemTimeStructType &gpsTimestampLsChange = + leapSecondChangeInfo.gpsTimestampLsChange; + + uint64_t gpsTimeLsChange = gpsTimestampLsChange.systemWeek * MSEC_IN_ONE_WEEK + + gpsTimestampLsChange.systemMsec; + uint64_t gpsTimePosReport = locationExtended.gpsTime.gpsWeek * MSEC_IN_ONE_WEEK + + locationExtended.gpsTime.gpsTimeOfWeekMs; + // we are only dealing with positive leap second change, as negative + // leap second change has never occurred and should not occur in future + if (leapSecondChangeInfo.leapSecondsAfterChange > + leapSecondChangeInfo.leapSecondsBeforeChange) { + // leap second adjustment is always 1 second at a time. It can happen + // every quarter end and up to four times per year. + if ((gpsTimePosReport >= gpsTimeLsChange) && + (gpsTimePosReport < (gpsTimeLsChange + 1000))) { + inTransition = true; + utcPosTimestamp = gpsTimeLsChange + UTC_GPS_OFFSET_MSECS - + leapSecondChangeInfo.leapSecondsBeforeChange * 1000; + + // we substract 1000 milli-seconds from UTC timestmap in order to calculate the + // proper year, month and date during leap second transtion. + // Let us give an example, assuming leap second transition is scheduled on 2019, + // Dec 31st mid night. When leap second transition is happening, + // instead of outputting the time as 2020, Jan, 1st, 00 hour, 00 min, and 00 sec. + // The time need to be displayed as 2019, Dec, 31st, 23 hour, 59 min and 60 sec. + utcPosTimestamp -= 1000; + } + } + } + return inTransition; +} + +/*=========================================================================== +FUNCTION loc_nmea_get_fix_quality + +DESCRIPTION + This function obtains the fix quality for GGA sentence, mode indicator + for RMC and VTG sentence based on nav solution mask and tech mask in + the postion report. + +DEPENDENCIES + NONE + +Output parameter + ggaGpsQuality: gps quality field in GGA sentence + rmcModeIndicator: mode indicator field in RMC sentence + vtgModeIndicator: mode indicator field in VTG sentence + +SIDE EFFECTS + N/A + +===========================================================================*/ +static void loc_nmea_get_fix_quality(const UlpLocation & location, + const GpsLocationExtended & locationExtended, + bool custom_gga_fix_quality, + char ggaGpsQuality[3], + char & rmcModeIndicator, + char & vtgModeIndicator, + char gnsModeIndicator[7]) { + + ggaGpsQuality[0] = '0'; // 0 means no fix + rmcModeIndicator = 'N'; // N means no fix + vtgModeIndicator = 'N'; // N means no fix + memset(gnsModeIndicator, 'N', 6); // N means no fix + gnsModeIndicator[6] = '\0'; + do { + if (!(location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG)){ + break; + } + // NOTE: Order of the check is important + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK) { + if (LOC_NAV_MASK_PPP_CORRECTION & locationExtended.navSolutionMask) { + ggaGpsQuality[0] = '2'; // 2 means DGPS fix + rmcModeIndicator = 'P'; // P means precise + vtgModeIndicator = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'P'; // P means precise + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'P'; // P means precise + break; + } else if (LOC_NAV_MASK_RTK_FIXED_CORRECTION & locationExtended.navSolutionMask){ + ggaGpsQuality[0] = '4'; // 4 means RTK Fixed fix + rmcModeIndicator = 'R'; // use R (RTK fixed) + vtgModeIndicator = 'D'; // use D (differential) as + // no RTK fixed defined for VTG in NMEA 183 spec + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'R'; // R means RTK fixed + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'R'; // R means RTK fixed + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'R'; // R means RTK fixed + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'R'; // R means RTK fixed + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'R'; // R means RTK fixed + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'R'; // R means RTK fixed + break; + } else if (LOC_NAV_MASK_RTK_CORRECTION & locationExtended.navSolutionMask){ + ggaGpsQuality[0] = '5'; // 5 means RTK float fix + rmcModeIndicator = 'F'; // F means RTK float fix + vtgModeIndicator = 'D'; // use D (differential) as + // no RTK float defined for VTG in NMEA 183 spec + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'F'; // F means RTK float fix + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'F'; // F means RTK float fix + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'F'; // F means RTK float fix + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'F'; // F means RTK float fix + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'F'; // F means RTK float fix + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'F'; // F means RTK float fix + break; + } else if (LOC_NAV_MASK_DGNSS_CORRECTION & locationExtended.navSolutionMask){ + ggaGpsQuality[0] = '2'; // 2 means DGPS fix + rmcModeIndicator = 'D'; // D means differential + vtgModeIndicator = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'D'; // D means differential + break; + } else if (LOC_NAV_MASK_SBAS_CORRECTION_IONO & locationExtended.navSolutionMask){ + ggaGpsQuality[0] = '2'; // 2 means DGPS fix + rmcModeIndicator = 'D'; // D means differential + vtgModeIndicator = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'D'; // D means differential + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'D'; // D means differential + break; + } + } + // NOTE: Order of the check is important + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_POS_TECH_MASK) { + if (LOC_POS_TECH_MASK_SATELLITE & locationExtended.tech_mask){ + ggaGpsQuality[0] = '1'; // 1 means GPS + rmcModeIndicator = 'A'; // A means autonomous + vtgModeIndicator = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[0] = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[1] = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[2] = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[3] = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[4] = 'A'; // A means autonomous + if (locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask ? 1 : 0) + gnsModeIndicator[5] = 'A'; // A means autonomous + break; + } else if (LOC_POS_TECH_MASK_SENSORS & locationExtended.tech_mask){ + ggaGpsQuality[0] = '6'; // 6 means estimated (dead reckoning) + rmcModeIndicator = 'E'; // E means estimated (dead reckoning) + vtgModeIndicator = 'E'; // E means estimated (dead reckoning) + memset(gnsModeIndicator, 'E', 6); // E means estimated (dead reckoning) + break; + } + } + } while (0); + + do { + // check for customized nmea enabled or not + // with customized GGA quality enabled + // PPP fix w/o sensor: 59, PPP fix w/ sensor: 69 + // DGNSS/SBAS correction fix w/o sensor: 2, w/ sensor: 62 + // RTK fixed fix w/o sensor: 4, w/ sensor: 64 + // RTK float fix w/o sensor: 5, w/ sensor: 65 + // SPE fix w/o sensor: 1, and w/ sensor: 61 + // Sensor dead reckoning fix: 6 + if (true == custom_gga_fix_quality) { + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_NAV_SOLUTION_MASK) { + // PPP fix w/o sensor: fix quality will now be 59 + // PPP fix w sensor: fix quality will now be 69 + if (LOC_NAV_MASK_PPP_CORRECTION & locationExtended.navSolutionMask) { + if ((locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_POS_TECH_MASK) && + (LOC_POS_TECH_MASK_SENSORS & locationExtended.tech_mask)) { + ggaGpsQuality[0] = '6'; + ggaGpsQuality[1] = '9'; + } else { + ggaGpsQuality[0] = '5'; + ggaGpsQuality[1] = '9'; + } + break; + } + } + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_POS_TECH_MASK) { + if (LOC_POS_TECH_MASK_SENSORS & locationExtended.tech_mask){ + char ggaQuality_copy = ggaGpsQuality[0]; + ggaGpsQuality[0] = '6'; // 6 sensor assisted + // RTK fixed fix w/ sensor: fix quality will now be 64 + // RTK float fix w/ sensor: 65 + // DGNSS and/or SBAS correction fix and w/ sensor: 62 + // GPS fix without correction and w/ sensor: 61 + if ((LOC_NAV_MASK_RTK_FIXED_CORRECTION & locationExtended.navSolutionMask)|| + (LOC_NAV_MASK_RTK_CORRECTION & locationExtended.navSolutionMask)|| + (LOC_NAV_MASK_DGNSS_CORRECTION & locationExtended.navSolutionMask)|| + (LOC_NAV_MASK_SBAS_CORRECTION_IONO & locationExtended.navSolutionMask)|| + (LOC_POS_TECH_MASK_SATELLITE & locationExtended.tech_mask)) { + ggaGpsQuality[1] = ggaQuality_copy; + break; + } + } + } + } + } while (0); + + LOC_LOGv("gps quality: %s, rmc mode indicator: %c, vtg mode indicator: %c", + ggaGpsQuality, rmcModeIndicator, vtgModeIndicator); +} + +/*=========================================================================== +FUNCTION loc_nmea_generate_pos + +DESCRIPTION + Generate NMEA sentences generated based on position report + Currently below sentences are generated within this function: + - $GPGSA : GPS DOP and active SVs + - $GLGSA : GLONASS DOP and active SVs + - $GAGSA : GALILEO DOP and active SVs + - $GNGSA : GNSS DOP and active SVs + - $--VTG : Track made good and ground speed + - $--RMC : Recommended minimum navigation information + - $--GGA : Time, position and fix related data + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_nmea_generate_pos(const UlpLocation &location, + const GpsLocationExtended &locationExtended, + const LocationSystemInfo &systemInfo, + unsigned char generate_nmea, + bool custom_gga_fix_quality, + std::vector &nmeaArraystr, + int& indexOfGGA, + bool isTagBlockGroupingEnabled) +{ + ENTRY_LOG(); + + indexOfGGA = -1; + LocGpsUtcTime utcPosTimestamp = 0; + bool inLsTransition = false; + + inLsTransition = get_utctime_with_leapsecond_transition + (location, locationExtended, systemInfo, utcPosTimestamp); + + time_t utcTime(utcPosTimestamp/1000); + struct tm result; + tm * pTm = gmtime_r(&utcTime, &result); + if (NULL == pTm) { + LOC_LOGE("gmtime failed"); + return; + } + + char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char sentence_DTM[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char sentence_RMC[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char sentence_GNS[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char sentence_GGA[NMEA_SENTENCE_MAX_LENGTH] = {0}; + char* pMarker = sentence; + int lengthRemaining = sizeof(sentence); + int length = 0; + int utcYear = pTm->tm_year % 100; // 2 digit year + int utcMonth = pTm->tm_mon + 1; // tm_mon starts at zero + int utcDay = pTm->tm_mday; + int utcHours = pTm->tm_hour; + int utcMinutes = pTm->tm_min; + int utcSeconds = pTm->tm_sec; + int utcMSeconds = (location.gpsLocation.timestamp)%1000; + int datum_type = loc_get_datum_type(); + LocEcef ecef_w84; + LocEcef ecef_p90; + LocLla lla_w84; + LocLla lla_p90; + LocLla ref_lla; + LocLla local_lla; + + if (inLsTransition) { + // During leap second transition, we need to display the extra + // leap second of hour, minute, second as (23:59:60) + utcHours = 23; + utcMinutes = 59; + utcSeconds = 60; + // As UTC timestamp is freezing during leap second transition, + // retrieve milli-seconds portion from GPS timestamp. + utcMSeconds = locationExtended.gpsTime.gpsTimeOfWeekMs % 1000; + } + + loc_sv_cache_info sv_cache_info = {}; + + if (GPS_LOCATION_EXTENDED_HAS_GNSS_SV_USED_DATA & locationExtended.flags) { + sv_cache_info.gps_used_mask = + locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask; + sv_cache_info.glo_used_mask = + locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask; + sv_cache_info.gal_used_mask = + locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask; + sv_cache_info.bds_used_mask = + locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask; + sv_cache_info.qzss_used_mask = + locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask; + sv_cache_info.navic_used_mask = + locationExtended.gnss_sv_used_ids.navic_sv_used_ids_mask; + } + + if (generate_nmea) { + char talker[3] = {'G', 'P', '\0'}; + uint32_t svUsedCount = 0; + uint32_t count = 0; + loc_nmea_sv_meta sv_meta; + // ------------------- + // ---$GPGSA/$GNGSA--- + // ------------------- + + count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, + GNSS_SIGNAL_GPS_L1CA, true), nmeaArraystr, isTagBlockGroupingEnabled); + if (count > 0) + { + svUsedCount += count; + talker[0] = sv_meta.talker[0]; + talker[1] = sv_meta.talker[1]; + } + + // ------------------- + // ---$GLGSA/$GNGSA--- + // ------------------- + + count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GLONASS, + GNSS_SIGNAL_GLONASS_G1, true), nmeaArraystr, isTagBlockGroupingEnabled); + if (count > 0) + { + svUsedCount += count; + talker[0] = sv_meta.talker[0]; + talker[1] = sv_meta.talker[1]; + } + + // ------------------- + // ---$GAGSA/$GNGSA--- + // ------------------- + + count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, + GNSS_SIGNAL_GALILEO_E1, true), nmeaArraystr, isTagBlockGroupingEnabled); + if (count > 0) + { + svUsedCount += count; + talker[0] = sv_meta.talker[0]; + talker[1] = sv_meta.talker[1]; + } + + // ---------------------------- + // ---$GBGSA/$GNGSA (BEIDOU)--- + // ---------------------------- + count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, + GNSS_SIGNAL_BEIDOU_B1I, true), nmeaArraystr, isTagBlockGroupingEnabled); + if (count > 0) + { + svUsedCount += count; + talker[0] = sv_meta.talker[0]; + talker[1] = sv_meta.talker[1]; + } + + // -------------------------- + // ---$GQGSA/$GNGSA (QZSS)--- + // -------------------------- + + count = loc_nmea_generate_GSA(locationExtended, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, + GNSS_SIGNAL_QZSS_L1CA, true), nmeaArraystr, isTagBlockGroupingEnabled); + if (count > 0) + { + svUsedCount += count; + talker[0] = sv_meta.talker[0]; + talker[1] = sv_meta.talker[1]; + } + + // if svUsedCount is 0, it means we do not generate any GSA sentence yet. + // in this case, generate an empty GSA sentence + if (svUsedCount == 0) { + strlcpy(sentence, "$GPGSA,A,1,,,,,,,,,,,,,,,,", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + } + + char ggaGpsQuality[3] = {'0', '\0', '\0'}; + char rmcModeIndicator = 'N'; + char vtgModeIndicator = 'N'; + char gnsModeIndicator[7] = {'N', 'N', 'N', 'N', 'N', 'N', '\0'}; + loc_nmea_get_fix_quality(location, locationExtended, custom_gga_fix_quality, + ggaGpsQuality, rmcModeIndicator, vtgModeIndicator, gnsModeIndicator); + + // ------------------- + // ------$--VTG------- + // ------------------- + + pMarker = sentence; + lengthRemaining = sizeof(sentence); + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_BEARING) + { + float magTrack = location.gpsLocation.bearing; + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV) + { + magTrack = location.gpsLocation.bearing - locationExtended.magneticDeviation; + if (magTrack < 0.0) + magTrack += 360.0; + else if (magTrack > 360.0) + magTrack -= 360.0; + } + + length = snprintf(pMarker, lengthRemaining, "$%sVTG,%.1lf,T,%.1lf,M,", talker, location.gpsLocation.bearing, magTrack); + } + else + { + length = snprintf(pMarker, lengthRemaining, "$%sVTG,,T,,M,", talker); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_SPEED) + { + float speedKnots = location.gpsLocation.speed * (3600.0/1852.0); + float speedKmPerHour = location.gpsLocation.speed * 3.6; + + length = snprintf(pMarker, lengthRemaining, "%.1lf,N,%.1lf,K,", speedKnots, speedKmPerHour); + } + else + { + length = snprintf(pMarker, lengthRemaining, ",N,,K,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = snprintf(pMarker, lengthRemaining, "%c", vtgModeIndicator); + + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + memset(&ecef_w84, 0, sizeof(ecef_w84)); + memset(&ecef_p90, 0, sizeof(ecef_p90)); + memset(&lla_w84, 0, sizeof(lla_w84)); + memset(&lla_p90, 0, sizeof(lla_p90)); + memset(&ref_lla, 0, sizeof(ref_lla)); + memset(&local_lla, 0, sizeof(local_lla)); + lla_w84.lat = location.gpsLocation.latitude / 180.0 * M_PI; + lla_w84.lon = location.gpsLocation.longitude / 180.0 * M_PI; + lla_w84.alt = location.gpsLocation.altitude; + + convert_Lla_to_Ecef(lla_w84, ecef_w84); + convert_WGS84_to_PZ90(ecef_w84, ecef_p90); + convert_Ecef_to_Lla(ecef_p90, lla_p90); + + switch (datum_type) { + case LOC_GNSS_DATUM_WGS84: + ref_lla.lat = location.gpsLocation.latitude; + ref_lla.lon = location.gpsLocation.longitude; + ref_lla.alt = location.gpsLocation.altitude; + local_lla.lat = lla_p90.lat / M_PI * 180.0; + local_lla.lon = lla_p90.lon / M_PI * 180.0; + local_lla.alt = lla_p90.alt; + break; + case LOC_GNSS_DATUM_PZ90: + ref_lla.lat = lla_p90.lat / M_PI * 180.0; + ref_lla.lon = lla_p90.lon / M_PI * 180.0; + ref_lla.alt = lla_p90.alt; + local_lla.lat = location.gpsLocation.latitude; + local_lla.lon = location.gpsLocation.longitude; + local_lla.alt = location.gpsLocation.altitude; + break; + default: + break; + } + + // ------------------- + // ------$--DTM------- + // ------------------- + loc_nmea_generate_DTM(ref_lla, local_lla, talker, sentence_DTM, sizeof(sentence_DTM)); + + // ------------------- + // ------$--RMC------- + // ------------------- + + pMarker = sentence_RMC; + lengthRemaining = sizeof(sentence_RMC); + + bool validFix = ((0 != sv_cache_info.gps_used_mask) || + (0 != sv_cache_info.glo_used_mask) || + (0 != sv_cache_info.gal_used_mask) || + (0 != sv_cache_info.qzss_used_mask) || + (0 != sv_cache_info.bds_used_mask)); + + if (validFix) { + length = snprintf(pMarker, lengthRemaining, "$%sRMC,%02d%02d%02d.%02d,A,", + talker, utcHours, utcMinutes, utcSeconds, utcMSeconds/10); + } else { + length = snprintf(pMarker, lengthRemaining, "$%sRMC,%02d%02d%02d.%02d,V,", + talker, utcHours, utcMinutes, utcSeconds, utcMSeconds/10); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG) + { + double latitude = ref_lla.lat; + double longitude = ref_lla.lon; + char latHemisphere; + char lonHemisphere; + double latMinutes; + double lonMinutes; + + if (latitude > 0) + { + latHemisphere = 'N'; + } + else + { + latHemisphere = 'S'; + latitude *= -1.0; + } + + if (longitude < 0) + { + lonHemisphere = 'W'; + longitude *= -1.0; + } + else + { + lonHemisphere = 'E'; + } + + latMinutes = fmod(latitude * 60.0 , 60.0); + lonMinutes = fmod(longitude * 60.0 , 60.0); + + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,", + (uint8_t)floor(latitude), latMinutes, latHemisphere, + (uint8_t)floor(longitude),lonMinutes, lonHemisphere); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_SPEED) + { + float speedKnots = location.gpsLocation.speed * (3600.0/1852.0); + length = snprintf(pMarker, lengthRemaining, "%.1lf,", speedKnots); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_BEARING) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,", location.gpsLocation.bearing); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = snprintf(pMarker, lengthRemaining, "%2.2d%2.2d%2.2d,", + utcDay, utcMonth, utcYear); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_MAG_DEV) + { + float magneticVariation = locationExtended.magneticDeviation; + char direction; + if (magneticVariation < 0.0) + { + direction = 'W'; + magneticVariation *= -1.0; + } + else + { + direction = 'E'; + } + + length = snprintf(pMarker, lengthRemaining, "%.1lf,%c,", + magneticVariation, direction); + } + else + { + length = snprintf(pMarker, lengthRemaining, ",,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = snprintf(pMarker, lengthRemaining, "%c", rmcModeIndicator); + pMarker += length; + lengthRemaining -= length; + + // hardcode Navigation Status field to 'V' + length = snprintf(pMarker, lengthRemaining, ",%c", 'V'); + + length = loc_nmea_put_checksum(sentence_RMC, sizeof(sentence_RMC), false); + + // ------------------- + // ------$--GNS------- + // ------------------- + + pMarker = sentence_GNS; + lengthRemaining = sizeof(sentence_GNS); + + length = snprintf(pMarker, lengthRemaining, "$%sGNS,%02d%02d%02d.%02d," , + talker, utcHours, utcMinutes, utcSeconds, utcMSeconds/10); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG) + { + double latitude = ref_lla.lat; + double longitude = ref_lla.lon; + char latHemisphere; + char lonHemisphere; + double latMinutes; + double lonMinutes; + + if (latitude > 0) + { + latHemisphere = 'N'; + } + else + { + latHemisphere = 'S'; + latitude *= -1.0; + } + + if (longitude < 0) + { + lonHemisphere = 'W'; + longitude *= -1.0; + } + else + { + lonHemisphere = 'E'; + } + + latMinutes = fmod(latitude * 60.0 , 60.0); + lonMinutes = fmod(longitude * 60.0 , 60.0); + + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,", + (uint8_t)floor(latitude), latMinutes, latHemisphere, + (uint8_t)floor(longitude),lonMinutes, lonHemisphere); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + length = snprintf(pMarker, lengthRemaining, "%s,", gnsModeIndicator); + + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) { + length = snprintf(pMarker, lengthRemaining, "%02d,%.1f,", + svUsedCount, locationExtended.hdop); + } + else { // no hdop + length = snprintf(pMarker, lengthRemaining, "%02d,,", + svUsedCount); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,", + locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining,","); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if ((location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ALTITUDE) && + (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL)) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,", + ref_lla.alt - locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DGNSS_DATA_AGE) + { + length = snprintf(pMarker, lengthRemaining, "%.1f,", + (float)locationExtended.dgnssDataAgeMsec / 1000); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DGNSS_REF_STATION_ID) + { + length = snprintf(pMarker, lengthRemaining, "%04d", + locationExtended.dgnssRefStationId); + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + // hardcode Navigation Status field to 'V' + length = snprintf(pMarker, lengthRemaining, ",%c", 'V'); + pMarker += length; + lengthRemaining -= length; + + length = loc_nmea_put_checksum(sentence_GNS, sizeof(sentence_GNS), false); + + // ------------------- + // ------$--GGA------- + // ------------------- + + pMarker = sentence_GGA; + lengthRemaining = sizeof(sentence_GGA); + + length = snprintf(pMarker, lengthRemaining, "$%sGGA,%02d%02d%02d.%02d," , + talker, utcHours, utcMinutes, utcSeconds, utcMSeconds/10); + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_LAT_LONG) + { + double latitude = ref_lla.lat; + double longitude = ref_lla.lon; + char latHemisphere; + char lonHemisphere; + double latMinutes; + double lonMinutes; + + if (latitude > 0) + { + latHemisphere = 'N'; + } + else + { + latHemisphere = 'S'; + latitude *= -1.0; + } + + if (longitude < 0) + { + lonHemisphere = 'W'; + longitude *= -1.0; + } + else + { + lonHemisphere = 'E'; + } + + latMinutes = fmod(latitude * 60.0 , 60.0); + lonMinutes = fmod(longitude * 60.0 , 60.0); + + length = snprintf(pMarker, lengthRemaining, "%02d%09.6lf,%c,%03d%09.6lf,%c,", + (uint8_t)floor(latitude), latMinutes, latHemisphere, + (uint8_t)floor(longitude),lonMinutes, lonHemisphere); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,,,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + // Number of satellites in use, 00-12 + if (svUsedCount > MAX_SATELLITES_IN_USE) + svUsedCount = MAX_SATELLITES_IN_USE; + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DOP) + { + length = snprintf(pMarker, lengthRemaining, "%s,%02d,%.1f,", + ggaGpsQuality, svUsedCount, locationExtended.hdop); + } + else + { // no hdop + length = snprintf(pMarker, lengthRemaining, "%s,%02d,,", + ggaGpsQuality, svUsedCount); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,M,", + locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining,",,"); + } + + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if ((location.gpsLocation.flags & LOC_GPS_LOCATION_HAS_ALTITUDE) && + (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL)) + { + length = snprintf(pMarker, lengthRemaining, "%.1lf,M,", + ref_lla.alt - locationExtended.altitudeMeanSeaLevel); + } + else + { + length = snprintf(pMarker, lengthRemaining, ",,"); + } + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DGNSS_DATA_AGE) + { + length = snprintf(pMarker, lengthRemaining, "%.1f,", + (float)locationExtended.dgnssDataAgeMsec / 1000); + } + else + { + length = snprintf(pMarker, lengthRemaining, ","); + } + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + + if (locationExtended.flags & GPS_LOCATION_EXTENDED_HAS_DGNSS_REF_STATION_ID) + { + length = snprintf(pMarker, lengthRemaining, "%04d", + locationExtended.dgnssRefStationId); + if (length < 0 || length >= lengthRemaining) + { + LOC_LOGE("NMEA Error in string formatting"); + return; + } + pMarker += length; + lengthRemaining -= length; + } + + length = loc_nmea_put_checksum(sentence_GGA, sizeof(sentence_GGA), false); + + // ------$--DTM------- + nmeaArraystr.push_back(sentence_DTM); + // ------$--RMC------- + nmeaArraystr.push_back(sentence_RMC); + if(LOC_GNSS_DATUM_PZ90 == datum_type) { + // ------$--DTM------- + nmeaArraystr.push_back(sentence_DTM); + } + // ------$--GNS------- + nmeaArraystr.push_back(sentence_GNS); + if(LOC_GNSS_DATUM_PZ90 == datum_type) { + // ------$--DTM------- + nmeaArraystr.push_back(sentence_DTM); + } + // ------$--GGA------- + nmeaArraystr.push_back(sentence_GGA); + indexOfGGA = static_cast(nmeaArraystr.size() - 1); + } + //Send blank NMEA reports for non-final fixes + else { + strlcpy(sentence, "$GPGSA,A,1,,,,,,,,,,,,,,,,", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + strlcpy(sentence, "$GPVTG,,T,,M,,N,,K,N", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + strlcpy(sentence, "$GPDTM,,,,,,,,", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + strlcpy(sentence, "$GPRMC,,V,,,,,,,,,,N,V", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + strlcpy(sentence, "$GPGNS,,,,,,N,,,,,,,V", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + + strlcpy(sentence, "$GPGGA,,,,,,0,,,,,,,,", sizeof(sentence)); + length = loc_nmea_put_checksum(sentence, sizeof(sentence), false); + nmeaArraystr.push_back(sentence); + } + + EXIT_LOG(%d, 0); +} + + + +/*=========================================================================== +FUNCTION loc_nmea_generate_sv + +DESCRIPTION + Generate NMEA sentences generated based on sv report + +DEPENDENCIES + NONE + +RETURN VALUE + 0 + +SIDE EFFECTS + N/A + +===========================================================================*/ +void loc_nmea_generate_sv(const GnssSvNotification &svNotify, + std::vector &nmeaArraystr) +{ + ENTRY_LOG(); + + char sentence[NMEA_SENTENCE_MAX_LENGTH] = {0}; + loc_sv_cache_info sv_cache_info = {}; + + //Count GPS SVs for saparating GPS from GLONASS and throw others + for (uint32_t svOffset = 0; svOffset < svNotify.count; svOffset++) { + if ((GNSS_SV_TYPE_GPS == svNotify.gnssSvs[svOffset].type) || + (GNSS_SV_TYPE_SBAS == svNotify.gnssSvs[svOffset].type)) + { + if (GNSS_SIGNAL_GPS_L5 == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.gps_l5_count++; + } else if (GNSS_SIGNAL_GPS_L2 == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.gps_l2_count++; + } else { + // GNSS_SIGNAL_GPS_L1CA, GNSS_SIGNAL_SBAS_L1 or default + // If no signal type in report, it means default L1 + sv_cache_info.gps_l1_count++; + } + } + else if (GNSS_SV_TYPE_GLONASS == svNotify.gnssSvs[svOffset].type) + { + if (GNSS_SIGNAL_GLONASS_G2 == svNotify.gnssSvs[svOffset].gnssSignalTypeMask){ + sv_cache_info.glo_g2_count++; + } else { + // GNSS_SIGNAL_GLONASS_G1 or default + // If no signal type in report, it means default G1 + sv_cache_info.glo_g1_count++; + } + } + else if (GNSS_SV_TYPE_GALILEO == svNotify.gnssSvs[svOffset].type) + { + if(GNSS_SIGNAL_GALILEO_E5A == svNotify.gnssSvs[svOffset].gnssSignalTypeMask){ + sv_cache_info.gal_e5_count++; + } else if (GNSS_SIGNAL_GALILEO_E5B == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.gal_e5b_count++; + } else { + // GNSS_SIGNAL_GALILEO_E1 or default + // If no signal type in report, it means default E1 + sv_cache_info.gal_e1_count++; + } + } + else if (GNSS_SV_TYPE_QZSS == svNotify.gnssSvs[svOffset].type) + { + if (GNSS_SIGNAL_QZSS_L5 == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.qzss_l5_count++; + } else if (GNSS_SIGNAL_QZSS_L2 == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.qzss_l2_count++; + } else { + // GNSS_SIGNAL_QZSS_L1CA or default + // If no signal type in report, it means default L1 + sv_cache_info.qzss_l1_count++; + } + } + else if (GNSS_SV_TYPE_BEIDOU == svNotify.gnssSvs[svOffset].type) + { + // cache the used in fix mask, as it will be needed to send $PQGSA + // during the position report + if (GNSS_SV_OPTIONS_USED_IN_FIX_BIT == + (svNotify.gnssSvs[svOffset].gnssSvOptionsMask & + GNSS_SV_OPTIONS_USED_IN_FIX_BIT)) + { + setSvMask(sv_cache_info.bds_used_mask, svNotify.gnssSvs[svOffset].svId); + } + if ((GNSS_SIGNAL_BEIDOU_B2AI == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) || + (GNSS_SIGNAL_BEIDOU_B2AQ == svNotify.gnssSvs[svOffset].gnssSignalTypeMask)) { + sv_cache_info.bds_b2_count++; + } else if (GNSS_SIGNAL_BEIDOU_B1C == svNotify.gnssSvs[svOffset].gnssSignalTypeMask) { + sv_cache_info.bds_b1c_count++; + } else { + // GNSS_SIGNAL_BEIDOU_B1I or default + // If no signal type in report, it means default B1I + sv_cache_info.bds_b1i_count++; + } + } + else if (GNSS_SV_TYPE_NAVIC == svNotify.gnssSvs[svOffset].type) + { + // GNSS_SIGNAL_NAVIC_L5 is the only signal type for NAVIC + sv_cache_info.navic_l5_count++; + } + } + + loc_nmea_sv_meta sv_meta; + // --------------------- + // ------$GPGSV:L1CA---- + // --------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, + GNSS_SIGNAL_GPS_L1CA, false), nmeaArraystr); + + // --------------------- + // ------$GPGSV:L5------ + // --------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, + GNSS_SIGNAL_GPS_L5, false), nmeaArraystr); + + // --------------------- + // ------$GPGSV:L2------ + // --------------------- + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GPS, + GNSS_SIGNAL_GPS_L2, false), nmeaArraystr); + + // --------------------- + // ------$GLGSV:G1------ + // --------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GLONASS, + GNSS_SIGNAL_GLONASS_G1, false), nmeaArraystr); + + // --------------------- + // ------$GLGSV:G2------ + // --------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GLONASS, + GNSS_SIGNAL_GLONASS_G2, false), nmeaArraystr); + + // --------------------- + // ------$GAGSV:E1------ + // --------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, + GNSS_SIGNAL_GALILEO_E1, false), nmeaArraystr); + + // ------------------------- + // ------$GAGSV:E5A--------- + // ------------------------- + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, + GNSS_SIGNAL_GALILEO_E5A, false), nmeaArraystr); + + // ------------------------- + // ------$GAGSV:E5B--------- + // ------------------------- + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_GALILEO, + GNSS_SIGNAL_GALILEO_E5B, false), nmeaArraystr); + + // ----------------------------- + // ------$GQGSV (QZSS):L1CA----- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, + GNSS_SIGNAL_QZSS_L1CA, false), nmeaArraystr); + + // ----------------------------- + // ------$GQGSV (QZSS):L5------- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, + GNSS_SIGNAL_QZSS_L5, false), nmeaArraystr); + + // ----------------------------- + // ------$GQGSV (QZSS):L2------- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_QZSS, + GNSS_SIGNAL_QZSS_L2, false), nmeaArraystr); + + + // ----------------------------- + // ------$GBGSV (BEIDOU:B1I)---- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, + GNSS_SIGNAL_BEIDOU_B1I, false), nmeaArraystr); + + // ----------------------------- + // ------$GBGSV (BEIDOU:B1C)---- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, + GNSS_SIGNAL_BEIDOU_B1C, false), nmeaArraystr); + + // ----------------------------- + // ------$GBGSV (BEIDOU:B2AI)--- + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_BEIDOU, + GNSS_SIGNAL_BEIDOU_B2AI, false), nmeaArraystr); + + // ----------------------------- + // ------$GIGSV (NAVIC:L5)------ + // ----------------------------- + + loc_nmea_generate_GSV(svNotify, sentence, sizeof(sentence), + loc_nmea_sv_meta_init(sv_meta, sv_cache_info, GNSS_SV_TYPE_NAVIC, + GNSS_SIGNAL_NAVIC_L5,false), nmeaArraystr); + + EXIT_LOG(%d, 0); +} diff --git a/gps/utils/loc_nmea.h b/gps/utils/loc_nmea.h new file mode 100644 index 0000000..2d98f42 --- /dev/null +++ b/gps/utils/loc_nmea.h @@ -0,0 +1,95 @@ +/* Copyright (c) 2012-2013, 2015-2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef LOC_ENG_NMEA_H +#define LOC_ENG_NMEA_H + +#include +#include +#include +#define NMEA_SENTENCE_MAX_LENGTH 200 + +/** gnss datum type */ +#define LOC_GNSS_DATUM_WGS84 0 +#define LOC_GNSS_DATUM_PZ90 1 + +/* len of semi major axis of ref ellips*/ +#define MAJA (6378137.0) +/* flattening coef of ref ellipsoid*/ +#define FLAT (1.0/298.2572235630) +/* 1st eccentricity squared*/ +#define ESQR (FLAT*(2.0 - FLAT)) +/*1 minus eccentricity squared*/ +#define OMES (1.0 - ESQR) +#define MILARCSEC2RAD (4.848136811095361e-09) +/*semi major axis */ +#define C_PZ90A (6378136.0) +/*semi minor axis */ +#define C_PZ90B (6356751.3618) +/* Transformation from WGS84 to PZ90 + * Cx,Cy,Cz,Rs,Rx,Ry,Rz,C_SYS_A,C_SYS_B*/ +const double DatumConstFromWGS84[9] = + {+0.003, +0.001, 0.000, (1.0+(0.000*1E-6)), (-0.019*MILARCSEC2RAD), + (+0.042*MILARCSEC2RAD), (-0.002*MILARCSEC2RAD), C_PZ90A, C_PZ90B}; + +/** Represents a LTP*/ +typedef struct { + double lat; + double lon; + double alt; +} LocLla; + +/** Represents a ECEF*/ +typedef struct { + double X; + double Y; + double Z; +} LocEcef; + +void loc_nmea_generate_sv(const GnssSvNotification &svNotify, + std::vector &nmeaArraystr); + +void loc_nmea_generate_pos(const UlpLocation &location, + const GpsLocationExtended &locationExtended, + const LocationSystemInfo &systemInfo, + unsigned char generate_nmea, + bool custom_gga_fix_quality, + std::vector &nmeaArraystr, + int& indexOfGGA, + bool isTagBlockGroupingEnabled); + +#define DEBUG_NMEA_MINSIZE 6 +#define DEBUG_NMEA_MAXSIZE 4096 +inline bool loc_nmea_is_debug(const char* nmea, int length) { + return ((nullptr != nmea) && + (length >= DEBUG_NMEA_MINSIZE) && (length <= DEBUG_NMEA_MAXSIZE) && + (nmea[0] == '$') && (nmea[1] == 'P') && (nmea[2] == 'Q') && (nmea[3] == 'W')); +} + +#endif // LOC_ENG_NMEA_H diff --git a/gps/utils/loc_target.cpp b/gps/utils/loc_target.cpp new file mode 100644 index 0000000..3ee42e6 --- /dev/null +++ b/gps/utils/loc_target.cpp @@ -0,0 +1,249 @@ +/* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "loc_target.h" +#include "loc_log.h" +#include + +#define APQ8064_ID_1 "109" +#define APQ8064_ID_2 "153" +#define MPQ8064_ID_1 "130" +#define MSM8930_ID_1 "142" +#define MSM8930_ID_2 "116" +#define APQ8030_ID_1 "157" +#define APQ8074_ID_1 "184" + +#define LINE_LEN 100 +#define STR_LIQUID "Liquid" +#define STR_SURF "Surf" +#define STR_MTP "MTP" +#define STR_APQ "apq" +#define STR_SDC "sdc" // alternative string for APQ targets +#define STR_QCS "qcs" // string for Gen9 APQ targets +#define STR_MSM "msm" +#define STR_SDM "sdm" // alternative string for MSM targets +#define STR_APQ_NO_WGR "baseband_apq_nowgr" +#define STR_AUTO "auto" +#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r') +#define LENGTH(s) (sizeof(s) - 1) +#define GPS_CHECK_NO_ERROR 0 +#define GPS_CHECK_NO_GPS_HW 1 + +static unsigned int gTarget = (unsigned int)-1; + +static int read_a_line(const char * file_path, char * line, int line_size) +{ + FILE *fp; + int result = 0; + + * line = '\0'; + fp = fopen(file_path, "r" ); + if( fp == NULL ) { + LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno)); + result = -1; + } else { + int len; + fgets(line, line_size, fp); + len = strlen(line); + while ('\n' == line[len-1]) { + // If there is a new line at end of string, replace it with NULL + line[len-1] = '\0'; + len--; + } + len = len < line_size - 1? len : line_size - 1; + line[len] = '\0'; + LOC_LOGD("cat %s: %s", file_path, line); + fclose(fp); + } + return result; +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length) +{ + if(baseband && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.baseband", baseband, ""); + LOC_LOGD("%s:%d]: Baseband: %s\n", __func__, __LINE__, baseband); + } + else { + LOC_LOGE("%s:%d]: NULL parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length) +{ + if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.board.platform", platform_name, ""); + LOC_LOGD("%s:%d]: Target name: %s\n", __func__, __LINE__, platform_name); + } + else { + LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_auto_platform_name(char *platform_name, int array_length) +{ + if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.hardware.type", platform_name, ""); + LOC_LOGD("%s:%d]: Autoplatform name: %s\n", __func__, __LINE__, platform_name); + } + else { + LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +/*Reads the property ro.config.low_ram to identify if this is a low ram target + Returns: + 0 if not a low ram target + 1 if this is a low ram target +*/ +int loc_identify_low_ram_target() +{ + int ret = 0; + char low_ram_target[PROPERTY_VALUE_MAX]; + property_get("ro.config.low_ram", low_ram_target, ""); + LOC_LOGd("low ram target: %s\n", low_ram_target); + return !(strncmp(low_ram_target, "true", PROPERTY_VALUE_MAX)); +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +/* Reads the soc_id node and return the soc_id value */ +void loc_get_device_soc_id(char *soc_id_value, int array_length) +{ + static const char soc_id[] = "/sys/devices/soc0/soc_id"; + static const char soc_id_dep[] = "/sys/devices/system/soc/soc0/id"; + int return_val = 0; + + if (soc_id_value && (array_length >= PROPERTY_VALUE_MAX)) { + if (!access(soc_id, F_OK)) { + return_val = read_a_line(soc_id, soc_id_value, array_length); + } else { + return_val = read_a_line(soc_id_dep, soc_id_value, array_length); + } + if (0 == return_val) { + LOC_LOGd("SOC Id value: %s\n", soc_id_value); + } else { + LOC_LOGe("Unable to read the soc_id value\n"); + } + } else { + LOC_LOGe("Null parameter or array length less than PROPERTY_VALUE_MAX\n"); + } +} + +unsigned int loc_get_target(void) +{ + if (gTarget != (unsigned int)-1) + return gTarget; + + static const char hw_platform[] = "/sys/devices/soc0/hw_platform"; + static const char hw_platform_dep[] = + "/sys/devices/system/soc/soc0/hw_platform"; + static const char mdm[] = "/target"; // mdm target we are using + + char rd_hw_platform[LINE_LEN]; + char rd_id[LINE_LEN]; + char rd_mdm[LINE_LEN]; + char baseband[LINE_LEN]; + char rd_auto_platform[LINE_LEN]; + + loc_get_target_baseband(baseband, sizeof(baseband)); + + if (!access(hw_platform, F_OK)) { + read_a_line(hw_platform, rd_hw_platform, LINE_LEN); + } else { + read_a_line(hw_platform_dep, rd_hw_platform, LINE_LEN); + } + // Get the soc-id for this device. + loc_get_device_soc_id(rd_id, sizeof(rd_id)); + + /*check automotive platform*/ + loc_get_auto_platform_name(rd_auto_platform, sizeof(rd_auto_platform)); + if( !memcmp(rd_auto_platform, STR_AUTO, LENGTH(STR_AUTO)) ) + { + gTarget = TARGET_AUTO; + goto detected; + } + + if( !memcmp(baseband, STR_APQ_NO_WGR, LENGTH(STR_APQ_NO_WGR)) ){ + + gTarget = TARGET_NO_GNSS; + goto detected; + } + + if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) || + !memcmp(baseband, STR_SDC, LENGTH(STR_SDC)) || + !memcmp(baseband, STR_QCS, LENGTH(STR_QCS)) ) { + + if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) + && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) ) + gTarget = TARGET_NO_GNSS; + else + gTarget = TARGET_APQ_SA; + } else if (((!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) || + (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) || + (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) && + !read_a_line( mdm, rd_mdm, LINE_LEN)) { + gTarget = TARGET_MDM; + } else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) || + (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) { + gTarget = TARGET_MSM_NO_SSC; + } else if ( !memcmp(baseband, STR_MSM, LENGTH(STR_MSM)) || + !memcmp(baseband, STR_SDM, LENGTH(STR_SDM)) ) { + gTarget = TARGET_DEFAULT; + } else { + gTarget = TARGET_UNKNOWN; + } + +detected: + LOC_LOGW("HAL: %s returned %d", __FUNCTION__, gTarget); + return gTarget; +} diff --git a/gps/utils/loc_target.h b/gps/utils/loc_target.h new file mode 100644 index 0000000..2dcd895 --- /dev/null +++ b/gps/utils/loc_target.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_TARGET_H +#define LOC_TARGET_H +#define TARGET_SET(gnss,ssc) ( (gnss<<1)|ssc ) +#define TARGET_DEFAULT TARGET_SET(GNSS_MSM, HAS_SSC) +#define TARGET_MDM TARGET_SET(GNSS_MDM, HAS_SSC) +#define TARGET_APQ_SA TARGET_SET(GNSS_GSS, NO_SSC) +#define TARGET_NO_GNSS TARGET_SET(GNSS_NONE, NO_SSC) +#define TARGET_MSM_NO_SSC TARGET_SET(GNSS_MSM, NO_SSC) +#define TARGET_AUTO TARGET_SET(GNSS_AUTO, NO_SSC) +#define TARGET_UNKNOWN TARGET_SET(GNSS_UNKNOWN, NO_SSC) +#define getTargetGnssType(target) (target>>1) + +#ifdef __cplusplus +extern "C" +{ +#endif + +unsigned int loc_get_target(void); + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_auto_platform_name(char *platform_name, int array_length); +int loc_identify_low_ram_target(); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_device_soc_id(char *soc_id_value, int array_length); + +/* Please remember to update 'target_name' in loc_log.cpp, + if do any changes to this enum. */ +typedef enum { + GNSS_NONE = 0, + GNSS_MSM, + GNSS_GSS, + GNSS_MDM, + GNSS_AUTO, + GNSS_UNKNOWN +}GNSS_TARGET; + +typedef enum { + NO_SSC = 0, + HAS_SSC +}SSC_TYPE; + +#ifdef __cplusplus +} +#endif + +#endif /*LOC_TARGET_H*/ diff --git a/gps/utils/loc_timer.h b/gps/utils/loc_timer.h new file mode 100644 index 0000000..fff0c46 --- /dev/null +++ b/gps/utils/loc_timer.h @@ -0,0 +1,74 @@ +/* Copyright (c) 2013,2015 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOC_DELAY_H__ +#define __LOC_DELAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include +#include +#include +/* + user_data: client context pointer, passthrough. Originally received + from calling client when loc_timer_start() is called. + result: 0 if timer successfully timed out; else timer failed. +*/ +typedef void (*loc_timer_callback)(void *user_data, int32_t result); + + +/* + delay_msec: timeout value for the timer. + cb_func: callback function pointer, implemented by client. + Can not be NULL. + user_data: client context pointer, passthrough. Will be + returned when loc_timer_callback() is called. + wakeOnExpire: true if to wake up CPU (if sleeping) upon timer + expiration and notify the client. + false if to wait until next time CPU wakes up (if + sleeping) and then notify the client. + Returns the handle, which can be used to stop the timer + NULL, if timer start fails (e.g. if cb_func is NULL). +*/ +void* loc_timer_start(uint64_t delay_msec, + loc_timer_callback cb_func, + void *user_data, + bool wake_on_expire=false); + +/* + handle becomes invalid upon the return of the callback +*/ +void loc_timer_stop(void*& handle); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif //__LOC_DELAY_H__ diff --git a/gps/utils/log_util.h b/gps/utils/log_util.h new file mode 100644 index 0000000..33aa6e2 --- /dev/null +++ b/gps/utils/log_util.h @@ -0,0 +1,291 @@ +/* Copyright (c) 2011-2014, 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __LOG_UTIL_H__ +#define __LOG_UTIL_H__ + +#include +#include +#if defined (USE_ANDROID_LOGGING) || defined (ANDROID) +// Android and LE targets with logcat support +#include +#include +#include + +#elif defined (USE_GLIB) +// LE targets with no logcat support +#include +#include +#include +#include +#include +#include + +#ifndef LOG_TAG +#define LOG_TAG "GPS_UTILS" +#endif /* LOG_TAG */ + +// LE targets with no logcat support +#if defined(FEATURE_EXTERNAL_AP) || defined(USE_SYSLOG_LOGGING) +#include +#define ALOGE(...) syslog(LOG_ERR, "LOC_LOGE: " __VA_ARGS__); +#define ALOGW(...) syslog(LOG_WARNING, "LOC_LOGW: " __VA_ARGS__); +#define ALOGI(...) syslog(LOG_NOTICE, "LOC_LOGI: " __VA_ARGS__); +#define ALOGD(...) syslog(LOG_DEBUG, "LOC_LOGD: " __VA_ARGS__); +#define ALOGV(...) syslog(LOG_NOTICE, "LOC_LOGV: " __VA_ARGS__); +#else /* FEATURE_EXTERNAL_AP */ +#define TS_PRINTF(format, x...) \ +{ \ + struct timeval tv; \ + struct timezone tz; \ + int hh, mm, ss; \ + gettimeofday(&tv, &tz); \ + hh = tv.tv_sec/3600%24; \ + mm = (tv.tv_sec%3600)/60; \ + ss = tv.tv_sec%60; \ + fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec, ##x); \ +} + +#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGW(format, x...) TS_PRINTF("W/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGI(format, x...) TS_PRINTF("I/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGD(format, x...) TS_PRINTF("D/%s (%d): " format , LOG_TAG, getpid(), ##x) +#define ALOGV(format, x...) TS_PRINTF("V/%s (%d): " format , LOG_TAG, getpid(), ##x) +#endif /* FEATURE_EXTERNAL_AP */ + +#endif /* #if defined (USE_ANDROID_LOGGING) || defined (ANDROID) */ + +#ifdef __cplusplus +extern "C" +{ +#endif +/*============================================================================= + * + * LOC LOGGER TYPE DECLARATION + * + *============================================================================*/ +/* LOC LOGGER */ +typedef struct loc_logger_s +{ + unsigned long DEBUG_LEVEL; + unsigned long TIMESTAMP; + bool LOG_BUFFER_ENABLE; +} loc_logger_s_type; + + +/*============================================================================= + * + * EXTERNAL DATA + * + *============================================================================*/ + +// Logging Improvements +extern const char *loc_logger_boolStr[]; + +extern loc_logger_s_type loc_logger; +extern const char *boolStr[]; +extern const char VOID_RET[]; +extern const char FROM_AFW[]; +extern const char TO_MODEM[]; +extern const char FROM_MODEM[]; +extern const char TO_AFW[]; +extern const char EXIT_TAG[]; +extern const char ENTRY_TAG[]; +extern const char EXIT_ERROR_TAG[]; + +#define BUILD_TYPE_PROP_NA 0 +#define BUILD_TYPE_PROP_USER 1 +#define BUILD_TYPE_PROP_USERDEBUG 2 +#define BUILD_TYPE_PROP_INVALID 3 +extern int build_type_prop; + +/*============================================================================= + * + * MODULE EXPORTED FUNCTIONS + * + *============================================================================*/ +inline void loc_logger_init(unsigned long debug, unsigned long timestamp) +{ + loc_logger.DEBUG_LEVEL = debug; + + if (BUILD_TYPE_PROP_NA == build_type_prop) { + char value[PROPERTY_VALUE_MAX] = "NA"; + property_get("ro.build.type", value, "userdebug"); + if (0 == strcmp(value, "user")) { + build_type_prop = BUILD_TYPE_PROP_USER; + } else if (0 == strcmp(value, "userdebug")) { + build_type_prop = BUILD_TYPE_PROP_USERDEBUG; + } else { + build_type_prop = BUILD_TYPE_PROP_INVALID; + } + } + + if (BUILD_TYPE_PROP_USER == build_type_prop) { + // force user builds to 2 or less + if (loc_logger.DEBUG_LEVEL > 2) { + loc_logger.DEBUG_LEVEL = 2; + } + } + + loc_logger.TIMESTAMP = timestamp; +} + +inline void log_buffer_init(bool enabled) { + loc_logger.LOG_BUFFER_ENABLE = enabled; +} +extern void log_tag_level_map_init(); +extern int get_tag_log_level(const char* tag); +extern char* get_timestamp(char* str, unsigned long buf_size); +extern void log_buffer_insert(char *str, unsigned long buf_size, int level); +/*============================================================================= + * + * LOGGING BUFFER MACROS + * + *============================================================================*/ +#ifndef LOG_NDEBUG +#define LOG_NDEBUG 0 +#endif +#define TOTAL_LOG_LEVELS 5 +#define LOGGING_BUFFER_MAX_LEN 1024 +#define IF_LOG_BUFFER_ENABLE if (loc_logger.LOG_BUFFER_ENABLE) +#define INSERT_BUFFER(flag, level, format, x...) \ +{ \ + IF_LOG_BUFFER_ENABLE { \ + if (flag == 0) { \ + char timestr[32]; \ + get_timestamp(timestr, sizeof(timestr)); \ + char log_str[LOGGING_BUFFER_MAX_LEN]; \ + snprintf(log_str, LOGGING_BUFFER_MAX_LEN, "%s %d %ld %s :" format "\n", \ + timestr, getpid(), syscall(SYS_gettid), LOG_TAG==NULL ? "": LOG_TAG, ##x);\ + log_buffer_insert(log_str, sizeof(log_str), level); \ + } \ + } \ +} + +#ifndef DEBUG_DMN_LOC_API + +/* LOGGING MACROS */ +/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp + if that value remains unchanged, it means gps.conf did not + provide a value and we default to the initial value to use + Android's logging levels*/ + + +/* Tag based logging control MACROS */ +/* The logic is like this: + * 1, LOCAL_LOG_LEVEL is defined as a static variable in log_util.h, + * then all source files which includes log_util.h will have its own LOCAL_LOG_LEVEL variable; + * 2, For each source file, + * 2.1, First time when LOC_LOG* is invoked(its LOCAL_LOG_LEVEL == -1), + * Set the tag based log level according to the map; + * If this tag isn't found in map, set local debug level as global loc_logger.DEBUG_LEVEL; + * 2.2, If not the first time, use its LOCAL_LOG_LEVEL as the debug level of this tag. +*/ +static int LOCAL_LOG_LEVEL = -1; +#define IF_LOC_LOG(x) \ + if (((LOCAL_LOG_LEVEL == -1 && (LOCAL_LOG_LEVEL = get_tag_log_level(LOG_TAG)) >= x) ||\ + LOCAL_LOG_LEVEL >= x) && LOCAL_LOG_LEVEL <= 5) + +#define IF_LOC_LOGE IF_LOC_LOG(1) +#define IF_LOC_LOGW IF_LOC_LOG(2) +#define IF_LOC_LOGI IF_LOC_LOG(3) +#define IF_LOC_LOGD IF_LOC_LOG(4) +#define IF_LOC_LOGV IF_LOC_LOG(5) + +#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 0, __VA_ARGS__);} +#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 1, __VA_ARGS__);} +#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 2, __VA_ARGS__);} +#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 3, __VA_ARGS__);} +#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); INSERT_BUFFER(LOG_NDEBUG, 4, __VA_ARGS__);} + +#else /* DEBUG_DMN_LOC_API */ + +#define LOC_LOGE(...) ALOGE(__VA_ARGS__) +#define LOC_LOGW(...) ALOGW(__VA_ARGS__) +#define LOC_LOGI(...) ALOGI(__VA_ARGS__) +#define LOC_LOGD(...) ALOGD(__VA_ARGS__) +#define LOC_LOGV(...) ALOGV(__VA_ARGS__) + +#endif /* DEBUG_DMN_LOC_API */ + +/*============================================================================= + * + * LOGGING IMPROVEMENT MACROS + * + *============================================================================*/ +#define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL) \ + do { \ + if (loc_logger.TIMESTAMP) { \ + char ts[32]; \ + LOC_LOG("[%s] %s %s line %d " #SPEC, \ + get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \ + } else { \ + LOC_LOG("%s %s line %d " #SPEC, \ + ID, WHAT, __LINE__, VAL); \ + } \ + } while(0) + +#define LOC_LOG_HEAD(fmt) "%s:%d] " fmt +#define LOC_LOGv(fmt,...) LOC_LOGV(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define LOC_LOGw(fmt,...) LOC_LOGW(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define LOC_LOGi(fmt,...) LOC_LOGI(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define LOC_LOGd(fmt,...) LOC_LOGD(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define LOC_LOGe(fmt,...) LOC_LOGE(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL) +#define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL) +#define LOG_E(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGE, ID, WHAT, SPEC, VAL) +#define LOG_D(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGD, ID, WHAT, SPEC, VAL) + +#define ENTRY_LOG() LOG_V(ENTRY_TAG, __FUNCTION__, %s, "") +#define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL) +#define EXIT_LOG_WITH_ERROR(SPEC, VAL) \ + if (VAL != 0) { \ + LOG_E(EXIT_ERROR_TAG, __FUNCTION__, SPEC, VAL); \ + } else { \ + LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL); \ + } + + +// Used for logging callflow from Android Framework +#define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __FUNCTION__, %s, "") +// Used for logging callflow to Modem +#define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __FUNCTION__, SPEC, VAL) +// Used for logging callflow from Modem(TO_MODEM, __FUNCTION__, %s, "") +#define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __FUNCTION__, SPEC, VAL) +// Used for logging high frequency callflow from Modem(TO_MODEM, __FUNCTION__, %s, "") +#define MODEM_LOG_CALLFLOW_DEBUG(SPEC, VAL) LOG_D(FROM_MODEM, __FUNCTION__, SPEC, VAL) +// Used for logging callflow to Android Framework +#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL) + +#ifdef __cplusplus +} +#endif + +#endif // __LOG_UTIL_H__ diff --git a/gps/utils/msg_q.c b/gps/utils/msg_q.c new file mode 100644 index 0000000..3383960 --- /dev/null +++ b/gps/utils/msg_q.c @@ -0,0 +1,380 @@ +/* Copyright (c) 2011-2012, 2014, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Uncomment to log verbose logs +#define LOG_NDEBUG 1 +#define LOG_TAG "LocSvc_utils_q" +#include +#include +#include +#include +#include +#include "linked_list.h" +#include "msg_q.h" + +typedef struct msg_q { + void* msg_list; /* Linked list to store information */ + pthread_cond_t list_cond; /* Condition variable for waiting on msg queue */ + pthread_mutex_t list_mutex; /* Mutex for exclusive access to message queue */ + int unblocked; /* Has this message queue been unblocked? */ +} msg_q; + +/*=========================================================================== +FUNCTION convert_linked_list_err_type + +DESCRIPTION + Converts from one set of enum values to another. + + linked_list_val: Value to convert to msg_q_enum_type + +DEPENDENCIES + N/A + +RETURN VALUE + Corresponding linked_list_enum_type in msg_q_enum_type + +SIDE EFFECTS + N/A + +===========================================================================*/ +static msq_q_err_type convert_linked_list_err_type(linked_list_err_type linked_list_val) +{ + switch( linked_list_val ) + { + case eLINKED_LIST_SUCCESS: + return eMSG_Q_SUCCESS; + case eLINKED_LIST_INVALID_PARAMETER: + return eMSG_Q_INVALID_PARAMETER; + case eLINKED_LIST_INVALID_HANDLE: + return eMSG_Q_INVALID_HANDLE; + case eLINKED_LIST_UNAVAILABLE_RESOURCE: + return eMSG_Q_UNAVAILABLE_RESOURCE; + case eLINKED_LIST_INSUFFICIENT_BUFFER: + return eMSG_Q_INSUFFICIENT_BUFFER; + + case eLINKED_LIST_FAILURE_GENERAL: + default: + return eMSG_Q_FAILURE_GENERAL; + } +} + +/* ----------------------- END INTERNAL FUNCTIONS ---------------------------------------- */ + +/*=========================================================================== + + FUNCTION: msg_q_init + + ===========================================================================*/ +msq_q_err_type msg_q_init(void** msg_q_data) +{ + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* tmp_msg_q; + tmp_msg_q = (msg_q*)calloc(1, sizeof(msg_q)); + if( tmp_msg_q == NULL ) + { + LOC_LOGE("%s: Unable to allocate space for message queue!\n", __FUNCTION__); + return eMSG_Q_FAILURE_GENERAL; + } + + if( linked_list_init(&tmp_msg_q->msg_list) != 0 ) + { + LOC_LOGE("%s: Unable to initialize storage list!\n", __FUNCTION__); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + if( pthread_mutex_init(&tmp_msg_q->list_mutex, NULL) != 0 ) + { + LOC_LOGE("%s: Unable to initialize list mutex!\n", __FUNCTION__); + linked_list_destroy(&tmp_msg_q->msg_list); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + if( pthread_cond_init(&tmp_msg_q->list_cond, NULL) != 0 ) + { + LOC_LOGE("%s: Unable to initialize msg q cond var!\n", __FUNCTION__); + linked_list_destroy(&tmp_msg_q->msg_list); + pthread_mutex_destroy(&tmp_msg_q->list_mutex); + free(tmp_msg_q); + return eMSG_Q_FAILURE_GENERAL; + } + + tmp_msg_q->unblocked = 0; + + *msg_q_data = tmp_msg_q; + + return eMSG_Q_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: msg_q_init2 + + ===========================================================================*/ +const void* msg_q_init2() +{ + void* q = NULL; + if (eMSG_Q_SUCCESS != msg_q_init(&q)) { + q = NULL; + } + return q; +} + +/*=========================================================================== + + FUNCTION: msg_q_destroy + + ===========================================================================*/ +msq_q_err_type msg_q_destroy(void** msg_q_data) +{ + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)*msg_q_data; + + linked_list_destroy(&p_msg_q->msg_list); + pthread_mutex_destroy(&p_msg_q->list_mutex); + pthread_cond_destroy(&p_msg_q->list_cond); + + p_msg_q->unblocked = 0; + + free(*msg_q_data); + *msg_q_data = NULL; + + return eMSG_Q_SUCCESS; +} + +/*=========================================================================== + + FUNCTION: msg_q_snd + + ===========================================================================*/ +msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*)) +{ + msq_q_err_type rv; + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + if( msg_obj == NULL ) + { + LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + pthread_mutex_lock(&p_msg_q->list_mutex); + LOC_LOGV("%s: Sending message with handle = %p\n", __FUNCTION__, msg_obj); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + rv = convert_linked_list_err_type(linked_list_add(p_msg_q->msg_list, msg_obj, dealloc)); + + /* Show data is in the message queue. */ + pthread_cond_signal(&p_msg_q->list_cond); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGV("%s: Finished Sending message with handle = %p\n", __FUNCTION__, msg_obj); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_rcv + + ===========================================================================*/ +msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj) +{ + msq_q_err_type rv; + if( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + if( msg_obj == NULL ) + { + LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + pthread_mutex_lock(&p_msg_q->list_mutex); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + /* Wait for data in the message queue */ + while( linked_list_empty(p_msg_q->msg_list) && !p_msg_q->unblocked ) + { + pthread_cond_wait(&p_msg_q->list_cond, &p_msg_q->list_mutex); + } + + rv = convert_linked_list_err_type(linked_list_remove(p_msg_q->msg_list, msg_obj)); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGV("%s: Received message %p rv = %d\n", __FUNCTION__, *msg_obj, rv); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_rmv + + ===========================================================================*/ +msq_q_err_type msg_q_rmv(void* msg_q_data, void** msg_obj) +{ + msq_q_err_type rv; + if (msg_q_data == NULL) { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + if (msg_obj == NULL) { + LOC_LOGE("%s: Invalid msg_obj parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_PARAMETER; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + pthread_mutex_lock(&p_msg_q->list_mutex); + + if (p_msg_q->unblocked) { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + if (linked_list_empty(p_msg_q->msg_list)) { + LOC_LOGW("%s: list is empty !!\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eLINKED_LIST_EMPTY; + } + + rv = convert_linked_list_err_type(linked_list_remove(p_msg_q->msg_list, msg_obj)); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGV("%s: Removed message %p rv = %d\n", __FUNCTION__, *msg_obj, rv); + + return rv; +} + + + +/*=========================================================================== + + FUNCTION: msg_q_flush + + ===========================================================================*/ +msq_q_err_type msg_q_flush(void* msg_q_data) +{ + msq_q_err_type rv; + if ( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + + LOC_LOGD("%s: Flushing Message Queue\n", __FUNCTION__); + + pthread_mutex_lock(&p_msg_q->list_mutex); + + /* Remove all elements from the list */ + rv = convert_linked_list_err_type(linked_list_flush(p_msg_q->msg_list)); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGD("%s: Message Queue flushed\n", __FUNCTION__); + + return rv; +} + +/*=========================================================================== + + FUNCTION: msg_q_unblock + + ===========================================================================*/ +msq_q_err_type msg_q_unblock(void* msg_q_data) +{ + if ( msg_q_data == NULL ) + { + LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); + return eMSG_Q_INVALID_HANDLE; + } + + msg_q* p_msg_q = (msg_q*)msg_q_data; + pthread_mutex_lock(&p_msg_q->list_mutex); + + if( p_msg_q->unblocked ) + { + LOC_LOGE("%s: Message queue has been unblocked.\n", __FUNCTION__); + pthread_mutex_unlock(&p_msg_q->list_mutex); + return eMSG_Q_UNAVAILABLE_RESOURCE; + } + + LOC_LOGD("%s: Unblocking Message Queue\n", __FUNCTION__); + /* Unblocking message queue */ + p_msg_q->unblocked = 1; + + /* Allow all the waiters to wake up */ + pthread_cond_broadcast(&p_msg_q->list_cond); + + pthread_mutex_unlock(&p_msg_q->list_mutex); + + LOC_LOGD("%s: Message Queue unblocked\n", __FUNCTION__); + + return eMSG_Q_SUCCESS; +} diff --git a/gps/utils/msg_q.h b/gps/utils/msg_q.h new file mode 100644 index 0000000..16df494 --- /dev/null +++ b/gps/utils/msg_q.h @@ -0,0 +1,230 @@ +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MSG_Q_H__ +#define __MSG_Q_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +/** Linked List Return Codes */ +typedef enum +{ + eMSG_Q_SUCCESS = 0, + /**< Request was successful. */ + eMSG_Q_FAILURE_GENERAL = -1, + /**< Failed because of a general failure. */ + eMSG_Q_INVALID_PARAMETER = -2, + /**< Failed because the request contained invalid parameters. */ + eMSG_Q_INVALID_HANDLE = -3, + /**< Failed because an invalid handle was specified. */ + eMSG_Q_UNAVAILABLE_RESOURCE = -4, + /**< Failed because an there were not enough resources. */ + eMSG_Q_INSUFFICIENT_BUFFER = -5, + /**< Failed because an the supplied buffer was too small. */ +}msq_q_err_type; + +/*=========================================================================== +FUNCTION msg_q_init + +DESCRIPTION + Initializes internal structures for message queue. + + msg_q_data: pointer to an opaque Q handle to be returned; NULL if fails + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_init(void** msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_init2 + +DESCRIPTION + Initializes internal structures for message queue. + +DEPENDENCIES + N/A + +RETURN VALUE + opaque handle to the Q created; NULL if create fails + +SIDE EFFECTS + N/A + +===========================================================================*/ +const void* msg_q_init2(); + +/*=========================================================================== +FUNCTION msg_q_destroy + +DESCRIPTION + Releases internal structures for message queue. + + msg_q_data: State of message queue to be released. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_destroy(void** msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_snd + +DESCRIPTION + Sends data to the message queue. The passed in data pointer + is not modified or freed. Passed in msg_obj is expected to live throughout + the use of the msg_q (i.e. data is not allocated internally) + + msg_q_data: Message Queue to add the element to. + msgp: Pointer to data to add into message queue. + dealloc: Function used to deallocate memory for this element. Pass NULL + if you do not want data deallocated during a flush operation + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*)); + +/*=========================================================================== +FUNCTION msg_q_rcv + +DESCRIPTION + Retrieves data from the message queue. msg_obj is the oldest message received + and pointer is simply removed from message queue. + + msg_q_data: Message Queue to copy data from into msgp. + msg_obj: Pointer to space to copy msg_q contents to. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj); + +/*=========================================================================== +FUNCTION msg_q_rmv + +DESCRIPTION + Remove data from the message queue. msg_obj is the oldest message received + and pointer is simply removed from message queue. + + msg_q_data: Message Queue to copy data from into msgp. + msg_obj: Pointer to space to copy msg_q contents to. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_rmv(void* msg_q_data, void** msg_obj); + + +/*=========================================================================== +FUNCTION msg_q_flush + +DESCRIPTION + Function removes all elements from the message queue. + + msg_q_data: Message Queue to remove elements from. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_flush(void* msg_q_data); + +/*=========================================================================== +FUNCTION msg_q_unblock + +DESCRIPTION + This function will stop use of the message queue. All waiters will wake up + and likely receive nothing from the queue resulting in a negative return + value. The message queue can no longer be used until it is destroyed + and initialized again after calling this function. + + msg_q_data: Message queue to unblock. + +DEPENDENCIES + N/A + +RETURN VALUE + Look at error codes above. + +SIDE EFFECTS + N/A + +===========================================================================*/ +msq_q_err_type msg_q_unblock(void* msg_q_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MSG_Q_H__ */ diff --git a/gpt-utils/Android.bp b/gpt-utils/Android.bp new file mode 100644 index 0000000..b3a5f1c --- /dev/null +++ b/gpt-utils/Android.bp @@ -0,0 +1,41 @@ +// +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +cc_library { + name: "libgptutils.xiaomi_holi", + vendor: true, + recovery_available: true, + shared_libs: [ + "libcutils", + "liblog", + "libz", + ], + cflags: [ + "-Wall", + "-Werror", + "-D_BSG_FRAMEWORK_KERNEL_HEADERS", + ], + srcs: [ + "gpt-utils.cpp", + "recovery-ufs-bsg.cpp", + ], + owner: "qti", + header_libs: [ + "generated_kernel_headers", + ], + export_include_dirs: ["."], +} diff --git a/gpt-utils/gpt-utils.cpp b/gpt-utils/gpt-utils.cpp new file mode 100644 index 0000000..58fc93a --- /dev/null +++ b/gpt-utils/gpt-utils.cpp @@ -0,0 +1,1519 @@ +/* + * Copyright (c) 2013,2016,2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _LARGEFILE64_SOURCE /* enable lseek64() */ + +/****************************************************************************** + * INCLUDE SECTION + ******************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include + + +#define LOG_TAG "gpt-utils" +#include +#include +#include "gpt-utils.h" +#include +#include + + +/****************************************************************************** + * DEFINE SECTION + ******************************************************************************/ +#define BLK_DEV_FILE "/dev/block/mmcblk0" +/* list the names of the backed-up partitions to be swapped */ +/* extension used for the backup partitions - tzbak, abootbak, etc. */ +#define BAK_PTN_NAME_EXT "bak" +#define XBL_PRIMARY "/dev/block/bootdevice/by-name/xbl" +#define XBL_BACKUP "/dev/block/bootdevice/by-name/xblbak" +#define XBL_AB_PRIMARY "/dev/block/bootdevice/by-name/xbl_a" +#define XBL_AB_SECONDARY "/dev/block/bootdevice/by-name/xbl_b" +/* GPT defines */ +#define MAX_LUNS 26 +//This will allow us to get the root lun path from the path to the partition. +//i.e: from /dev/block/sdaXXX get /dev/block/sda. The assumption here is that +//the boot critical luns lie between sda to sdz which is acceptable because +//only user added external disks,etc would lie beyond that limit which do not +//contain partitions that interest us here. +#define PATH_TRUNCATE_LOC (sizeof("/dev/block/sda") - 1) + +//From /dev/block/sda get just sda +#define LUN_NAME_START_LOC (sizeof("/dev/block/") - 1) +#define BOOT_LUN_A_ID 1 +#define BOOT_LUN_B_ID 2 +/****************************************************************************** + * MACROS + ******************************************************************************/ + + +#define GET_4_BYTES(ptr) ((uint32_t) *((uint8_t *)(ptr)) | \ + ((uint32_t) *((uint8_t *)(ptr) + 1) << 8) | \ + ((uint32_t) *((uint8_t *)(ptr) + 2) << 16) | \ + ((uint32_t) *((uint8_t *)(ptr) + 3) << 24)) + +#define GET_8_BYTES(ptr) ((uint64_t) *((uint8_t *)(ptr)) | \ + ((uint64_t) *((uint8_t *)(ptr) + 1) << 8) | \ + ((uint64_t) *((uint8_t *)(ptr) + 2) << 16) | \ + ((uint64_t) *((uint8_t *)(ptr) + 3) << 24) | \ + ((uint64_t) *((uint8_t *)(ptr) + 4) << 32) | \ + ((uint64_t) *((uint8_t *)(ptr) + 5) << 40) | \ + ((uint64_t) *((uint8_t *)(ptr) + 6) << 48) | \ + ((uint64_t) *((uint8_t *)(ptr) + 7) << 56)) + +#define PUT_4_BYTES(ptr, y) *((uint8_t *)(ptr)) = (y) & 0xff; \ + *((uint8_t *)(ptr) + 1) = ((y) >> 8) & 0xff; \ + *((uint8_t *)(ptr) + 2) = ((y) >> 16) & 0xff; \ + *((uint8_t *)(ptr) + 3) = ((y) >> 24) & 0xff; + +/****************************************************************************** + * TYPES + ******************************************************************************/ +using namespace std; +enum gpt_state { + GPT_OK = 0, + GPT_BAD_SIGNATURE, + GPT_BAD_CRC +}; +//List of LUN's containing boot critical images. +//Required in the case of UFS devices +struct update_data { + char lun_list[MAX_LUNS][PATH_MAX]; + uint32_t num_valid_entries; +}; + +int32_t set_boot_lun(char *sg_dev,uint8_t boot_lun_id); +/****************************************************************************** + * FUNCTIONS + ******************************************************************************/ +/** + * ========================================================================== + * + * \brief Read/Write len bytes from/to block dev + * + * \param [in] fd block dev file descriptor (returned from open) + * \param [in] rw RW flag: 0 - read, != 0 - write + * \param [in] offset block dev offset [bytes] - RW start position + * \param [in] buf Pointer to the buffer containing the data + * \param [in] len RW size in bytes. Buf must be at least that big + * + * \return 0 on success + * + * ========================================================================== + */ +static int blk_rw(int fd, int rw, int64_t offset, uint8_t *buf, unsigned len) +{ + int r; + + if (lseek64(fd, offset, SEEK_SET) < 0) { + fprintf(stderr, "block dev lseek64 %" PRIi64 " failed: %s\n", offset, + strerror(errno)); + return -1; + } + + if (rw) + r = write(fd, buf, len); + else + r = read(fd, buf, len); + + if (r < 0) + fprintf(stderr, "block dev %s failed: %s\n", rw ? "write" : "read", + strerror(errno)); + else + r = 0; + + return r; +} + + + +/** + * ========================================================================== + * + * \brief Search within GPT for partition entry with the given name + * or it's backup twin (name-bak). + * + * \param [in] ptn_name Partition name to seek + * \param [in] pentries_start Partition entries array start pointer + * \param [in] pentries_end Partition entries array end pointer + * \param [in] pentry_size Single partition entry size [bytes] + * + * \return First partition entry pointer that matches the name or NULL + * + * ========================================================================== + */ +static uint8_t *gpt_pentry_seek(const char *ptn_name, + const uint8_t *pentries_start, + const uint8_t *pentries_end, + uint32_t pentry_size) +{ + char *pentry_name; + unsigned len = strlen(ptn_name); + unsigned i; + char name8[MAX_GPT_NAME_SIZE] = {0}; // initialize with null + + for (pentry_name = (char *) (pentries_start + PARTITION_NAME_OFFSET); + pentry_name < (char *) pentries_end; + pentry_name += pentry_size) { + + /* Partition names in GPT are UTF-16 - ignoring UTF-16 2nd byte */ + for (i = 0; i < sizeof(name8) / 2; i++) + name8[i] = pentry_name[i * 2]; + name8[i] = '\0'; + + if (!strncmp(ptn_name, name8, len)) { + if (name8[len] == 0 || !strcmp(&name8[len], BAK_PTN_NAME_EXT)) + return (uint8_t *) (pentry_name - PARTITION_NAME_OFFSET); + } + } + + return NULL; +} + + + +/** + * ========================================================================== + * + * \brief Swaps boot chain in GPT partition entries array + * + * \param [in] pentries_start Partition entries array start + * \param [in] pentries_end Partition entries array end + * \param [in] pentry_size Single partition entry size + * + * \return 0 on success, 1 if no backup partitions found + * + * ========================================================================== + */ +static int gpt_boot_chain_swap(const uint8_t *pentries_start, + const uint8_t *pentries_end, + uint32_t pentry_size) +{ + const char ptn_swap_list[][MAX_GPT_NAME_SIZE] = { PTN_SWAP_LIST }; + + int backup_not_found = 1; + unsigned i; + + for (i = 0; i < ARRAY_SIZE(ptn_swap_list); i++) { + uint8_t *ptn_entry; + uint8_t *ptn_bak_entry; + uint8_t ptn_swap[PTN_ENTRY_SIZE]; + //Skip the xbl partition on UFS devices. That is handled + //seperately. + if (gpt_utils_is_ufs_device() && !strncmp(ptn_swap_list[i], + PTN_XBL, + strlen(PTN_XBL))) + continue; + + ptn_entry = gpt_pentry_seek(ptn_swap_list[i], pentries_start, + pentries_end, pentry_size); + if (ptn_entry == NULL) + continue; + + ptn_bak_entry = gpt_pentry_seek(ptn_swap_list[i], + ptn_entry + pentry_size, pentries_end, pentry_size); + if (ptn_bak_entry == NULL) { + fprintf(stderr, "'%s' partition not backup - skip safe update\n", + ptn_swap_list[i]); + continue; + } + + /* swap primary <-> backup partition entries */ + memcpy(ptn_swap, ptn_entry, PTN_ENTRY_SIZE); + memcpy(ptn_entry, ptn_bak_entry, PTN_ENTRY_SIZE); + memcpy(ptn_bak_entry, ptn_swap, PTN_ENTRY_SIZE); + backup_not_found = 0; + } + + return backup_not_found; +} + + + +/** + * ========================================================================== + * + * \brief Sets secondary GPT boot chain + * + * \param [in] fd block dev file descriptor + * \param [in] boot Boot chain to switch to + * + * \return 0 on success + * + * ========================================================================== + */ +static int gpt2_set_boot_chain(int fd, enum boot_chain boot) +{ + int64_t gpt2_header_offset; + uint64_t pentries_start_offset; + uint32_t gpt_header_size; + uint32_t pentry_size; + uint32_t pentries_array_size; + + uint8_t *gpt_header = NULL; + uint8_t *pentries = NULL; + uint32_t crc; + uint32_t crc_zero; + uint32_t blk_size = 0; + int r; + + + crc_zero = crc32(0L, Z_NULL, 0); + if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { + fprintf(stderr, "Failed to get GPT device block size: %s\n", + strerror(errno)); + r = -1; + goto EXIT; + } + gpt_header = (uint8_t*)malloc(blk_size); + if (!gpt_header) { + fprintf(stderr, "Failed to allocate memory to hold GPT block\n"); + r = -1; + goto EXIT; + } + gpt2_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; + if (gpt2_header_offset < 0) { + fprintf(stderr, "Getting secondary GPT header offset failed: %s\n", + strerror(errno)); + r = -1; + goto EXIT; + } + + /* Read primary GPT header from block dev */ + r = blk_rw(fd, 0, blk_size, gpt_header, blk_size); + + if (r) { + fprintf(stderr, "Failed to read primary GPT header from blk dev\n"); + goto EXIT; + } + pentries_start_offset = + GET_8_BYTES(gpt_header + PENTRIES_OFFSET) * blk_size; + pentry_size = GET_4_BYTES(gpt_header + PENTRY_SIZE_OFFSET); + pentries_array_size = + GET_4_BYTES(gpt_header + PARTITION_COUNT_OFFSET) * pentry_size; + + pentries = (uint8_t *) calloc(1, pentries_array_size); + if (pentries == NULL) { + fprintf(stderr, + "Failed to alloc memory for GPT partition entries array\n"); + r = -1; + goto EXIT; + } + /* Read primary GPT partititon entries array from block dev */ + r = blk_rw(fd, 0, pentries_start_offset, pentries, pentries_array_size); + if (r) + goto EXIT; + + crc = crc32(crc_zero, pentries, pentries_array_size); + if (GET_4_BYTES(gpt_header + PARTITION_CRC_OFFSET) != crc) { + fprintf(stderr, "Primary GPT partition entries array CRC invalid\n"); + r = -1; + goto EXIT; + } + + /* Read secondary GPT header from block dev */ + r = blk_rw(fd, 0, gpt2_header_offset, gpt_header, blk_size); + if (r) + goto EXIT; + + gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET); + pentries_start_offset = + GET_8_BYTES(gpt_header + PENTRIES_OFFSET) * blk_size; + + if (boot == BACKUP_BOOT) { + r = gpt_boot_chain_swap(pentries, pentries + pentries_array_size, + pentry_size); + if (r) + goto EXIT; + } + + crc = crc32(crc_zero, pentries, pentries_array_size); + PUT_4_BYTES(gpt_header + PARTITION_CRC_OFFSET, crc); + + /* header CRC is calculated with this field cleared */ + PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0); + crc = crc32(crc_zero, gpt_header, gpt_header_size); + PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, crc); + + /* Write the modified GPT header back to block dev */ + r = blk_rw(fd, 1, gpt2_header_offset, gpt_header, blk_size); + if (!r) + /* Write the modified GPT partititon entries array back to block dev */ + r = blk_rw(fd, 1, pentries_start_offset, pentries, + pentries_array_size); + +EXIT: + if(gpt_header) + free(gpt_header); + if (pentries) + free(pentries); + return r; +} + +/** + * ========================================================================== + * + * \brief Checks GPT state (header signature and CRC) + * + * \param [in] fd block dev file descriptor + * \param [in] gpt GPT header to be checked + * \param [out] state GPT header state + * + * \return 0 on success + * + * ========================================================================== + */ +static int gpt_get_state(int fd, enum gpt_instance gpt, enum gpt_state *state) +{ + int64_t gpt_header_offset; + uint32_t gpt_header_size; + uint8_t *gpt_header = NULL; + uint32_t crc; + uint32_t crc_zero; + uint32_t blk_size = 0; + + *state = GPT_OK; + + crc_zero = crc32(0L, Z_NULL, 0); + if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { + fprintf(stderr, "Failed to get GPT device block size: %s\n", + strerror(errno)); + goto error; + } + gpt_header = (uint8_t*)malloc(blk_size); + if (!gpt_header) { + fprintf(stderr, "gpt_get_state:Failed to alloc memory for header\n"); + goto error; + } + if (gpt == PRIMARY_GPT) + gpt_header_offset = blk_size; + else { + gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; + if (gpt_header_offset < 0) { + fprintf(stderr, "gpt_get_state:Seek to end of GPT part fail\n"); + goto error; + } + } + + if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) { + fprintf(stderr, "gpt_get_state: blk_rw failed\n"); + goto error; + } + if (memcmp(gpt_header, GPT_SIGNATURE, sizeof(GPT_SIGNATURE))) + *state = GPT_BAD_SIGNATURE; + gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET); + + crc = GET_4_BYTES(gpt_header + HEADER_CRC_OFFSET); + /* header CRC is calculated with this field cleared */ + PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0); + if (crc32(crc_zero, gpt_header, gpt_header_size) != crc) + *state = GPT_BAD_CRC; + free(gpt_header); + return 0; +error: + if (gpt_header) + free(gpt_header); + return -1; +} + + + +/** + * ========================================================================== + * + * \brief Sets GPT header state (used to corrupt and fix GPT signature) + * + * \param [in] fd block dev file descriptor + * \param [in] gpt GPT header to be checked + * \param [in] state GPT header state to set (GPT_OK or GPT_BAD_SIGNATURE) + * + * \return 0 on success + * + * ========================================================================== + */ +static int gpt_set_state(int fd, enum gpt_instance gpt, enum gpt_state state) +{ + int64_t gpt_header_offset; + uint32_t gpt_header_size; + uint8_t *gpt_header = NULL; + uint32_t crc; + uint32_t crc_zero; + uint32_t blk_size = 0; + + crc_zero = crc32(0L, Z_NULL, 0); + if (ioctl(fd, BLKSSZGET, &blk_size) != 0) { + fprintf(stderr, "Failed to get GPT device block size: %s\n", + strerror(errno)); + goto error; + } + gpt_header = (uint8_t*)malloc(blk_size); + if (!gpt_header) { + fprintf(stderr, "Failed to alloc memory for gpt header\n"); + goto error; + } + if (gpt == PRIMARY_GPT) + gpt_header_offset = blk_size; + else { + gpt_header_offset = lseek64(fd, 0, SEEK_END) - blk_size; + if (gpt_header_offset < 0) { + fprintf(stderr, "Failed to seek to end of GPT device\n"); + goto error; + } + } + if (blk_rw(fd, 0, gpt_header_offset, gpt_header, blk_size)) { + fprintf(stderr, "Failed to r/w gpt header\n"); + goto error; + } + if (state == GPT_OK) + memcpy(gpt_header, GPT_SIGNATURE, sizeof(GPT_SIGNATURE)); + else if (state == GPT_BAD_SIGNATURE) + *gpt_header = 0; + else { + fprintf(stderr, "gpt_set_state: Invalid state\n"); + goto error; + } + + gpt_header_size = GET_4_BYTES(gpt_header + HEADER_SIZE_OFFSET); + + /* header CRC is calculated with this field cleared */ + PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, 0); + crc = crc32(crc_zero, gpt_header, gpt_header_size); + PUT_4_BYTES(gpt_header + HEADER_CRC_OFFSET, crc); + + if (blk_rw(fd, 1, gpt_header_offset, gpt_header, blk_size)) { + fprintf(stderr, "gpt_set_state: blk write failed\n"); + goto error; + } + return 0; +error: + if(gpt_header) + free(gpt_header); + return -1; +} + +int get_scsi_node_from_bootdevice(const char *bootdev_path, + char *sg_node_path, + size_t buf_size) +{ + char sg_dir_path[PATH_MAX] = {0}; + char real_path[PATH_MAX] = {0}; + DIR *scsi_dir = NULL; + struct dirent *de; + int node_found = 0; + if (!bootdev_path || !sg_node_path) { + fprintf(stderr, "%s : invalid argument\n", + __func__); + goto error; + } + if (readlink(bootdev_path, real_path, sizeof(real_path) - 1) < 0) { + fprintf(stderr, "failed to resolve link for %s(%s)\n", + bootdev_path, + strerror(errno)); + goto error; + } + if(strlen(real_path) < PATH_TRUNCATE_LOC + 1){ + fprintf(stderr, "Unrecognized path :%s:\n", + real_path); + goto error; + } + //For the safe side in case there are additional partitions on + //the XBL lun we truncate the name. + real_path[PATH_TRUNCATE_LOC] = '\0'; + if(strlen(real_path) < LUN_NAME_START_LOC + 1){ + fprintf(stderr, "Unrecognized truncated path :%s:\n", + real_path); + goto error; + } + //This will give us /dev/block/sdb/device/scsi_generic + //which contains a file sgY whose name gives us the path + //to /dev/sgY which we return + snprintf(sg_dir_path, sizeof(sg_dir_path) - 1, + "/sys/block/%s/device/scsi_generic", + &real_path[LUN_NAME_START_LOC]); + scsi_dir = opendir(sg_dir_path); + if (!scsi_dir) { + fprintf(stderr, "%s : Failed to open %s(%s)\n", + __func__, + sg_dir_path, + strerror(errno)); + goto error; + } + while((de = readdir(scsi_dir))) { + if (de->d_name[0] == '.') + continue; + else if (!strncmp(de->d_name, "sg", 2)) { + snprintf(sg_node_path, + buf_size -1, + "/dev/%s", + de->d_name); + fprintf(stderr, "%s:scsi generic node is :%s:\n", + __func__, + sg_node_path); + node_found = 1; + break; + } + } + if(!node_found) { + fprintf(stderr,"%s: Unable to locate scsi generic node\n", + __func__); + goto error; + } + closedir(scsi_dir); + return 0; +error: + if (scsi_dir) + closedir(scsi_dir); + return -1; +} + + + +//Swtich betwieen using either the primary or the backup +//boot LUN for boot. This is required since UFS boot partitions +//cannot have a backup GPT which is what we use for failsafe +//updates of the other 'critical' partitions. This function will +//not be invoked for emmc targets and on UFS targets is only required +//to be invoked for XBL. +// +//The algorithm to do this is as follows: +//- Find the real block device(eg: /dev/block/sdb) that corresponds +// to the /dev/block/bootdevice/by-name/xbl(bak) symlink +// +//- Once we have the block device 'node' name(sdb in the above example) +// use this node to to locate the scsi generic device that represents +// it by checking the file /sys/block/sdb/device/scsi_generic/sgY +// +//- Once we locate sgY we call the query ioctl on /dev/sgy to switch +//the boot lun to either LUNA or LUNB +int gpt_utils_set_xbl_boot_partition(enum boot_chain chain) +{ + struct stat st; + ///sys/block/sdX/device/scsi_generic/ + char sg_dev_node[PATH_MAX] = {0}; + uint8_t boot_lun_id = 0; + const char *boot_dev = NULL; + + if (chain == BACKUP_BOOT) { + boot_lun_id = BOOT_LUN_B_ID; + if (!stat(XBL_BACKUP, &st)) + boot_dev = XBL_BACKUP; + else if (!stat(XBL_AB_SECONDARY, &st)) + boot_dev = XBL_AB_SECONDARY; + else { + fprintf(stderr, "%s: Failed to locate secondary xbl\n", + __func__); + goto error; + } + } else if (chain == NORMAL_BOOT) { + boot_lun_id = BOOT_LUN_A_ID; + if (!stat(XBL_PRIMARY, &st)) + boot_dev = XBL_PRIMARY; + else if (!stat(XBL_AB_PRIMARY, &st)) + boot_dev = XBL_AB_PRIMARY; + else { + fprintf(stderr, "%s: Failed to locate primary xbl\n", + __func__); + goto error; + } + } else { + fprintf(stderr, "%s: Invalid boot chain id\n", __func__); + goto error; + } + //We need either both xbl and xblbak or both xbl_a and xbl_b to exist at + //the same time. If not the current configuration is invalid. + if((stat(XBL_PRIMARY, &st) || + stat(XBL_BACKUP, &st)) && + (stat(XBL_AB_PRIMARY, &st) || + stat(XBL_AB_SECONDARY, &st))) { + fprintf(stderr, "%s:primary/secondary XBL prt not found(%s)\n", + __func__, + strerror(errno)); + goto error; + } + fprintf(stderr, "%s: setting %s lun as boot lun\n", + __func__, + boot_dev); + if (get_scsi_node_from_bootdevice(boot_dev, + sg_dev_node, + sizeof(sg_dev_node))) { + fprintf(stderr, "%s: Failed to get scsi node path for xblbak\n", + __func__); + goto error; + } + /* set boot lun using /dev/sg or /dev/ufs-bsg* */ + if (set_boot_lun(sg_dev_node, boot_lun_id)) { + fprintf(stderr, "%s: Failed to set xblbak as boot partition\n", + __func__); + goto error; + } + return 0; +error: + return -1; +} + +int gpt_utils_is_ufs_device() +{ + char bootdevice[PROPERTY_VALUE_MAX] = {0}; + property_get("ro.boot.bootdevice", bootdevice, "N/A"); + if (strlen(bootdevice) < strlen(".ufshc") + 1) + return 0; + return (!strncmp(&bootdevice[strlen(bootdevice) - strlen(".ufshc")], + ".ufshc", + sizeof(".ufshc"))); +} +//dev_path is the path to the block device that contains the GPT image that +//needs to be updated. This would be the device which holds one or more critical +//boot partitions and their backups. In the case of EMMC this function would +//be invoked only once on /dev/block/mmcblk1 since it holds the GPT image +//containing all the partitions For UFS devices it could potentially be +//invoked multiple times, once for each LUN containing critical image(s) and +//their backups +int prepare_partitions(enum boot_update_stage stage, const char *dev_path) +{ + int r = 0; + int fd = -1; + int is_ufs = gpt_utils_is_ufs_device(); + enum gpt_state gpt_prim, gpt_second; + enum boot_update_stage internal_stage; + struct stat xbl_partition_stat; + + if (!dev_path) { + fprintf(stderr, "%s: Invalid dev_path\n", + __func__); + r = -1; + goto EXIT; + } + fd = open(dev_path, O_RDWR); + if (fd < 0) { + fprintf(stderr, "%s: Opening '%s' failed: %s\n", + __func__, + BLK_DEV_FILE, + strerror(errno)); + r = -1; + goto EXIT; + } + r = gpt_get_state(fd, PRIMARY_GPT, &gpt_prim) || + gpt_get_state(fd, SECONDARY_GPT, &gpt_second); + if (r) { + fprintf(stderr, "%s: Getting GPT headers state failed\n", + __func__); + goto EXIT; + } + + /* These 2 combinations are unexpected and unacceptable */ + if (gpt_prim == GPT_BAD_CRC || gpt_second == GPT_BAD_CRC) { + fprintf(stderr, "%s: GPT headers CRC corruption detected, aborting\n", + __func__); + r = -1; + goto EXIT; + } + if (gpt_prim == GPT_BAD_SIGNATURE && gpt_second == GPT_BAD_SIGNATURE) { + fprintf(stderr, "%s: Both GPT headers corrupted, aborting\n", + __func__); + r = -1; + goto EXIT; + } + + /* Check internal update stage according GPT headers' state */ + if (gpt_prim == GPT_OK && gpt_second == GPT_OK) + internal_stage = UPDATE_MAIN; + else if (gpt_prim == GPT_BAD_SIGNATURE) + internal_stage = UPDATE_BACKUP; + else if (gpt_second == GPT_BAD_SIGNATURE) + internal_stage = UPDATE_FINALIZE; + else { + fprintf(stderr, "%s: Abnormal GPTs state: primary (%d), secondary (%d), " + "aborting\n", __func__, gpt_prim, gpt_second); + r = -1; + goto EXIT; + } + + /* Stage already set - ready for update, exitting */ + if ((int) stage == (int) internal_stage - 1) + goto EXIT; + /* Unexpected stage given */ + if (stage != internal_stage) { + r = -1; + goto EXIT; + } + + switch (stage) { + case UPDATE_MAIN: + if (is_ufs) { + if(stat(XBL_PRIMARY, &xbl_partition_stat)|| + stat(XBL_BACKUP, &xbl_partition_stat)){ + //Non fatal error. Just means this target does not + //use XBL but relies on sbl whose update is handled + //by the normal methods. + fprintf(stderr, "%s: xbl part not found(%s).Assuming sbl in use\n", + __func__, + strerror(errno)); + } else { + //Switch the boot lun so that backup boot LUN is used + r = gpt_utils_set_xbl_boot_partition(BACKUP_BOOT); + if(r){ + fprintf(stderr, "%s: Failed to set xbl backup partition as boot\n", + __func__); + goto EXIT; + } + } + } + //Fix up the backup GPT table so that it actually points to + //the backup copy of the boot critical images + fprintf(stderr, "%s: Preparing for primary partition update\n", + __func__); + r = gpt2_set_boot_chain(fd, BACKUP_BOOT); + if (r) { + if (r < 0) + fprintf(stderr, + "%s: Setting secondary GPT to backup boot failed\n", + __func__); + /* No backup partitions - do not corrupt GPT, do not flag error */ + else + r = 0; + goto EXIT; + } + //corrupt the primary GPT so that the backup(which now points to + //the backup boot partitions is used) + r = gpt_set_state(fd, PRIMARY_GPT, GPT_BAD_SIGNATURE); + if (r) { + fprintf(stderr, "%s: Corrupting primary GPT header failed\n", + __func__); + goto EXIT; + } + break; + case UPDATE_BACKUP: + if (is_ufs) { + if(stat(XBL_PRIMARY, &xbl_partition_stat)|| + stat(XBL_BACKUP, &xbl_partition_stat)){ + //Non fatal error. Just means this target does not + //use XBL but relies on sbl whose update is handled + //by the normal methods. + fprintf(stderr, "%s: xbl part not found(%s).Assuming sbl in use\n", + __func__, + strerror(errno)); + } else { + //Switch the boot lun so that backup boot LUN is used + r = gpt_utils_set_xbl_boot_partition(NORMAL_BOOT); + if(r) { + fprintf(stderr, "%s: Failed to set xbl backup partition as boot\n", + __func__); + goto EXIT; + } + } + } + //Fix the primary GPT header so that is used + fprintf(stderr, "%s: Preparing for backup partition update\n", + __func__); + r = gpt_set_state(fd, PRIMARY_GPT, GPT_OK); + if (r) { + fprintf(stderr, "%s: Fixing primary GPT header failed\n", + __func__); + goto EXIT; + } + //Corrupt the scondary GPT header + r = gpt_set_state(fd, SECONDARY_GPT, GPT_BAD_SIGNATURE); + if (r) { + fprintf(stderr, "%s: Corrupting secondary GPT header failed\n", + __func__); + goto EXIT; + } + break; + case UPDATE_FINALIZE: + //Undo the changes we had made in the UPDATE_MAIN stage so that the + //primary/backup GPT headers once again point to the same set of + //partitions + fprintf(stderr, "%s: Finalizing partitions\n", + __func__); + r = gpt2_set_boot_chain(fd, NORMAL_BOOT); + if (r < 0) { + fprintf(stderr, "%s: Setting secondary GPT to normal boot failed\n", + __func__); + goto EXIT; + } + + r = gpt_set_state(fd, SECONDARY_GPT, GPT_OK); + if (r) { + fprintf(stderr, "%s: Fixing secondary GPT header failed\n", + __func__); + goto EXIT; + } + break; + default:; + } + +EXIT: + if (fd >= 0) { + fsync(fd); + close(fd); + } + return r; +} + +int add_lun_to_update_list(char *lun_path, struct update_data *dat) +{ + uint32_t i = 0; + struct stat st; + if (!lun_path || !dat){ + fprintf(stderr, "%s: Invalid data", + __func__); + return -1; + } + if (stat(lun_path, &st)) { + fprintf(stderr, "%s: Unable to access %s. Skipping adding to list", + __func__, + lun_path); + return -1; + } + if (dat->num_valid_entries == 0) { + fprintf(stderr, "%s: Copying %s into lun_list[%d]\n", + __func__, + lun_path, + i); + strlcpy(dat->lun_list[0], lun_path, + PATH_MAX * sizeof(char)); + dat->num_valid_entries = 1; + } else { + for (i = 0; (i < dat->num_valid_entries) && + (dat->num_valid_entries < MAX_LUNS - 1); i++) { + //Check if the current LUN is not already part + //of the lun list + if (!strncmp(lun_path,dat->lun_list[i], + strlen(dat->lun_list[i]))) { + //LUN already in list..Return + return 0; + } + } + fprintf(stderr, "%s: Copying %s into lun_list[%d]\n", + __func__, + lun_path, + dat->num_valid_entries); + //Add LUN path lun list + strlcpy(dat->lun_list[dat->num_valid_entries], lun_path, + PATH_MAX * sizeof(char)); + dat->num_valid_entries++; + } + return 0; +} + +int prepare_boot_update(enum boot_update_stage stage) +{ + int is_ufs = gpt_utils_is_ufs_device(); + struct stat ufs_dir_stat; + struct update_data data; + int rcode = 0; + uint32_t i = 0; + int is_error = 0; + const char ptn_swap_list[][MAX_GPT_NAME_SIZE] = { PTN_SWAP_LIST }; + //Holds /dev/block/bootdevice/by-name/*bak entry + char buf[PATH_MAX] = {0}; + //Holds the resolved path of the symlink stored in buf + char real_path[PATH_MAX] = {0}; + + if (!is_ufs) { + //emmc device. Just pass in path to mmcblk0 + return prepare_partitions(stage, BLK_DEV_FILE); + } else { + //Now we need to find the list of LUNs over + //which the boot critical images are spread + //and set them up for failsafe updates.To do + //this we find out where the symlinks for the + //each of the paths under + ///dev/block/bootdevice/by-name/PTN_SWAP_LIST + //actually point to. + fprintf(stderr, "%s: Running on a UFS device\n", + __func__); + memset(&data, '\0', sizeof(struct update_data)); + for (i=0; i < ARRAY_SIZE(ptn_swap_list); i++) { + //XBL on UFS does not follow the convention + //of being loaded based on well known GUID'S. + //We take care of switching the UFS boot LUN + //explicitly later on. + if (!strncmp(ptn_swap_list[i], + PTN_XBL, + strlen(PTN_XBL))) + continue; + snprintf(buf, sizeof(buf), + "%s/%sbak", + BOOT_DEV_DIR, + ptn_swap_list[i]); + if (stat(buf, &ufs_dir_stat)) { + continue; + } + if (readlink(buf, real_path, sizeof(real_path) - 1) < 0) + { + fprintf(stderr, "%s: readlink error. Skipping %s", + __func__, + strerror(errno)); + } else { + if(strlen(real_path) < PATH_TRUNCATE_LOC + 1){ + fprintf(stderr, "Unknown path.Skipping :%s:\n", + real_path); + } else { + real_path[PATH_TRUNCATE_LOC] = '\0'; + add_lun_to_update_list(real_path, &data); + } + } + memset(buf, '\0', sizeof(buf)); + memset(real_path, '\0', sizeof(real_path)); + } + for (i=0; i < data.num_valid_entries; i++) { + fprintf(stderr, "%s: Preparing %s for update stage %d\n", + __func__, + data.lun_list[i], + stage); + rcode = prepare_partitions(stage, data.lun_list[i]); + if (rcode != 0) + { + fprintf(stderr, "%s: Failed to prepare %s.Continuing..\n", + __func__, + data.lun_list[i]); + is_error = 1; + } + } + } + if (is_error) + return -1; + return 0; +} + +//Given a parttion name(eg: rpm) get the path to the block device that +//represents the GPT disk the partition resides on. In the case of emmc it +//would be the default emmc dev(/dev/block/mmcblk0). In the case of UFS we look +//through the /dev/block/bootdevice/by-name/ tree for partname, and resolve +//the path to the LUN from there. +static int get_dev_path_from_partition_name(const char *partname, + char *buf, + size_t buflen) +{ + struct stat st; + char path[PATH_MAX] = {0}; + if (!partname || !buf || buflen < ((PATH_TRUNCATE_LOC) + 1)) { + ALOGE("%s: Invalid argument", __func__); + goto error; + } + if (gpt_utils_is_ufs_device()) { + //Need to find the lun that holds partition partname + snprintf(path, sizeof(path), + "%s/%s", + BOOT_DEV_DIR, + partname); + if (stat(path, &st)) { + goto error; + } + if (readlink(path, buf, buflen) < 0) + { + goto error; + } else { + buf[PATH_TRUNCATE_LOC] = '\0'; + } + } else { + snprintf(buf, buflen, BLK_DEV_FILE); + } + return 0; + +error: + return -1; +} + +int gpt_utils_get_partition_map(vector& ptn_list, + map>& partition_map) { + char devpath[PATH_MAX] = {'\0'}; + map>::iterator it; + if (ptn_list.size() < 1) { + fprintf(stderr, "%s: Invalid ptn list\n", __func__); + goto error; + } + //Go through the passed in list + for (uint32_t i = 0; i < ptn_list.size(); i++) + { + //Key in the map is the path to the device that holds the + //partition + if (get_dev_path_from_partition_name(ptn_list[i].c_str(), + devpath, + sizeof(devpath))) { + //Not necessarily an error. The partition may just + //not be present. + continue; + } + string path = devpath; + it = partition_map.find(path); + if (it != partition_map.end()) { + it->second.push_back(ptn_list[i]); + } else { + vector str_vec; + str_vec.push_back( ptn_list[i]); + partition_map.insert(pair> + (path, str_vec)); + } + memset(devpath, '\0', sizeof(devpath)); + } + return 0; +error: + return -1; +} + +//Get the block size of the disk represented by decsriptor fd +static uint32_t gpt_get_block_size(int fd) +{ + uint32_t block_size = 0; + if (fd < 0) { + ALOGE("%s: invalid descriptor", + __func__); + goto error; + } + if (ioctl(fd, BLKSSZGET, &block_size) != 0) { + ALOGE("%s: Failed to get GPT dev block size : %s", + __func__, + strerror(errno)); + goto error; + } + return block_size; +error: + return 0; +} + +//Write the GPT header present in the passed in buffer back to the +//disk represented by fd +static int gpt_set_header(uint8_t *gpt_header, int fd, + enum gpt_instance instance) +{ + uint32_t block_size = 0; + off64_t gpt_header_offset = 0; + if (!gpt_header || fd < 0) { + ALOGE("%s: Invalid arguments", + __func__); + goto error; + } + block_size = gpt_get_block_size(fd); + if (block_size == 0) { + ALOGE("%s: Failed to get block size", __func__); + goto error; + } + if (instance == PRIMARY_GPT) + gpt_header_offset = block_size; + else + gpt_header_offset = lseek64(fd, 0, SEEK_END) - block_size; + if (gpt_header_offset <= 0) { + ALOGE("%s: Failed to get gpt header offset",__func__); + goto error; + } + if (blk_rw(fd, 1, gpt_header_offset, gpt_header, block_size)) { + ALOGE("%s: Failed to write back GPT header", __func__); + goto error; + } + return 0; +error: + return -1; +} + +//Read out the GPT header for the disk that contains the partition partname +static uint8_t* gpt_get_header(const char *partname, enum gpt_instance instance) +{ + uint8_t* hdr = NULL; + char devpath[PATH_MAX] = {0}; + int64_t hdr_offset = 0; + uint32_t block_size = 0; + int fd = -1; + if (!partname) { + ALOGE("%s: Invalid partition name", __func__); + goto error; + } + if (get_dev_path_from_partition_name(partname, devpath, sizeof(devpath)) + != 0) { + ALOGE("%s: Failed to resolve path for %s", + __func__, + partname); + goto error; + } + fd = open(devpath, O_RDWR); + if (fd < 0) { + ALOGE("%s: Failed to open %s : %s", + __func__, + devpath, + strerror(errno)); + goto error; + } + block_size = gpt_get_block_size(fd); + if (block_size == 0) + { + ALOGE("%s: Failed to get gpt block size for %s", + __func__, + partname); + goto error; + } + + hdr = (uint8_t*)malloc(block_size); + if (!hdr) { + ALOGE("%s: Failed to allocate memory for gpt header", + __func__); + } + if (instance == PRIMARY_GPT) + hdr_offset = block_size; + else { + hdr_offset = lseek64(fd, 0, SEEK_END) - block_size; + } + if (hdr_offset < 0) { + ALOGE("%s: Failed to get gpt header offset", + __func__); + goto error; + } + if (blk_rw(fd, 0, hdr_offset, hdr, block_size)) { + ALOGE("%s: Failed to read GPT header from device", + __func__); + goto error; + } + close(fd); + return hdr; +error: + if (fd >= 0) + close(fd); + if (hdr) + free(hdr); + return NULL; +} + +//Returns the partition entry array based on the +//passed in buffer which contains the gpt header. +//The fd here is the descriptor for the 'disk' which +//holds the partition +static uint8_t* gpt_get_pentry_arr(uint8_t *hdr, int fd) +{ + uint64_t pentries_start = 0; + uint32_t pentry_size = 0; + uint32_t block_size = 0; + uint32_t pentries_arr_size = 0; + uint8_t *pentry_arr = NULL; + int rc = 0; + if (!hdr) { + ALOGE("%s: Invalid header", __func__); + goto error; + } + if (fd < 0) { + ALOGE("%s: Invalid fd", __func__); + goto error; + } + block_size = gpt_get_block_size(fd); + if (!block_size) { + ALOGE("%s: Failed to get gpt block size for", + __func__); + goto error; + } + pentries_start = GET_8_BYTES(hdr + PENTRIES_OFFSET) * block_size; + pentry_size = GET_4_BYTES(hdr + PENTRY_SIZE_OFFSET); + pentries_arr_size = + GET_4_BYTES(hdr + PARTITION_COUNT_OFFSET) * pentry_size; + pentry_arr = (uint8_t*)calloc(1, pentries_arr_size); + if (!pentry_arr) { + ALOGE("%s: Failed to allocate memory for partition array", + __func__); + goto error; + } + rc = blk_rw(fd, 0, + pentries_start, + pentry_arr, + pentries_arr_size); + if (rc) { + ALOGE("%s: Failed to read partition entry array", + __func__); + goto error; + } + return pentry_arr; +error: + if (pentry_arr) + free(pentry_arr); + return NULL; +} + +static int gpt_set_pentry_arr(uint8_t *hdr, int fd, uint8_t* arr) +{ + uint32_t block_size = 0; + uint64_t pentries_start = 0; + uint32_t pentry_size = 0; + uint32_t pentries_arr_size = 0; + int rc = 0; + if (!hdr || fd < 0 || !arr) { + ALOGE("%s: Invalid argument", __func__); + goto error; + } + block_size = gpt_get_block_size(fd); + if (!block_size) { + ALOGE("%s: Failed to get gpt block size for", + __func__); + goto error; + } + pentries_start = GET_8_BYTES(hdr + PENTRIES_OFFSET) * block_size; + pentry_size = GET_4_BYTES(hdr + PENTRY_SIZE_OFFSET); + pentries_arr_size = + GET_4_BYTES(hdr + PARTITION_COUNT_OFFSET) * pentry_size; + rc = blk_rw(fd, 1, + pentries_start, + arr, + pentries_arr_size); + if (rc) { + ALOGE("%s: Failed to read partition entry array", + __func__); + goto error; + } + return 0; +error: + return -1; +} + + + +//Allocate a handle used by calls to the "gpt_disk" api's +struct gpt_disk * gpt_disk_alloc() +{ + struct gpt_disk *disk; + disk = (struct gpt_disk *)malloc(sizeof(struct gpt_disk)); + if (!disk) { + ALOGE("%s: Failed to allocate memory", __func__); + goto end; + } + memset(disk, 0, sizeof(struct gpt_disk)); +end: + return disk; +} + +//Free previously allocated/initialized handle +void gpt_disk_free(struct gpt_disk *disk) +{ + if (!disk) + return; + if (disk->hdr) + free(disk->hdr); + if (disk->hdr_bak) + free(disk->hdr_bak); + if (disk->pentry_arr) + free(disk->pentry_arr); + if (disk->pentry_arr_bak) + free(disk->pentry_arr_bak); + free(disk); + return; +} + +//fills up the passed in gpt_disk struct with information about the +//disk represented by path dev. Returns 0 on success and -1 on error. +int gpt_disk_get_disk_info(const char *dev, struct gpt_disk *dsk) +{ + + struct gpt_disk *disk = NULL; + int fd = -1; + uint32_t gpt_header_size = 0; + uint32_t crc_zero; + + crc_zero = crc32(0L, Z_NULL, 0); + if (!dsk || !dev) { + ALOGE("%s: Invalid arguments", __func__); + goto error; + } + disk = dsk; + disk->hdr = gpt_get_header(dev, PRIMARY_GPT); + if (!disk->hdr) { + ALOGE("%s: Failed to get primary header", __func__); + goto error; + } + gpt_header_size = GET_4_BYTES(disk->hdr + HEADER_SIZE_OFFSET); + disk->hdr_crc = crc32(crc_zero, disk->hdr, gpt_header_size); + disk->hdr_bak = gpt_get_header(dev, SECONDARY_GPT); + if (!disk->hdr_bak) { + ALOGE("%s: Failed to get backup header", __func__); + goto error; + } + disk->hdr_bak_crc = crc32(crc_zero, disk->hdr_bak, gpt_header_size); + + //Descriptor for the block device. We will use this for further + //modifications to the partition table + if (get_dev_path_from_partition_name(dev, + disk->devpath, + sizeof(disk->devpath)) != 0) { + ALOGE("%s: Failed to resolve path for %s", + __func__, + dev); + goto error; + } + fd = open(disk->devpath, O_RDWR); + if (fd < 0) { + ALOGE("%s: Failed to open %s: %s", + __func__, + disk->devpath, + strerror(errno)); + goto error; + } + disk->pentry_arr = gpt_get_pentry_arr(disk->hdr, fd); + if (!disk->pentry_arr) { + ALOGE("%s: Failed to obtain partition entry array", + __func__); + goto error; + } + disk->pentry_arr_bak = gpt_get_pentry_arr(disk->hdr_bak, fd); + if (!disk->pentry_arr_bak) { + ALOGE("%s: Failed to obtain backup partition entry array", + __func__); + goto error; + } + disk->pentry_size = GET_4_BYTES(disk->hdr + PENTRY_SIZE_OFFSET); + disk->pentry_arr_size = + GET_4_BYTES(disk->hdr + PARTITION_COUNT_OFFSET) * + disk->pentry_size; + disk->pentry_arr_crc = GET_4_BYTES(disk->hdr + PARTITION_CRC_OFFSET); + disk->pentry_arr_bak_crc = GET_4_BYTES(disk->hdr_bak + + PARTITION_CRC_OFFSET); + disk->block_size = gpt_get_block_size(fd); + close(fd); + disk->is_initialized = GPT_DISK_INIT_MAGIC; + return 0; +error: + if (fd >= 0) + close(fd); + return -1; +} + +//Get pointer to partition entry from a allocated gpt_disk structure +uint8_t* gpt_disk_get_pentry(struct gpt_disk *disk, + const char *partname, + enum gpt_instance instance) +{ + uint8_t *ptn_arr = NULL; + if (!disk || !partname || disk->is_initialized != GPT_DISK_INIT_MAGIC) { + ALOGE("%s: Invalid argument",__func__); + goto error; + } + ptn_arr = (instance == PRIMARY_GPT) ? + disk->pentry_arr : disk->pentry_arr_bak; + return (gpt_pentry_seek(partname, ptn_arr, + ptn_arr + disk->pentry_arr_size , + disk->pentry_size)); +error: + return NULL; +} + +//Update CRC values for the various components of the gpt_disk +//structure. This function should be called after any of the fields +//have been updated before the structure contents are written back to +//disk. +int gpt_disk_update_crc(struct gpt_disk *disk) +{ + uint32_t gpt_header_size = 0; + uint32_t crc_zero; + crc_zero = crc32(0L, Z_NULL, 0); + if (!disk || (disk->is_initialized != GPT_DISK_INIT_MAGIC)) { + ALOGE("%s: invalid argument", __func__); + goto error; + } + //Recalculate the CRC of the primary partiton array + disk->pentry_arr_crc = crc32(crc_zero, + disk->pentry_arr, + disk->pentry_arr_size); + //Recalculate the CRC of the backup partition array + disk->pentry_arr_bak_crc = crc32(crc_zero, + disk->pentry_arr_bak, + disk->pentry_arr_size); + //Update the partition CRC value in the primary GPT header + PUT_4_BYTES(disk->hdr + PARTITION_CRC_OFFSET, disk->pentry_arr_crc); + //Update the partition CRC value in the backup GPT header + PUT_4_BYTES(disk->hdr_bak + PARTITION_CRC_OFFSET, + disk->pentry_arr_bak_crc); + //Update the CRC value of the primary header + gpt_header_size = GET_4_BYTES(disk->hdr + HEADER_SIZE_OFFSET); + //Header CRC is calculated with its own CRC field set to 0 + PUT_4_BYTES(disk->hdr + HEADER_CRC_OFFSET, 0); + PUT_4_BYTES(disk->hdr_bak + HEADER_CRC_OFFSET, 0); + disk->hdr_crc = crc32(crc_zero, disk->hdr, gpt_header_size); + disk->hdr_bak_crc = crc32(crc_zero, disk->hdr_bak, gpt_header_size); + PUT_4_BYTES(disk->hdr + HEADER_CRC_OFFSET, disk->hdr_crc); + PUT_4_BYTES(disk->hdr_bak + HEADER_CRC_OFFSET, disk->hdr_bak_crc); + return 0; +error: + return -1; +} + +//Write the contents of struct gpt_disk back to the actual disk +int gpt_disk_commit(struct gpt_disk *disk) +{ + int fd = -1; + if (!disk || (disk->is_initialized != GPT_DISK_INIT_MAGIC)){ + ALOGE("%s: Invalid args", __func__); + goto error; + } + fd = open(disk->devpath, O_RDWR); + if (fd < 0) { + ALOGE("%s: Failed to open %s: %s", + __func__, + disk->devpath, + strerror(errno)); + goto error; + } + //Write the primary header + if(gpt_set_header(disk->hdr, fd, PRIMARY_GPT) != 0) { + ALOGE("%s: Failed to update primary GPT header", + __func__); + goto error; + } + //Write back the primary partition array + if (gpt_set_pentry_arr(disk->hdr, fd, disk->pentry_arr)) { + ALOGE("%s: Failed to write primary GPT partition arr", + __func__); + goto error; + } + //Write back the secondary header + if(gpt_set_header(disk->hdr_bak, fd, SECONDARY_GPT) != 0) { + ALOGE("%s: Failed to update secondary GPT header", + __func__); + goto error; + } + //Write back the secondary partition array + if (gpt_set_pentry_arr(disk->hdr_bak, fd, disk->pentry_arr_bak)) { + ALOGE("%s: Failed to write secondary GPT partition arr", + __func__); + goto error; + } + close(fd); + return 0; +error: + if (fd >= 0) + close(fd); + return -1; +} diff --git a/gpt-utils/gpt-utils.h b/gpt-utils/gpt-utils.h new file mode 100644 index 0000000..5bfe1e9 --- /dev/null +++ b/gpt-utils/gpt-utils.h @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2013,2016,2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GPT_UTILS_H__ +#define __GPT_UTILS_H__ +#include +#include +#include +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +/****************************************************************************** + * GPT HEADER DEFINES + ******************************************************************************/ +#define GPT_SIGNATURE "EFI PART" +#define HEADER_SIZE_OFFSET 12 +#define HEADER_CRC_OFFSET 16 +#define PRIMARY_HEADER_OFFSET 24 +#define BACKUP_HEADER_OFFSET 32 +#define FIRST_USABLE_LBA_OFFSET 40 +#define LAST_USABLE_LBA_OFFSET 48 +#define PENTRIES_OFFSET 72 +#define PARTITION_COUNT_OFFSET 80 +#define PENTRY_SIZE_OFFSET 84 +#define PARTITION_CRC_OFFSET 88 + +#define TYPE_GUID_OFFSET 0 +#define TYPE_GUID_SIZE 16 +#define PTN_ENTRY_SIZE 128 +#define UNIQUE_GUID_OFFSET 16 +#define FIRST_LBA_OFFSET 32 +#define LAST_LBA_OFFSET 40 +#define ATTRIBUTE_FLAG_OFFSET 48 +#define PARTITION_NAME_OFFSET 56 +#define MAX_GPT_NAME_SIZE 72 + +/****************************************************************************** + * AB RELATED DEFINES + ******************************************************************************/ +//Bit 48 onwords in the attribute field are the ones where we are allowed to +//store our AB attributes. +#define AB_FLAG_OFFSET (ATTRIBUTE_FLAG_OFFSET + 6) +#define GPT_DISK_INIT_MAGIC 0xABCD +#define AB_PARTITION_ATTR_SLOT_ACTIVE (0x1<<2) +#define AB_PARTITION_ATTR_BOOT_SUCCESSFUL (0x1<<6) +#define AB_PARTITION_ATTR_UNBOOTABLE (0x1<<7) +#define AB_SLOT_ACTIVE_VAL 0x3F +#define AB_SLOT_INACTIVE_VAL 0x0 +#define AB_SLOT_ACTIVE 1 +#define AB_SLOT_INACTIVE 0 +#define AB_SLOT_A_SUFFIX "_a" +#define AB_SLOT_B_SUFFIX "_b" +#define PTN_XBL "xbl" +#define PTN_XBL_CFG "xbl_config" +#define PTN_SWAP_LIST PTN_XBL, PTN_XBL_CFG, "sbl1", "rpm", "tz", "aboot", "abl", "hyp", "lksecapp", "keymaster", "cmnlib", "cmnlib32", "cmnlib64", "pmic", "apdp", "devcfg", "hosd", "keystore", "msadp", "mdtp", "mdtpsecapp", "dsp", "aop", "qupfw", "vbmeta", "dtbo", "imagefv", "ImageFv", "multiimgoem", "multiimgqti", "uefisecapp", "vm-bootsys", "shrm", "cpucp", "featenabler", "vbmeta_system" +#define AB_PTN_LIST PTN_SWAP_LIST, "boot", "vendor_boot", "system", "system_ext", "vendor", "odm", "modem", "bluetooth" +#define BOOT_DEV_DIR "/dev/block/bootdevice/by-name" + +/****************************************************************************** + * HELPER MACROS + ******************************************************************************/ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +/****************************************************************************** + * TYPES + ******************************************************************************/ +enum boot_update_stage { + UPDATE_MAIN = 1, + UPDATE_BACKUP, + UPDATE_FINALIZE +}; + +enum gpt_instance { + PRIMARY_GPT = 0, + SECONDARY_GPT +}; + +enum boot_chain { + NORMAL_BOOT = 0, + BACKUP_BOOT +}; + +struct gpt_disk { + //GPT primary header + uint8_t *hdr; + //primary header crc + uint32_t hdr_crc; + //GPT backup header + uint8_t *hdr_bak; + //backup header crc + uint32_t hdr_bak_crc; + //Partition entries array + uint8_t *pentry_arr; + //Partition entries array for backup table + uint8_t *pentry_arr_bak; + //Size of the pentry array + uint32_t pentry_arr_size; + //Size of each element in the pentry array + uint32_t pentry_size; + //CRC of the partition entry array + uint32_t pentry_arr_crc; + //CRC of the backup partition entry array + uint32_t pentry_arr_bak_crc; + //Path to block dev representing the disk + char devpath[PATH_MAX]; + //Block size of disk + uint32_t block_size; + uint32_t is_initialized; +}; + +/****************************************************************************** + * FUNCTION PROTOTYPES + ******************************************************************************/ +int prepare_boot_update(enum boot_update_stage stage); +//GPT disk methods +struct gpt_disk* gpt_disk_alloc(); +//Free previously allocated gpt_disk struct +void gpt_disk_free(struct gpt_disk *disk); +//Get the details of the disk holding the partition whose name +//is passed in via dev +int gpt_disk_get_disk_info(const char *dev, struct gpt_disk *disk); + +//Get pointer to partition entry from a allocated gpt_disk structure +uint8_t* gpt_disk_get_pentry(struct gpt_disk *disk, + const char *partname, + enum gpt_instance instance); + +//Update the crc fields of the modified disk structure +int gpt_disk_update_crc(struct gpt_disk *disk); + +//Write the contents of struct gpt_disk back to the actual disk +int gpt_disk_commit(struct gpt_disk *disk); + +//Return if the current device is UFS based or not +int gpt_utils_is_ufs_device(); + +//Swtich betwieen using either the primary or the backup +//boot LUN for boot. This is required since UFS boot partitions +//cannot have a backup GPT which is what we use for failsafe +//updates of the other 'critical' partitions. This function will +//not be invoked for emmc targets and on UFS targets is only required +//to be invoked for XBL. +// +//The algorithm to do this is as follows: +//- Find the real block device(eg: /dev/block/sdb) that corresponds +// to the /dev/block/bootdevice/by-name/xbl(bak) symlink +// +//- Once we have the block device 'node' name(sdb in the above example) +// use this node to to locate the scsi generic device that represents +// it by checking the file /sys/block/sdb/device/scsi_generic/sgY +// +//- Once we locate sgY we call the query ioctl on /dev/sgy to switch +//the boot lun to either LUNA or LUNB +int gpt_utils_set_xbl_boot_partition(enum boot_chain chain); + +//Given a vector of partition names as a input and a reference to a map, +//populate the map to indicate which physical disk each of the partitions +//sits on. The key in the map is the path to the block device where the +//partiton lies and the value is a vector of strings indicating which of +//the passed in partiton names sits on that device. +int gpt_utils_get_partition_map(std::vector& partition_list, + std::map>& partition_map); +#ifdef __cplusplus +} +#endif +#endif /* __GPT_UTILS_H__ */ diff --git a/gpt-utils/recovery-ufs-bsg.cpp b/gpt-utils/recovery-ufs-bsg.cpp new file mode 100644 index 0000000..4249aa6 --- /dev/null +++ b/gpt-utils/recovery-ufs-bsg.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#define LOG_TAG "recovery_ufs" + +#include "recovery-ufs-bsg.h" + +#ifndef _BSG_FRAMEWORK_KERNEL_HEADERS +#ifndef _GENERIC_KERNEL_HEADERS +#include +#include +#endif +#endif + +//Size of the buffer that needs to be passed to the UFS ioctl +#define UFS_ATTR_DATA_SIZE 32 + +#ifdef _BSG_FRAMEWORK_KERNEL_HEADERS +static int get_ufs_bsg_dev(void) +{ + DIR *dir; + struct dirent *ent; + int ret = -ENODEV; + + if ((dir = opendir ("/dev")) != NULL) { + /* read all the files and directories within directory */ + while ((ent = readdir(dir)) != NULL) { + if (!strcmp(ent->d_name, "ufs-bsg") || + !strcmp(ent->d_name, "ufs-bsg0")) { + snprintf(ufs_bsg_dev, FNAME_SZ, "/dev/%s", ent->d_name); + ret = 0; + break; + } + } + if (ret) + ALOGE("could not find the ufs-bsg dev\n"); + closedir (dir); + } else { + /* could not open directory */ + ALOGE("could not open /dev (error no: %d)\n", errno); + ret = -EINVAL; + } + + return ret; +} + +int ufs_bsg_dev_open(void) +{ + int ret; + if (!fd_ufs_bsg) { + fd_ufs_bsg = open(ufs_bsg_dev, O_RDWR); + ret = errno; + if (fd_ufs_bsg < 0) { + ALOGE("Unable to open %s (error no: %d)", + ufs_bsg_dev, errno); + fd_ufs_bsg = 0; + return ret; + } + } + return 0; +} + +void ufs_bsg_dev_close(void) +{ + if (fd_ufs_bsg) { + close(fd_ufs_bsg); + fd_ufs_bsg = 0; + } +} + +static int ufs_bsg_ioctl(int fd, struct ufs_bsg_request *req, + struct ufs_bsg_reply *rsp, __u8 *buf, __u32 buf_len, + enum bsg_ioctl_dir dir) +{ + int ret; + struct sg_io_v4 sg_io{}; + + sg_io.guard = 'Q'; + sg_io.protocol = BSG_PROTOCOL_SCSI; + sg_io.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT; + sg_io.request_len = sizeof(*req); + sg_io.request = (__u64)req; + sg_io.response = (__u64)rsp; + sg_io.max_response_len = sizeof(*rsp); + if (dir == BSG_IOCTL_DIR_FROM_DEV) { + sg_io.din_xfer_len = buf_len; + sg_io.din_xferp = (__u64)(buf); + } else { + sg_io.dout_xfer_len = buf_len; + sg_io.dout_xferp = (__u64)(buf); + } + + ret = ioctl(fd, SG_IO, &sg_io); + if (ret) + ALOGE("%s: Error from sg_io ioctl (return value: %d, error no: %d, reply result from LLD: %d\n)", + __func__, ret, errno, rsp->result); + + if (sg_io.info || rsp->result) { + ALOGE("%s: Error from sg_io info (check sg info: device_status: 0x%x, transport_status: 0x%x, driver_status: 0x%x, reply result from LLD: %d\n)", + __func__, sg_io.device_status, sg_io.transport_status, + sg_io.driver_status, rsp->result); + ret = -EAGAIN; + } + + return ret; +} + +static void compose_ufs_bsg_query_req(struct ufs_bsg_request *req, __u8 func, + __u8 opcode, __u8 idn, __u8 index, __u8 sel, + __u16 length) +{ + struct utp_upiu_header *hdr = &req->upiu_req.header; + struct utp_upiu_query *qr = &req->upiu_req.qr; + + req->msgcode = UTP_UPIU_QUERY_REQ; + hdr->dword_0 = DWORD(UTP_UPIU_QUERY_REQ, 0, 0, 0); + hdr->dword_1 = DWORD(0, func, 0, 0); + hdr->dword_2 = DWORD(0, 0, length >> 8, (__u8)length); + qr->opcode = opcode; + qr->idn = idn; + qr->index = index; + qr->selector = sel; + qr->length = htobe16(length); +} + + +static int ufs_query_attr(int fd, __u32 value, + __u8 func, __u8 opcode, __u8 idn, + __u8 index, __u8 sel) +{ + struct ufs_bsg_request req{}; + struct ufs_bsg_reply rsp{}; + enum bsg_ioctl_dir dir = BSG_IOCTL_DIR_FROM_DEV; + int ret = 0; + + if (opcode == QUERY_REQ_OP_WRITE_DESC || opcode == QUERY_REQ_OP_WRITE_ATTR) + dir = BSG_IOCTL_DIR_TO_DEV; + + req.upiu_req.qr.value = htobe32(value); + + compose_ufs_bsg_query_req(&req, func, opcode, idn, index, sel, 0); + + ret = ufs_bsg_ioctl(fd, &req, &rsp, 0, 0, dir); + if (ret) + ALOGE("%s: Error from ufs_bsg_ioctl (return value: %d, error no: %d\n)", + __func__, ret, errno); + + return ret; +} + +int32_t set_boot_lun(char *sg_dev __unused,uint8_t lun_id) +{ + int32_t ret; + __u32 boot_lun_id = lun_id; + + ret = get_ufs_bsg_dev(); + if (ret) + return ret; + ALOGV("Found the ufs bsg dev: %s\n", ufs_bsg_dev); + + ret = ufs_bsg_dev_open(); + if (ret) + return ret; + ALOGV("Opened ufs bsg dev: %s\n", ufs_bsg_dev); + + ret = ufs_query_attr(fd_ufs_bsg, boot_lun_id, QUERY_REQ_FUNC_STD_WRITE, + QUERY_REQ_OP_WRITE_ATTR, QUERY_ATTR_IDN_BOOT_LU_EN, 0, 0); + if (ret) { + ALOGE("Error requesting ufs attr idn %d via query ioctl (return value: %d, error no: %d)", + QUERY_ATTR_IDN_BOOT_LU_EN, ret, errno); + goto out; + } +out: + ufs_bsg_dev_close(); + return ret; +} +#endif + +#ifndef _BSG_FRAMEWORK_KERNEL_HEADERS +int32_t set_boot_lun(char *sg_dev, uint8_t boot_lun_id) +{ +#ifndef _GENERIC_KERNEL_HEADERS + int fd = -1; + int rc; + struct ufs_ioctl_query_data *data = NULL; + size_t ioctl_data_size = sizeof(struct ufs_ioctl_query_data) + UFS_ATTR_DATA_SIZE; + + data = (struct ufs_ioctl_query_data*)malloc(ioctl_data_size); + if (!data) { + fprintf(stderr, "%s: Failed to alloc query data struct\n", + __func__); + goto error; + } + memset(data, 0, ioctl_data_size); + data->opcode = UPIU_QUERY_OPCODE_WRITE_ATTR; + data->idn = QUERY_ATTR_IDN_BOOT_LU_EN; + data->buf_size = UFS_ATTR_DATA_SIZE; + data->buffer[0] = boot_lun_id; + fd = open(sg_dev, O_RDWR); + if (fd < 0) { + fprintf(stderr, "%s: Failed to open %s(%s)\n", + __func__, + sg_dev, + strerror(errno)); + goto error; + } + rc = ioctl(fd, UFS_IOCTL_QUERY, data); + if (rc) { + fprintf(stderr, "%s: UFS query ioctl failed(%s)\n", + __func__, + strerror(errno)); + goto error; + } + close(fd); + free(data); + return 0; +error: + if (fd >= 0) + close(fd); + if (data) + free(data); + return -1; +#else + return 0; +#endif +} +#endif + diff --git a/gpt-utils/recovery-ufs-bsg.h b/gpt-utils/recovery-ufs-bsg.h new file mode 100644 index 0000000..fafea5f --- /dev/null +++ b/gpt-utils/recovery-ufs-bsg.h @@ -0,0 +1,131 @@ +#ifndef __RECOVERY_UFS_BSG_H__ +#define __RECOVERY_UFS_BSG_H__ + +/* + * Copyright (c) 2020 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef ANDROID +#include "cutils/log.h" +#endif + +#ifdef OE +#include +#define LOGI(...) syslog(LOG_NOTICE, "INFO:" __VA_ARGS__) +#define LOGV(...) syslog(LOG_NOTICE,"VERB:" __VA_ARGS__) +#define LOGD(...) syslog(LOG_DEBUG,"DBG:" __VA_ARGS__) +#define LOGE(...) syslog(LOG_ERR,"ERR:" __VA_ARGS__) +#define LOGW(...) syslog(LOG_WARNING,"WRN:" __VA_ARGS__) +#define strlcat(d,s,l) snprintf(d+strlen(d),l,"%s",s) +#endif + + + +#define FNAME_SZ 64 + +#define SG_IO 0x2285 + +#define DWORD(b3, b2, b1, b0) htobe32((b3 << 24) | (b2 << 16) |\ + (b1 << 8) | b0) + +/* UFS BSG device nodes */ +char ufs_bsg_dev[FNAME_SZ] = "/dev/ufs-bsg"; + +int fd_ufs_bsg; + +int32_t set_ufs_lun(uint8_t lun_id); + +#ifdef _BSG_FRAMEWORK_KERNEL_HEADERS +/* UPIU Transaction Codes */ +enum { + UTP_UPIU_NOP_OUT = 0x00, + UTP_UPIU_COMMAND = 0x01, + UTP_UPIU_DATA_OUT = 0x02, + UTP_UPIU_TASK_REQ = 0x04, + UTP_UPIU_QUERY_REQ = 0x16, +}; + +/* UPIU Query Function field */ +enum { + QUERY_REQ_FUNC_STD_READ = 0x01, + QUERY_REQ_FUNC_STD_WRITE = 0x81, +}; + +enum query_req_opcode { + QUERY_REQ_OP_READ_DESC = 0x1, + QUERY_REQ_OP_WRITE_DESC = 0x2, + QUERY_REQ_OP_READ_ATTR = 0x3, + QUERY_REQ_OP_WRITE_ATTR = 0x4, + QUERY_REQ_OP_READ_FLAG = 0x5, + QUERY_REQ_OP_SET_FLAG = 0x6, + QUERY_REQ_OP_CLEAR_FLAG = 0x7, + QUERY_REQ_OP_TOGGLE_FLAG = 0x8, +}; + +enum query_desc_idn { + QUERY_DESC_IDN_DEVICE = 0x0, + QUERY_DESC_IDN_UNIT = 0x2, + QUERY_DESC_IDN_GEOMETRY = 0x7, +}; + +enum query_desc_size { + QUERY_DESC_SIZE_DEVICE = 0x40, + QUERY_DESC_SIZE_GEOMETRY = 0x48, + QUERY_DESC_SIZE_UNIT = 0x23, +}; + +enum bsg_ioctl_dir { + BSG_IOCTL_DIR_TO_DEV, + BSG_IOCTL_DIR_FROM_DEV, +}; + +enum query_attr_idn { + QUERY_ATTR_IDN_BOOT_LU_EN = 0x00, + QUERY_ATTR_IDN_RESERVED = 0x01, + QUERY_ATTR_IDN_POWER_MODE = 0x02, + QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03, +}; +#endif /* _BSG_FRAMEWORK_KERNEL_HEADERS */ + +#endif /* __RECOVERY_UFS_BSG_H__ */ diff --git a/gpt-utils/sparse_crc32.cpp b/gpt-utils/sparse_crc32.cpp new file mode 100644 index 0000000..267322c --- /dev/null +++ b/gpt-utils/sparse_crc32.cpp @@ -0,0 +1,97 @@ +/*- + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + * code or tables extracted from it, as desired without restriction. + */ + +/* + * First, the polynomial itself and its table of feedback terms. The + * polynomial is + * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 + * + * Note that we take it "backwards" and put the highest-order term in + * the lowest-order bit. The X^32 term is "implied"; the LSB is the + * X^31 term, etc. The X^0 term (usually shown as "+1") results in + * the MSB being 1 + * + * Note that the usual hardware shift register implementation, which + * is what we're using (we're merely optimizing it by doing eight-bit + * chunks at a time) shifts bits into the lowest-order term. In our + * implementation, that means shifting towards the right. Why do we + * do it this way? Because the calculated CRC must be transmitted in + * order from highest-order term to lowest-order term. UARTs transmit + * characters in order from LSB to MSB. By storing the CRC this way + * we hand it to the UART in the order low-byte to high-byte; the UART + * sends each low-bit to hight-bit; and the result is transmission bit + * by bit from highest- to lowest-order term without requiring any bit + * shuffling on our part. Reception works similarly + * + * The feedback terms table consists of 256, 32-bit entries. Notes + * + * The table can be generated at runtime if desired; code to do so + * is shown later. It might not be obvious, but the feedback + * terms simply represent the results of eight shift/xor opera + * tions for all combinations of data and CRC register values + * + * The values must be right-shifted by eight bits by the "updcrc + * logic; the shift must be unsigned (bring in zeroes). On some + * hardware you could probably optimize the shift in assembler by + * using byte-swap instructions + * polynomial $edb88320 + * + * + * CRC32 code derived from work by Gary S. Brown. + */ + +/* Code taken from FreeBSD 8 */ +#include +#include + +static uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + +/* + * A function that calculates the CRC-32 based on the table above is + * given below for documentation purposes. An equivalent implementation + * of this function that's actually used in the kernel can be found + * in sys/libkern.h, where it can be inlined. + */ + +uint32_t sparse_crc32(uint32_t crc_in, const void* buf, size_t size) { + const uint8_t* p = reinterpret_cast(buf); + uint32_t crc; + + crc = crc_in ^ ~0U; + while (size--) crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + return crc ^ ~0U; +} diff --git a/gpt-utils/sparse_crc32.h b/gpt-utils/sparse_crc32.h new file mode 100644 index 0000000..2702c4f --- /dev/null +++ b/gpt-utils/sparse_crc32.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _LIBSPARSE_SPARSE_CRC32_H_ +#define _LIBSPARSE_SPARSE_CRC32_H_ + +#include + +uint32_t sparse_crc32(uint32_t crc, const void* buf, size_t size); + +#endif diff --git a/libhidl/Android.bp b/libhidl/Android.bp new file mode 100644 index 0000000..7356726 --- /dev/null +++ b/libhidl/Android.bp @@ -0,0 +1,12 @@ +// +// Copyright (C) 2022 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_shared { + name: "android.hidl.base@1.0", + shared_libs: ["libhidlbase"], + system_ext_specific: true, + vendor_available: true +} diff --git a/libinit/Android.bp b/libinit/Android.bp index 59a0fa8..d3ed028 100644 --- a/libinit/Android.bp +++ b/libinit/Android.bp @@ -1,5 +1,5 @@ // -// Copyright (C) 2021 The LineageOS Project +// Copyright (C) 2022 The LineageOS Project // // SPDX-License-Identifier: Apache-2.0 // @@ -7,7 +7,27 @@ cc_library_static { name: "init_xiaomi_veux", srcs: ["init_xiaomi_veux.cpp"], - whole_static_libs: ["//device/xiaomi/sm6375-common:libinit_xiaomi_holi"], + whole_static_libs: ["//device/xiaomi/veux:libinit_xiaomi_holi"], include_dirs: ["system/core/init"], recovery_available: true, } + +cc_library_static { + name: "libinit_xiaomi_holi", + srcs: [ + "libinit_dalvik_heap.cpp", + "libinit_variant.cpp", + "libinit_utils.cpp", + ], + whole_static_libs: ["libbase"], + export_include_dirs: ["include"], + recovery_available: true, +} + +cc_library_static { + name: "init_xiaomi_holi", + srcs: ["init_xiaomi_holi.cpp"], + whole_static_libs: ["libinit_xiaomi_holi"], + include_dirs: ["system/core/init"], + recovery_available: true, +} \ No newline at end of file diff --git a/libinit/include/libinit_dalvik_heap.h b/libinit/include/libinit_dalvik_heap.h new file mode 100644 index 0000000..caea339 --- /dev/null +++ b/libinit/include/libinit_dalvik_heap.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_HEAP_H +#define LIBINIT_DALVIK_HEAP_H + +#include + +typedef struct dalvik_heap_info { + std::string heapstartsize; + std::string heapgrowthlimit; + std::string heapsize; + std::string heapminfree; + std::string heapmaxfree; + std::string heaptargetutilization; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/include/libinit_utils.h b/libinit/include/libinit_utils.h new file mode 100644 index 0000000..6c42883 --- /dev/null +++ b/libinit/include/libinit_utils.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_UTILS_H +#define LIBINIT_UTILS_H + +#include + +void property_override(std::string prop, std::string value, bool add = true); + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = false); + +std::string fingerprint_to_description(std::string fingerprint); + +#endif // LIBINIT_UTILS_H diff --git a/libinit/include/libinit_variant.h b/libinit/include/libinit_variant.h new file mode 100644 index 0000000..f0b3222 --- /dev/null +++ b/libinit/include/libinit_variant.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_VARIANT_H +#define LIBINIT_VARIANT_H + +#include +#include + +typedef struct variant_info { + std::string hwc_value; + std::string model_value; + + std::string brand; + std::string device; + std::string marketname; + std::string model; + std::string name; + std::string build_fingerprint; + + bool nfc; +} variant_info_t; + +void search_variant(const std::vector variants); + +void set_variant_props(const variant_info_t variant); + +#endif // LIBINIT_VARIANT_H diff --git a/libinit/init_xiaomi_holi.cpp b/libinit/init_xiaomi_holi.cpp new file mode 100644 index 0000000..22cb31e --- /dev/null +++ b/libinit/init_xiaomi_holi.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "vendor_init.h" + +void vendor_load_properties() { + set_dalvik_heap(); +} diff --git a/libinit/init_xiaomi_veux.cpp b/libinit/init_xiaomi_veux.cpp index 2324f05..98bbb7c 100644 --- a/libinit/init_xiaomi_veux.cpp +++ b/libinit/init_xiaomi_veux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 The LineageOS Project + * Copyright (C) 2022 The LineageOS Project * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,95 +10,121 @@ #include "vendor_init.h" static const variant_info_t veux_global_info = { + .hwc_value = "Global", .model_value = "S88006AA1", - .sku_value = "", .brand = "Redmi", .device = "veux", .marketname = "Redmi Note 11 Pro 5G", .model = "2201116SG", .name = "veux_global", - .build_fingerprint = "Redmi/veux_global/veux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "Redmi/veux_global/veux:11/RKQ1.211001.001/V13.0.14.0.RKCMIXM:user/release-keys", .nfc = true, }; +static const variant_info_t veux_in_info = { + .hwc_value = "India", + .model_value = "S88006AA1", + + .brand = "Redmi", + .device = "veux", + .marketname = "Redmi Note 11 Pro 5G", + .model = "2201116SG", + .name = "veux_in", + .build_fingerprint = "Redmi/veux_in/veux:11/RKQ1.211001.001/V13.0.4.0.RKCINXM:user/release-keys", +}; + static const variant_info_t veux_info = { + .hwc_value = "CN", .model_value = "S88007AA1", - .sku_value = "", .brand = "Redmi", .device = "veux", .marketname = "Redmi Note 11E Pro", .model = "2201116SC", .name = "veux", - .build_fingerprint = "Redmi/veux/veux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "Redmi/veux/veux:11/RKQ1.211001.001/V13.0.7.0.RKCCNXM:user/release-keys", .nfc = true, }; static const variant_info_t peux_in_info = { + .hwc_value = "", .model_value = "S88007EA1", - .sku_value = "", .brand = "Redmi", .device = "peux", .marketname = "Redmi Note 11 Pro+ 5G", .model = "2201116SI", .name = "peux_in", - .build_fingerprint = "Redmi/peux_in/peux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "Redmi/peux_in/peux:11/RKQ1.211001.001/V13.0.4.0.RKCINXM:user/release-keys", }; static const variant_info_t veux_jp_info = { + .hwc_value = "", .model_value = "S88008BA1", - .sku_value = "", .brand = "Redmi", .device = "veux", .marketname = "Redmi Note 11 Pro 5G", .model = "2201116SR", .name = "veux_jp", - .build_fingerprint = "Redmi/veux_jp/veux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "Redmi/veux/veux:11/RKQ1.211001.001/V13.0.2.0.RKCJPXM:user/release-keys", .nfc = true, }; static const variant_info_t veux_p_global_info = { + .hwc_value = "Global", .model_value = "S88106BA1", - .sku_value = "", .brand = "POCO", .device = "veux", .marketname = "POCO X4 Pro 5G", .model = "2201116PG", .name = "veux_p_global", - .build_fingerprint = "POCO/veux_p_global/veux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "POCO/veux_p_global/veux:11/RKQ1.211001.001/V13.0.14.0.RKCMIXM:user/release-keys", .nfc = true, }; +static const variant_info_t veux_p_in_info = { + .hwc_value = "India", + .model_value = "S88106BA1", + + .brand = "POCO", + .device = "veux", + .marketname = "POCO X4 Pro 5G", + .model = "2201116PG", + .name = "veux_p_in", + .build_fingerprint = "POCO/veux_p_in/veux:11/RKQ1.211001.001/V13.0.4.0.RKCINXM:user/release-keys", +}; + static const variant_info_t peux_p_in_info = { + .hwc_value = "India", .model_value = "S88107BA1", - .sku_value = "", .brand = "POCO", .device = "veux", .marketname = "POCO X4 Pro 5G", .model = "2201116PI", .name = "peux_p_in", - .build_fingerprint = "POCO/peux_p_in/peux:11/RKQ1.211001.001/V13.0.10.0.RKCMIXM:user/release-keys", + .build_fingerprint = "POCO/peux_p_in/peux:11/RKQ1.211001.001/V13.0.4.0.RKCINXM:user/release-keys", }; static const std::vector variants = { veux_global_info, + veux_in_info, veux_info, peux_in_info, veux_jp_info, veux_p_global_info, + veux_p_in_info, peux_p_in_info, }; void vendor_load_properties() { search_variant(variants); set_dalvik_heap(); -} +} \ No newline at end of file diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp new file mode 100644 index 0000000..b3b24ba --- /dev/null +++ b/libinit/libinit_dalvik_heap.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +#define HEAPSTARTSIZE_PROP "dalvik.vm.heapstartsize" +#define HEAPGROWTHLIMIT_PROP "dalvik.vm.heapgrowthlimit" +#define HEAPSIZE_PROP "dalvik.vm.heapsize" +#define HEAPMINFREE_PROP "dalvik.vm.heapminfree" +#define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree" +#define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization" + +#define GB(b) (b * 1024ull * 1024 * 1024) + +static const dalvik_heap_info_t dalvik_heap_info_6144 = { + .heapstartsize = "16m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "32m", + .heaptargetutilization = "0.5", +}; + +static const dalvik_heap_info_t dalvik_heap_info_4096 = { + .heapstartsize = "8m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "16m", + .heaptargetutilization = "0.6", +}; + +static const dalvik_heap_info_t dalvik_heap_info_2048 = { + .heapstartsize = "8m", + .heapgrowthlimit = "192m", + .heapsize = "512m", + .heapminfree = "512k", + .heapmaxfree = "8m", + .heaptargetutilization = "0.75", +}; + +void set_dalvik_heap() { + struct sysinfo sys; + const dalvik_heap_info_t *dhi; + + sysinfo(&sys); + + if (sys.totalram > GB(5)) + dhi = &dalvik_heap_info_6144; + else if (sys.totalram > GB(3)) + dhi = &dalvik_heap_info_4096; + else + dhi = &dalvik_heap_info_2048; + + property_override(HEAPSTARTSIZE_PROP, dhi->heapstartsize); + property_override(HEAPGROWTHLIMIT_PROP, dhi->heapgrowthlimit); + property_override(HEAPSIZE_PROP, dhi->heapsize); + property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization); + property_override(HEAPMINFREE_PROP, dhi->heapminfree); + property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree); +} diff --git a/libinit/libinit_utils.cpp b/libinit/libinit_utils.cpp new file mode 100644 index 0000000..50f5c35 --- /dev/null +++ b/libinit/libinit_utils.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include +#include + +#include + +void property_override(std::string prop, std::string value, bool add) { + auto pi = (prop_info *) __system_property_find(prop.c_str()); + if (pi != nullptr) { + __system_property_update(pi, value.c_str(), value.length()); + } else if (add) { + __system_property_add(prop.c_str(), prop.length(), value.c_str(), value.length()); + } +} + +std::vector ro_props_default_source_order = { + "odm.", + "product.", + "system.", + "system_ext.", + "vendor.", + "", +}; + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product) { + std::string prop_name; + + for (const auto &source : ro_props_default_source_order) { + if (product) + prop_name = "ro.product." + source + prop; + else + prop_name = "ro." + source + "build." + prop; + + property_override(prop_name, value, true); + } +} + +#define FIND_AND_REMOVE(s, delimiter, variable_name) \ + std::string variable_name = s.substr(0, s.find(delimiter)); \ + s.erase(0, s.find(delimiter) + delimiter.length()); + +#define APPEND_STRING(s, to_append) \ + s.append(" "); \ + s.append(to_append); + +std::string fingerprint_to_description(std::string fingerprint) { + std::string delimiter = "/"; + std::string delimiter2 = ":"; + std::string build_fingerprint_copy = fingerprint; + + FIND_AND_REMOVE(build_fingerprint_copy, delimiter, brand) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter, product) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, device) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter, platform_version) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_id) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter2, build_number) + FIND_AND_REMOVE(build_fingerprint_copy, delimiter, build_variant) + std::string build_version_tags = build_fingerprint_copy; + + std::string description = product + "-" + build_variant; + APPEND_STRING(description, platform_version) + APPEND_STRING(description, build_id) + APPEND_STRING(description, build_number) + APPEND_STRING(description, build_version_tags) + + return description; +} diff --git a/libinit/libinit_variant.cpp b/libinit/libinit_variant.cpp new file mode 100644 index 0000000..99babbf --- /dev/null +++ b/libinit/libinit_variant.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +using android::base::GetProperty; + + +#define HWC_PROP "ro.boot.hwc" +#define MODEL_PROP "ro.boot.board_id" +#define SKU_PROP "ro.boot.product.hardware.sku" + +void search_variant(const std::vector variants) { + std::string hwc_value = GetProperty(HWC_PROP, ""); + std::string model_value = GetProperty(MODEL_PROP, ""); + + for (const auto& variant : variants) { + if ((variant.hwc_value == "" || variant.hwc_value == hwc_value) && + (variant.model_value == "" || variant.model_value == model_value)) { + set_variant_props(variant); + break; + } + } +} + +void set_variant_props(const variant_info_t variant) { + set_ro_build_prop("brand", variant.brand, true); + set_ro_build_prop("device", variant.device, true); + set_ro_build_prop("marketname", variant.marketname, true); + set_ro_build_prop("model", variant.model, true); + set_ro_build_prop("name", variant.name, true); + + if (access("/system/bin/recovery", F_OK) != 0) { + set_ro_build_prop("fingerprint", variant.build_fingerprint); + property_override("ro.bootimage.build.fingerprint", variant.build_fingerprint); + + property_override("ro.build.description", fingerprint_to_description(variant.build_fingerprint)); + } + + if (variant.nfc) + property_override(SKU_PROP, "nfc"); +} diff --git a/lineage.dependencies b/lineage.dependencies deleted file mode 100644 index 37f142d..0000000 --- a/lineage.dependencies +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "repository": "android_device_xiaomi_sm6375-common", - "target_path": "device/xiaomi/sm6375-common" - } -] diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 0000000..c81b0fa --- /dev/null +++ b/manifest.xml @@ -0,0 +1,727 @@ + + + + android.hardware.audio + hwbinder + 6.0 + + IDevicesFactory + default + + @6.0::IDevicesFactory/default + + + android.hardware.audio.effect + hwbinder + 6.0 + + IEffectsFactory + default + + @6.0::IEffectsFactory/default + + + android.hardware.bluetooth + hwbinder + 1.0 + + IBluetoothHci + default + + @1.0::IBluetoothHci/default + + + android.hardware.bluetooth.audio + hwbinder + 2.1 + + IBluetoothAudioProvidersFactory + default + + @2.1::IBluetoothAudioProvidersFactory/default + + + android.hardware.camera.provider + hwbinder + 2.4 + + ICameraProvider + legacy/0 + + @2.4::ICameraProvider/legacy/0 + + + android.hardware.drm + hwbinder + @1.3::ICryptoFactory/wfdhdcp + @1.3::IDrmFactory/wfdhdcp + + + android.hardware.gatekeeper + hwbinder + 1.0 + + IGatekeeper + default + + @1.0::IGatekeeper/default + + + android.hardware.ir + hwbinder + 1.0 + + IConsumerIr + default + + @1.0::IConsumerIr/default + + + android.hardware.keymaster + hwbinder + 4.1 + + IKeymasterDevice + default + + @4.1::IKeymasterDevice/default + + + android.hardware.media.omx + hwbinder + 1.0 + + IOmx + default + + + IOmxStore + default + + @1.0::IOmx/default + @1.0::IOmxStore/default + + + android.hardware.memtrack + hwbinder + 1.0 + + IMemtrack + default + + @1.0::IMemtrack/default + + + android.hardware.radio + hwbinder + @1.2::ISap/slot1 + @1.2::ISap/slot2 + @1.5::IRadio/slot1 + @1.5::IRadio/slot2 + + + android.hardware.radio.config + hwbinder + 1.1 + + IRadioConfig + default + + @1.1::IRadioConfig/default + + + android.hardware.secure_element + hwbinder + 1.2 + + ISecureElement + SIM1 + SIM2 + + @1.2::ISecureElement/SIM1 + @1.2::ISecureElement/SIM2 + + + android.hardware.soundtrigger + hwbinder + 2.3 + + ISoundTriggerHw + default + + @2.3::ISoundTriggerHw/default + + + android.hardware.tetheroffload.config + hwbinder + 1.0 + + IOffloadConfig + default + + @1.0::IOffloadConfig/default + + + android.hardware.tetheroffload.control + hwbinder + 1.0 + + IOffloadControl + default + + @1.0::IOffloadControl/default + + + com.qualcomm.qti.dpm.api + hwbinder + 1.0 + + IdpmQmi + dpmQmiService + + @1.0::IdpmQmi/dpmQmiService + + + com.qualcomm.qti.imscmservice + hwbinder + 2.2 + + IImsCmService + qti.ims.connectionmanagerservice + + @2.2::IImsCmService/qti.ims.connectionmanagerservice + + + com.qualcomm.qti.uceservice + hwbinder + 2.3 + + IUceService + com.qualcomm.qti.uceservice + + @2.3::IUceService/com.qualcomm.qti.uceservice + + + interfaces.factoryAta + hwbinder + 1.0 + + IFactoryAta + default + + @1.0::IFactoryAta/default + + + interfaces.factoryInterface + hwbinder + 1.0 + + IFactoryInterface + default + + @1.0::IFactoryInterface/default + + + vendor.lineage.livedisplay + hwbinder + 2.0 + + IDisplayModes + default + + + IPictureAdjustment + default + + @2.0::IDisplayModes/default + @2.0::IPictureAdjustment/default + + + vendor.qti.data.factory + hwbinder + 2.2 + + IFactory + default + + @2.2::IFactory/default + + + vendor.qti.hardware.alarm + hwbinder + 1.0 + + IAlarm + default + + @1.0::IAlarm/default + + + vendor.qti.hardware.bluetooth_audio + hwbinder + 2.1 + + IBluetoothAudioProvidersFactory + default + + + + vendor.qti.hardware.bluetooth_sar + hwbinder + 1.1 + + IBluetoothSar + default + + @1.1::IBluetoothSar/default + + + vendor.qti.hardware.btconfigstore + hwbinder + 2.0 + + IBTConfigStore + default + + @2.0::IBTConfigStore/default + + + vendor.qti.hardware.cacert + hwbinder + 1.0 + + IService + default + + @1.0::IService/default + + + vendor.qti.hardware.camera.postproc + hwbinder + 1.0 + + IPostProcService + camerapostprocservice + + @1.0::IPostProcService/camerapostprocservice + + + vendor.qti.hardware.capabilityconfigstore + hwbinder + 1.0 + + ICapabilityConfigStore + default + + @1.0::ICapabilityConfigStore/default + + + vendor.qti.hardware.data.connection + hwbinder + 1.1 + + IDataConnection + slot1 + slot2 + + @1.1::IDataConnection/slot1 + @1.1::IDataConnection/slot2 + + + vendor.qti.hardware.data.iwlan + hwbinder + 1.0 + + IIWlan + slot1 + slot2 + + @1.0::IIWlan/slot1 + @1.0::IIWlan/slot2 + + + vendor.qti.hardware.data.latency + hwbinder + 1.0 + + ILinkLatency + default + + @1.0::ILinkLatency/default + + + vendor.qti.hardware.dsp + hwbinder + 1.0 + + IDspService + dspservice + + @1.0::IDspService/dspservice + + + vendor.qti.hardware.eid + hwbinder + 1.0 + + IEid + default + + @1.0::IEid/default + + + vendor.qti.hardware.embmssl + hwbinder + 1.1 + + IEmbms + embmsslServer0 + + @1.1::IEmbms/embmsslServer0 + + + vendor.qti.hardware.factory + hwbinder + 1.1 + + IFactory + default + + @1.1::IFactory/default + + + vendor.qti.hardware.fm + hwbinder + 1.0 + + IFmHci + default + + @1.0::IFmHci/default + + + vendor.qti.hardware.fstman + hwbinder + 1.0 + + IFstManager + default + + @1.0::IFstManager/default + + + vendor.qti.hardware.iop + hwbinder + 2.0 + + IIop + default + + @2.0::IIop/default + + + vendor.qti.hardware.perf + hwbinder + 2.2 + + IPerf + default + + @2.2::IPerf/default + + + vendor.qti.hardware.qccvndhal + hwbinder + 1.0 + + IQccvndhal + qccvndhal + + @1.0::IQccvndhal/qccvndhal + + + vendor.qti.hardware.qseecom + hwbinder + 1.0 + + IQSEECom + default + + @1.0::IQSEECom/default + + + vendor.qti.hardware.qteeconnector + hwbinder + 1.0 + + IAppConnector + default + + + IGPAppConnector + default + + @1.0::IAppConnector/default + @1.0::IGPAppConnector/default + + + vendor.qti.hardware.radio.am + hwbinder + 1.0 + + IQcRilAudio + slot1 + slot2 + + @1.0::IQcRilAudio/slot1 + @1.0::IQcRilAudio/slot2 + + + vendor.qti.hardware.radio.ims + hwbinder + 1.7 + + IImsRadio + imsradio0 + imsradio1 + + @1.7::IImsRadio/imsradio0 + @1.7::IImsRadio/imsradio1 + + + vendor.qti.hardware.radio.internal.deviceinfo + hwbinder + 1.0 + + IDeviceInfo + deviceinfo + + @1.0::IDeviceInfo/deviceinfo + + + vendor.qti.hardware.radio.lpa + hwbinder + 1.1 + + IUimLpa + UimLpa0 + UimLpa1 + + @1.1::IUimLpa/UimLpa0 + @1.1::IUimLpa/UimLpa1 + + + vendor.qti.hardware.radio.qcriNvOpt + hwbinder + 1.0 + + IqcriNvOpt + qcrinvopt0 + qcrinvopt1 + + @1.0::IqcriNvOpt/qcrinvopt0 + @1.0::IqcriNvOpt/qcrinvopt1 + + + vendor.qti.hardware.radio.qcrilhook + hwbinder + 1.0 + + IQtiOemHook + oemhook0 + oemhook1 + + @1.0::IQtiOemHook/oemhook0 + @1.0::IQtiOemHook/oemhook1 + + + vendor.qti.hardware.radio.qtiradio + hwbinder + 1.0 + + IQtiRadio + slot1 + slot2 + + @1.0::IQtiRadio/slot1 + @1.0::IQtiRadio/slot2 + + + vendor.qti.hardware.radio.qtiradio + hwbinder + 2.6 + + IQtiRadio + slot1 + slot2 + + @2.6::IQtiRadio/slot1 + @2.6::IQtiRadio/slot2 + + + vendor.qti.hardware.radio.uim + hwbinder + 1.2 + + IUim + Uim0 + Uim1 + + @1.2::IUim/Uim0 + @1.2::IUim/Uim1 + + + vendor.qti.hardware.radio.uim_remote_client + hwbinder + 1.0 + + IUimRemoteServiceClient + uimRemoteClient0 + uimRemoteClient1 + + @1.0::IUimRemoteServiceClient/uimRemoteClient0 + @1.0::IUimRemoteServiceClient/uimRemoteClient1 + + + vendor.qti.hardware.radio.uim_remote_server + hwbinder + 1.0 + + IUimRemoteServiceServer + uimRemoteServer0 + uimRemoteServer1 + + @1.0::IUimRemoteServiceServer/uimRemoteServer0 + @1.0::IUimRemoteServiceServer/uimRemoteServer1 + + + vendor.qti.hardware.sensorscalibrate + hwbinder + 1.0 + + ISensorsCalibrate + default + + @1.0::ISensorsCalibrate/default + + + vendor.qti.hardware.soter + hwbinder + 1.0 + + ISoter + default + + @1.0::ISoter/default + + + vendor.qti.hardware.tui_comm + hwbinder + 1.0 + + ITuiComm + default + + @1.0::ITuiComm/default + + + vendor.qti.hardware.wifi.wifilearner + hwbinder + 1.0 + + IWifiStats + wifiStats + + @1.0::IWifiStats/wifiStats + + + vendor.qti.hardware.wifidisplaysession + hwbinder + 1.0 + + IWifiDisplaySession + wifidisplaysession + + + IWifiDisplaySessionAudioTrack + wifidisplaysessionaudiotrack + + + IWifiDisplaySessionImageTrack + wifidisplaysessionimagetrack + + + IWifiDisplaySessionVideoTrack + wifidisplaysessionvideotrack + + @1.0::IWifiDisplaySession/wifidisplaysession + @1.0::IWifiDisplaySessionAudioTrack/wifidisplaysessionaudiotrack + @1.0::IWifiDisplaySessionImageTrack/wifidisplaysessionimagetrack + @1.0::IWifiDisplaySessionVideoTrack/wifidisplaysessionvideotrack + + + vendor.qti.hardware.wigig.netperftuner + hwbinder + 1.0 + + INetPerfTuner + default + + @1.0::INetPerfTuner/default + + + vendor.qti.hardware.wigig.supptunnel + hwbinder + 1.0 + + ISuppTunnelProvider + default + + @1.0::ISuppTunnelProvider/default + + + vendor.qti.ims.callinfo + hwbinder + 1.0 + + IService + default + + @1.0::IService/default + + + vendor.qti.ims.factory + hwbinder + 1.1 + + IImsFactory + default + + @1.1::IImsFactory/default + + + vendor.qti.imsrtpservice + hwbinder + 3.0 + + IRTPService + imsrtpservice + + @3.0::IRTPService/imsrtpservice + + + vendor.qti.qspmhal + hwbinder + 1.0 + + IQspmhal + default + + @1.0::IQspmhal/default + + diff --git a/manifest_nfc.xml b/manifest_nfc.xml new file mode 100644 index 0000000..41ad3be --- /dev/null +++ b/manifest_nfc.xml @@ -0,0 +1,29 @@ + + + android.hardware.nfc + hwbinder + 1.2 + + INfc + default + + + + vendor.nxp.nxpnfc + hwbinder + 2.0 + + INxpNfc + default + + + + vendor.nxp.nxpnfclegacy + hwbinder + 1.0 + + INxpNfcLegacy + default + + + diff --git a/odm.prop b/odm.prop new file mode 100644 index 0000000..585fab2 --- /dev/null +++ b/odm.prop @@ -0,0 +1,2 @@ +# Qcom +ro.vendor.qti.va_odm.support=1 diff --git a/org.ifaa.android.manager/Android.bp b/org.ifaa.android.manager/Android.bp new file mode 100644 index 0000000..74904e0 --- /dev/null +++ b/org.ifaa.android.manager/Android.bp @@ -0,0 +1,30 @@ +/* +* Copyright (C) 2017-2020 The LineageOS Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +java_library { + name: "org.ifaa.android.manager", + installable: true, + srcs: [ + "src/**/*.java", + "src/**/I*.aidl", + ], + libs: [ + "unsupportedappusage", + ], + aidl: { + local_include_dirs: ["src"], + }, +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManager.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManager.java new file mode 100644 index 0000000..82cb659 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManager.java @@ -0,0 +1,69 @@ +package org.ifaa.android.manager; + +import android.compat.annotation.UnsupportedAppUsage; +import android.content.Context; +import android.os.Build.VERSION; +import android.os.SystemProperties; + +public abstract class IFAAManager { + private static final int IFAA_VERSION_V2 = 2; + private static final int IFAA_VERSION_V3 = 3; + private static final int IFAA_VERSION_V4 = 4; + + static int sIfaaVer; + static boolean sIsFod = SystemProperties.getBoolean("ro.hardware.fp.fod", false); + + /** + * 返回手机系统上支持的校验方式,目前IFAF协议1.0版本指纹为0x01、虹膜为0x02 + */ + @UnsupportedAppUsage + public abstract int getSupportBIOTypes(Context context); + + /** + * 启动系统的指纹/虹膜管理应用界面,让用户进行指纹录入。指纹录入是在系统的指纹管理应用中实现的, + * 本函数的作用只是将指纹管理应用运行起来,直接进行页面跳转,方便用户录入。 + * @param context + * @param authType 生物特征识别类型,指纹为1,虹膜为2 + * @return 0,成功启动指纹管理应用;-1,启动指纹管理应用失败。 + */ + @UnsupportedAppUsage + public abstract int startBIOManager(Context context, int authType); + + /** + * 通过ifaateeclient的so文件实现REE到TA的通道 + * @param context + * @param param 用于传输到IFAA TA的数据buffer + * @return IFAA TA返回给REE数据buffer + */ + @UnsupportedAppUsage + public native byte[] processCmd(Context context, byte[] param); + + /** + * 获取设备型号,同一款机型型号需要保持一致 + */ + @UnsupportedAppUsage + public abstract String getDeviceModel(); + + /** + * 获取IFAAManager接口定义版本,目前为1 + */ + @UnsupportedAppUsage + public abstract int getVersion(); + + /** + * load so to communicate from REE to TEE + */ + static { + sIfaaVer = 1; + + if (VERSION.SDK_INT >= 28) { + sIfaaVer = IFAA_VERSION_V4; + } else if (sIsFod) { + sIfaaVer = IFAA_VERSION_V3; + } else if (VERSION.SDK_INT >= 24) { + sIfaaVer = IFAA_VERSION_V2; + } else { + System.loadLibrary("teeclientjni"); //teeclientjni for TA test binary //ifaateeclient + } + } +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerFactory.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerFactory.java new file mode 100644 index 0000000..3697874 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerFactory.java @@ -0,0 +1,11 @@ +package org.ifaa.android.manager; + +import android.compat.annotation.UnsupportedAppUsage; +import android.content.Context; + +public class IFAAManagerFactory { + @UnsupportedAppUsage + public static IFAAManager getIFAAManager(Context context, int authType) { + return IFAAManagerImpl.getInstance(context); + } +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerImpl.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerImpl.java new file mode 100644 index 0000000..120aed9 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerImpl.java @@ -0,0 +1,322 @@ +package org.ifaa.android.manager; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Build; +import android.os.Build.VERSION; +import android.os.HwBinder; +import android.os.HwBlob; +import android.os.HwParcel; +import android.os.IBinder; +import android.os.IBinder.DeathRecipient; +import android.os.IHwBinder; +import android.os.Parcel; +import android.os.RemoteException; +import android.os.SystemProperties; +import android.util.Slog; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.json.JSONObject; + +public class IFAAManagerImpl extends IFAAManagerV4 { + private static final int CODE_PROCESS_CMD = 1; + private static final int CODE_GETIDLIST_CMD = 2; + + private static final int IFAA_TYPE_FINGER = 1; + private static final int IFAA_TYPE_IRIS = 2; + private static final int IFAA_TYPE_SENSOR_FOD = 16; + + private static final int ACTIVITY_START_SUCCESS = 0; + private static final int ACTIVITY_START_FAILED = -1; + + private static volatile IFAAManagerImpl INSTANCE = null; + + private static final String CA_CERT_ALIAS_DELIMITER = " "; + + private static final String INTERFACE_DESCRIPTOR = + "vendor.xiaomi.hardware.mlipay@1.0::IMlipayService"; + private static final String SERVICE_NAME = + "vendor.xiaomi.hardware.mlipay@1.0::IMlipayService"; + private static final String TAG = "IfaaManagerImpl"; + + private static final String mIfaaActName = "org.ifaa.android.manager.IFAAService"; + private static final String mIfaaInterfaceDesc = "org.ifaa.android.manager.IIFAAService"; + private static final String mIfaaPackName = "com.tencent.soter.soterserver"; + + private static IBinder mService = null; + private String mDevModel = null; + private static Context mContext = null; + + private static ServiceConnection ifaaconn = new ServiceConnection() { + public void onServiceConnected(ComponentName name, IBinder service) { + mService = service; + try { + mService.linkToDeath(mDeathRecipient, 0); + } catch (RemoteException e) { + Slog.e(TAG, "linkToDeath fail.", e); + } + } + + public void onServiceDisconnected(ComponentName name) { + if (mContext != null) { + Slog.i(TAG, "re-bind the service."); + initService(); + } + } + }; + + private static DeathRecipient mDeathRecipient = new DeathRecipient() { + public void binderDied() { + if (mService != null) { + Slog.d(TAG, "binderDied, unlink the service."); + mService.unlinkToDeath(mDeathRecipient, 0); + } + } + }; + + public static IFAAManagerV4 getInstance(Context context) { + if (INSTANCE == null) { + synchronized (IFAAManagerImpl.class) { + if (INSTANCE == null) { + INSTANCE = new IFAAManagerImpl(); + if (VERSION.SDK_INT >= 28) { + mContext = context; + initService(); + } + } + } + } + + return INSTANCE; + } + + private String initExtString() { + String extStr = ""; + JSONObject obj = new JSONObject(); + JSONObject keyInfo = new JSONObject(); + String xy = ""; + String wh = ""; + + if (VERSION.SDK_INT >= 28) { + xy = SystemProperties.get("persist.vendor.sys.fp.fod.location.X_Y", ""); + wh = SystemProperties.get("persist.vendor.sys.fp.fod.size.width_height", ""); + } else { + xy = SystemProperties.get("persist.sys.fp.fod.location.X_Y", ""); + wh = SystemProperties.get("persist.sys.fp.fod.size.width_height", ""); + } + + try { + if (validateVal(xy) && validateVal(wh)) { + String[] splitXy = xy.split(","); + String[] splitWh = wh.split(","); + keyInfo.put("startX", Integer.parseInt(splitXy[0])); + keyInfo.put("startY", Integer.parseInt(splitXy[1])); + keyInfo.put("width", Integer.parseInt(splitWh[0])); + keyInfo.put("height", Integer.parseInt(splitWh[1])); + keyInfo.put("navConflict", true); + obj.put("type", 0); + obj.put("fullView", keyInfo); + extStr = obj.toString(); + } else { + Slog.e(TAG, "initExtString invalidate, xy:" + xy + " wh:" + wh); + } + } catch (Exception e) { + Slog.e(TAG, "Exception , xy:" + xy + " wh:" + wh, e); + } + + return extStr; + } + + private static void initService() { + Intent ifaaIntent = new Intent(); + ifaaIntent.setClassName(mIfaaPackName, mIfaaActName); + if (!mContext.bindService(ifaaIntent, ifaaconn, 1)) { + Slog.e(TAG, "cannot bind service org.ifaa.android.manager.IFAAService"); + } + } + + private boolean validateVal(String value) { + return !"".equalsIgnoreCase(value) && value.contains(","); + } + + public String getDeviceModel() { + if (mDevModel == null) { + mDevModel = Build.MANUFACTURER + "-" + Build.DEVICE; + } + + Slog.i(TAG, "getDeviceModel deviceModel:" + mDevModel); + return mDevModel; + } + + public int getEnabled(int bioType) { + return 1 == bioType ? 1000 : 1003; + } + + public String getExtInfo(int authType, String keyExtInfo) { + Slog.i(TAG, "getExtInfo:" + authType + CA_CERT_ALIAS_DELIMITER + keyExtInfo); + return initExtString(); + } + + public int[] getIDList(int bioType) { + int[] idList = new int[]{0}; + if (1 == bioType) { + int retry_count = 10; + while (true) { + int retry_count2 = retry_count - 1; + if (retry_count <= 0) { + break; + } + if (mService == null || !mService.pingBinder()) { + try { + Thread.sleep(30); + } catch (InterruptedException e) { + Slog.e(TAG, "getIDList InterruptedException while waiting: " + e, e); + } + } else { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + try { + data.writeInterfaceToken(mIfaaInterfaceDesc); + data.writeInt(bioType); + mService.transact(CODE_GETIDLIST_CMD, data, reply, 0); + reply.readException(); + idList = reply.createIntArray(); + } catch (RemoteException e) { + Slog.e(TAG, "getIDList transact failed. ", e); + } catch (Throwable th) { + data.recycle(); + reply.recycle(); + } + data.recycle(); + reply.recycle(); + } + retry_count = retry_count2; + } + } + return idList; + } + + public int getSupportBIOTypes(Context context) { + int ifaaProp; + String fpVendor = ""; + + if (VERSION.SDK_INT >= 28) { + ifaaProp = SystemProperties.getInt("persist.vendor.sys.pay.ifaa", 0); + fpVendor = SystemProperties.get("persist.vendor.sys.fp.vendor", ""); + } else { + ifaaProp = SystemProperties.getInt("persist.sys.ifaa", 0); + fpVendor = SystemProperties.get("persist.sys.fp.vendor", ""); + } + + int res = "none".equalsIgnoreCase(fpVendor) ? + ifaaProp & IFAA_TYPE_IRIS : ifaaProp & (IFAA_TYPE_FINGER | IFAA_TYPE_IRIS); + + if ((res & IFAA_TYPE_FINGER) == IFAA_TYPE_FINGER && sIsFod) { + res |= IFAA_TYPE_SENSOR_FOD; + } + + Slog.i(TAG, "getSupportBIOTypes:" + ifaaProp + ", " + sIsFod + ", " + fpVendor + + ", res:" + res); + return res; + } + + public int getVersion() { + Slog.i(TAG, "getVersion sdk:" + VERSION.SDK_INT + " ifaaVer:" + sIfaaVer); + return sIfaaVer; + } + + public byte[] processCmdV2(Context context, byte[] param) { + Slog.i(TAG, "processCmdV2 sdk:" + VERSION.SDK_INT); + + if (VERSION.SDK_INT >= 28) { + int retry_count = 10; + + while (true) { + int retry_count2 = retry_count - 1; + if (retry_count <= 0) { + break; + } + if (mService == null || !mService.pingBinder()) { + Slog.i(TAG, "processCmdV2 waiting ifaaService, remain: " + retry_count2 + + " time(s)"); + try { + Thread.sleep(30); + } catch (InterruptedException e) { + Slog.e(TAG, "processCmdV2 InterruptedException while waiting: " + e, e); + } + } else { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + try { + data.writeInterfaceToken(mIfaaInterfaceDesc); + data.writeByteArray(param); + mService.transact(CODE_PROCESS_CMD, data, reply, 0); + reply.readException(); + return reply.createByteArray(); + } catch (RemoteException e) { + Slog.e(TAG, "processCmdV2 transact failed. ", e); + retry_count = retry_count2; + } finally { + data.recycle(); + reply.recycle(); + } + } + retry_count = retry_count2; + } + + Slog.e(TAG, "processCmdV2, return null"); + return null; + } + + HwParcel hidl_reply = new HwParcel(); + try { + IHwBinder hwService = HwBinder.getService(SERVICE_NAME, "default"); + if (hwService != null) { + HwParcel hidl_request = new HwParcel(); + hidl_request.writeInterfaceToken(INTERFACE_DESCRIPTOR); + ArrayList sbuf = new ArrayList(Arrays.asList(HwBlob.wrapArray(param))); + hidl_request.writeInt8Vector(sbuf); + hidl_request.writeInt32(sbuf.size()); + hwService.transact(CODE_PROCESS_CMD, hidl_request, hidl_reply, 0); + hidl_reply.verifySuccess(); + hidl_request.releaseTemporaryStorage(); + ArrayList val = hidl_reply.readInt8Vector(); + byte[] array = new byte[val.size()]; + for (int i = 0; i < val.size(); i++) { + array[i] = ((Byte) val.get(i)).byteValue(); + } + hidl_reply.release(); + return array; + } + } catch (RemoteException e) { + Slog.e(TAG, "transact failed. ", e); + } catch (Throwable th) { + hidl_reply.release(); + } + + hidl_reply.release(); + Slog.e(TAG, "processCmdV2, return null"); + return null; + } + + public void setExtInfo(int authType, String keyExtInfo, String valExtInfo) { + } + + public int startBIOManager(Context context, int authType) { + int res = ACTIVITY_START_FAILED; + + if (authType == IFAA_TYPE_FINGER) { + Intent intent = new Intent("android.settings.SECURITY_SETTINGS"); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + res = ACTIVITY_START_SUCCESS; + } + + Slog.i(TAG, "startBIOManager authType:" + authType + " res:" + res); + return res; + } +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV2.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV2.java new file mode 100644 index 0000000..d634ef0 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV2.java @@ -0,0 +1,9 @@ +package org.ifaa.android.manager; + +import android.compat.annotation.UnsupportedAppUsage; +import android.content.Context; + +public abstract class IFAAManagerV2 extends IFAAManager { + @UnsupportedAppUsage + public abstract byte[] processCmdV2(Context paramContext, byte[] paramArrayOfByte); +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV3.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV3.java new file mode 100644 index 0000000..328fd75 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV3.java @@ -0,0 +1,20 @@ +package org.ifaa.android.manager; + +import android.compat.annotation.UnsupportedAppUsage; + +public abstract class IFAAManagerV3 extends IFAAManagerV2 { + @UnsupportedAppUsage + public static final String KEY_FINGERPRINT_FULLVIEW = "org.ifaa.ext.key.CUSTOM_VIEW"; + @UnsupportedAppUsage + public static final String KEY_GET_SENSOR_LOCATION = "org.ifaa.ext.key.GET_SENSOR_LOCATION"; + @UnsupportedAppUsage + public static final String VALUE_FINGERPRINT_DISABLE = "disable"; + @UnsupportedAppUsage + public static final String VLAUE_FINGERPRINT_ENABLE = "enable"; + + @UnsupportedAppUsage + public abstract String getExtInfo(int authType, String keyExtInfo); + + @UnsupportedAppUsage + public abstract void setExtInfo(int authType, String keyExtInfo, String valExtInfo); +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV4.java b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV4.java new file mode 100644 index 0000000..2c47557 --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IFAAManagerV4.java @@ -0,0 +1,11 @@ +package org.ifaa.android.manager; + +import android.compat.annotation.UnsupportedAppUsage; + +public abstract class IFAAManagerV4 extends IFAAManagerV3 { + @UnsupportedAppUsage + public abstract int getEnabled(int i); + + @UnsupportedAppUsage + public abstract int[] getIDList(int i); +} diff --git a/org.ifaa.android.manager/src/org/ifaa/android/manager/IIFAAService.aidl b/org.ifaa.android.manager/src/org/ifaa/android/manager/IIFAAService.aidl new file mode 100644 index 0000000..80937fe --- /dev/null +++ b/org.ifaa.android.manager/src/org/ifaa/android/manager/IIFAAService.aidl @@ -0,0 +1,12 @@ +package org.ifaa.android.manager; + +interface IIFAAService { + byte[] processCmd_v2(in byte[] param); + int[] getIDList(int bioType); + int faceEnroll(String sessionId, int flags); + int faceUpgrade(int action, String path, int offset, in byte[] data, int data_len); + int faceAuthenticate_v2(String sessionId, int flags); + int faceCancel_v2(String sessionId); + byte[] faceInvokeCommand(in byte[] param); + int faceGetCellinfo(); +} diff --git a/overlay-lineage/frameworks/base/packages/SystemUI/res/values/config.xml b/overlay-lineage/frameworks/base/packages/SystemUI/res/values/config.xml deleted file mode 100644 index b72d76e..0000000 --- a/overlay-lineage/frameworks/base/packages/SystemUI/res/values/config.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - 6 - 7 - - - false - - diff --git a/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml b/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml deleted file mode 100644 index fbc6c95..0000000 --- a/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 64 - - - 64 - - - true - - - true - - - - restart - restart_recovery - restart_bootloader - restart_fastboot - - diff --git a/overlay-lineage/packages/apps/Settings/res/values/config.xml b/overlay-lineage/packages/apps/Settings/res/values/config.xml deleted file mode 100644 index 1b4f8d6..0000000 --- a/overlay-lineage/packages/apps/Settings/res/values/config.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - 3 - diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml deleted file mode 100644 index 0749e77..0000000 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ /dev/null @@ -1,374 +0,0 @@ - - - - - - - - true - - - - 1 - 2 - 4 - 6 - 8 - 10 - 15 - 20 - 25 - 30 - 35 - 40 - 45 - 50 - 55 - 60 - 65 - 70 - 75 - 80 - 85 - 90 - 95 - 100 - 120 - 140 - 160 - 180 - 200 - 220 - 240 - 260 - 280 - 300 - 320 - 340 - 360 - 380 - 400 - 420 - 440 - 460 - 480 - 500 - 700 - 900 - 1100 - 1300 - 1500 - 1700 - 1900 - 2000 - 2500 - 3000 - 3500 - 4000 - 4500 - 5000 - 5500 - 6000 - 6500 - 7000 - 7500 - 8000 - 8500 - 9000 - 9500 - 10000 - 10500 - 11000 - 11500 - 12000 - 12500 - 13000 - 13500 - 14000 - 14500 - 15000 - 16000 - 17000 - 18000 - 19000 - 20000 - 21000 - 22000 - 23000 - 24000 - 25000 - 26000 - 27000 - 28000 - 29000 - 30000 - 35000 - 40000 - 45000 - 50000 - 55000 - 60000 - 65000 - 70000 - 75000 - 80000 - 85000 - 90000 - 95000 - 100000 - - - - - 4.5 - 6.6 - 8.0 - 20.0 - 24.3 - 29.7 - 34.0 - 46.0 - 59.0 - 76.0 - 81.0 - 82.0 - 82.0 - 82.0 - 83.0 - 83.0 - 83.0 - 84.0 - 84.0 - 85.0 - 85.0 - 85.0 - 85.0 - 86.0 - 86.0 - 87.0 - 89.0 - 90.0 - 91.0 - 93.0 - 94.0 - 96.0 - 97.0 - 99.0 - 100.0 - 101.0 - 104.0 - 105.0 - 106.0 - 108.0 - 109.0 - 111.0 - 112.0 - 114.0 - 116.0 - 137.0 - 157.0 - 180.0 - 205.0 - 226.0 - 257.0 - 280.0 - 295.0 - 369.0 - 400.0 - 416.7 - 433.3 - 450.0 - 466.7 - 483.3 - 500.0 - 512.5 - 525.0 - 537.5 - 550.0 - 562.5 - 575.0 - 587.5 - 600.0 - 610.0 - 620.0 - 630.0 - 640.0 - 650.0 - 660.0 - 670.0 - 680.0 - 690.0 - 700.0 - 705.0 - 710.0 - 715.0 - 720.0 - 725.0 - 730.0 - 735.0 - 740.0 - 745.0 - 750.0 - 755.0 - 760.0 - 765.0 - 770.0 - 775.0 - 800.0 - 816.7 - 833.3 - 850.0 - 866.7 - 883.3 - 900.0 - 914.3 - 928.6 - 942.9 - 957.1 - 971.4 - 985.7 - 1000.0 - - - - - 4.5 - 1000.0 - - - - - 1 - 255 - - - - 1000 - 1000 - - - 100.0% - - - - 0 - 10 - - - - - 0 - 10 - - - - - 10 - - - - - M 25,20 - h -50 - v 80 - h 50 - Z - - - - true - - - 0 - - - 120 - true - true - - - true - - - true - - - - - @array/config_sfps_sensor_props_0 - - - - - 1080 - 920 - 200 - - - diff --git a/overlay/frameworks/base/core/res/res/values/dimens.xml b/overlay/frameworks/base/core/res/res/values/dimens.xml deleted file mode 100644 index be50eef..0000000 --- a/overlay/frameworks/base/core/res/res/values/dimens.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - 47.0px - 102.0px - 110.0px - - diff --git a/overlay/frameworks/base/core/res/res/xml/power_profile.xml b/overlay/frameworks/base/core/res/res/xml/power_profile.xml deleted file mode 100644 index bc60d86..0000000 --- a/overlay/frameworks/base/core/res/res/xml/power_profile.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - 0.1 - 100.2 - 208 - 9 - 0.47 - 0.32 - 148 - 25 - 13.6 - 57 - 86 - 616 - 45 - 217 - 47 - - 2.82 - 1.82 - - - 0.1 - - - 6 - 2 - - - 300000 - 576000 - 710400 - 940800 - 1190400 - 1324800 - 1478400 - 1574400 - 1708800 - 1804800 - - - 691200 - 940800 - 1228800 - 1401600 - 1516800 - 1651200 - 1804800 - 1900800 - 2054400 - 2208000 - - - 35 - 39 - 46 - 65 - 86 - 105 - 117 - 172 - 187 - 208 - - - 91 - 91 - 146 - 190 - 215 - 257 - 322 - 366 - 421 - 526 - - 4.78 - - 22.7 - - 5000 - 5000 - 1.4 - 177 - 269 - - 3300 - - .0002 - .002 - .02 - .2 - 2 - - 0 - 1 - 200 - - 293 - 296 - 316 - 401 - 506 - - 800 - - 0 - 0 - - 0 - \ No newline at end of file diff --git a/overlay/frameworks/base/packages/SystemUI/res/values/config.xml b/overlay/frameworks/base/packages/SystemUI/res/values/config.xml deleted file mode 100644 index 08814de..0000000 --- a/overlay/frameworks/base/packages/SystemUI/res/values/config.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - false - - diff --git a/overlay/frameworks/base/packages/SystemUI/res/values/dimens.xml b/overlay/frameworks/base/packages/SystemUI/res/values/dimens.xml deleted file mode 100644 index 60abc46..0000000 --- a/overlay/frameworks/base/packages/SystemUI/res/values/dimens.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - 1080px - - - 1030px - - - @dimen/physical_power_button_center_screen_location_y - - diff --git a/overlay/packages/apps/Settings/res/values/config.xml b/overlay/packages/apps/Settings/res/values/config.xml deleted file mode 100644 index 4144c28..0000000 --- a/overlay/packages/apps/Settings/res/values/config.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - true - - diff --git a/permissions/privapp-permissions-hotword.xml b/permissions/privapp-permissions-hotword.xml new file mode 100644 index 0000000..7ab2bab --- /dev/null +++ b/permissions/privapp-permissions-hotword.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/proprietary-files.txt b/proprietary-files.txt index 75ea891..0690fef 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -136,6 +136,12 @@ vendor/etc/spk_cal_pinknoise.wav vendor/etc/spk_cal_silence.wav vendor/etc/usb_audio_policy_configuration.xml +# ADSP +vendor/bin/adsprpcd +vendor/etc/init/vendor.qti.adsprpc-guestos-service.rc +vendor/lib64/libadsp_default_listener.so +vendor/lib64/libadsprpc.so + # Audio Effects vendor/lib/soundfx/libhwdap.so vendor/lib/soundfx/libmisoundfx.so @@ -146,6 +152,12 @@ vendor/lib64/soundfx/libmisoundfx.so vendor/lib64/soundfx/libswdap.so vendor/lib64/soundfx/libswgamedap.so +# Audio FX modules +system_ext/etc/permissions/audiosphere.xml +system_ext/framework/audiosphere.jar +vendor/lib/soundfx/libasphere.so +vendor/lib/soundfx/libshoebox.so + # Audio Hardware vendor/lib/hw/audio.primary.holi.so vendor/lib/liba2dpoffload.so @@ -156,6 +168,37 @@ vendor/lib/libhdmipassthru.so vendor/lib/libqtigef.so vendor/lib/libssrec.so +# Bluetooth +vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti +vendor/etc/init/android.hardware.bluetooth@1.0-service-qti.rc +vendor/lib64/hw/android.hardware.bluetooth@1.0-impl-qti.so +vendor/lib64/hw/vendor.qti.hardware.bluetooth_sar@1.1-impl.so +vendor/lib64/hw/vendor.qti.hardware.btconfigstore@1.0-impl.so +vendor/lib64/hw/vendor.qti.hardware.btconfigstore@2.0-impl.so +vendor/lib64/libbtnv.so +vendor/lib64/libsoc_helper.so +vendor/lib64/vendor.qti.hardware.bluetooth_sar@1.0.so +vendor/lib64/vendor.qti.hardware.bluetooth_sar@1.1.so +vendor/lib64/vendor.qti.hardware.fm@1.0.so + +# Bluetooth (A2DP) +vendor/lib/hw/audio.bluetooth_qti.default.so +vendor/lib/hw/vendor.qti.hardware.bluetooth_audio@2.0-impl.so +vendor/lib/hw/vendor.qti.hardware.bluetooth_audio@2.1-impl.so +vendor/lib/btaudio_offload_if.so +vendor/lib/libbluetooth_audio_session_qti.so +vendor/lib/libbluetooth_audio_session_qti_2_1.so + +# Bluetooth (aptX) - from crosshatch - RQ1A.201205.003 +system_ext/lib64/libaptXHD_encoder.so|e13fa70c97caaa24d061678bdee608eb8850a69e +system_ext/lib64/libaptX_encoder.so|df1c89d7af1bb35808d5fe3496b04ba066c10cbc + +# CAcert +-vendor/app/CACertService/CACertService.apk +vendor/lib64/libcacertclient.so +vendor/lib64/libjnihelper.so +vendor/lib64/vendor.qti.hardware.cacert@1.0.so + # Camera vendor/lib64/camera/com.qti.eeprom.gt24p128c2csli_imx766.so vendor/lib64/camera/com.qti.eeprom.irs2381c_polar.so @@ -277,11 +320,9 @@ vendor/lib64/libarcsoft_high_dynamic_range.so vendor/lib64/libarcsoft_low_light_hdr.so vendor/lib64/libbitmlengine.so vendor/lib64/libbitmlenginev2.so -vendor/lib64/libbitmlenginev2.so vendor/lib64/libc++_shared.so vendor/lib64/libcamera_nn_stub.so vendor/lib64/libcamera_scene.so -vendor/lib64/libcamera_scene.so vendor/lib64/libcamerapostproc.so vendor/lib64/libcamxswispiqmodule.so vendor/lib64/libcapiv2svacnn.so @@ -303,8 +344,6 @@ vendor/lib64/libmmcamera_mfnr_t4.so vendor/lib64/libmmcamera_pdpc.so vendor/lib64/libmpbase.so vendor/lib64/libofflinedump.so -vendor/lib64/libofflinedump.so -vendor/lib64/libofflinelog.so vendor/lib64/libofflinelog.so vendor/lib64/libopencv.so vendor/lib64/libopestriping.so @@ -349,7 +388,6 @@ vendor/lib64/libcamxifestriping.so vendor/lib64/libcamximageformatutils.so vendor/lib64/libcamxqsatalgo.so vendor/lib64/libcamxstatscore.so -vendor/lib64/libcamxswispiqmodule.so vendor/lib64/libcamxswprocessalgo.so vendor/lib64/libcamxtintlessalgo.so @@ -361,99 +399,57 @@ vendor/lib64/camera/components/com.qti.camx.chiiqutils.so vendor/lib64/camera/components/com.qti.eisv2.so vendor/lib64/camera/components/com.qti.eisv3.so vendor/lib64/camera/components/com.qti.hvx.addconstant.so -vendor/lib64/camera/components/com.qti.hvx.addconstant.so -vendor/lib64/camera/components/com.qti.hvx.binning.so vendor/lib64/camera/components/com.qti.hvx.binning.so vendor/lib64/camera/components/com.qti.node.customhwnode.so -vendor/lib64/camera/components/com.qti.node.customhwnode.so -vendor/lib64/camera/components/com.qti.node.depth.so vendor/lib64/camera/components/com.qti.node.depth.so vendor/lib64/camera/components/com.qti.node.dewarp.so -vendor/lib64/camera/components/com.qti.node.dewarp.so -vendor/lib64/camera/components/com.qti.node.dummyrtb.so vendor/lib64/camera/components/com.qti.node.dummyrtb.so vendor/lib64/camera/components/com.qti.node.dummysat.so vendor/lib64/camera/components/com.qti.node.eisv2.so -vendor/lib64/camera/components/com.qti.node.eisv2.so -vendor/lib64/camera/components/com.qti.node.eisv3.so vendor/lib64/camera/components/com.qti.node.eisv3.so vendor/lib64/camera/components/com.qti.node.fcv.so -vendor/lib64/camera/components/com.qti.node.fcv.so vendor/lib64/camera/components/com.qti.node.formatconversion.so vendor/lib64/camera/components/com.qti.node.gpu.so -vendor/lib64/camera/components/com.qti.node.gpu.so -vendor/lib64/camera/components/com.qti.node.memcpy.so vendor/lib64/camera/components/com.qti.node.memcpy.so vendor/lib64/camera/components/com.qti.node.mialgocontrol.so vendor/lib64/camera/components/com.qti.node.mimovie.so vendor/lib64/camera/components/com.qti.node.ml.so -vendor/lib64/camera/components/com.qti.node.ml.so vendor/lib64/camera/components/com.qti.node.remosaic.so -vendor/lib64/camera/components/com.qti.node.remosaic.so -vendor/lib64/camera/components/com.qti.node.stich.so vendor/lib64/camera/components/com.qti.node.stich.so vendor/lib64/camera/components/com.qti.node.swaidenoiser.so -vendor/lib64/camera/components/com.qti.node.swaidenoiser.so vendor/lib64/camera/components/com.qti.node.swbestats.so vendor/lib64/camera/components/com.qti.node.swcac.so -vendor/lib64/camera/components/com.qti.node.swcac.so vendor/lib64/camera/components/com.qti.node.swec.so vendor/lib64/camera/components/com.qti.node.swfusion.so vendor/lib64/camera/components/com.qti.node.swlsc.so -vendor/lib64/camera/components/com.qti.node.swlsc.so -vendor/lib64/camera/components/com.qti.node.swmctf.so vendor/lib64/camera/components/com.qti.node.swmctf.so vendor/lib64/camera/components/com.qti.node.swmfnr.so -vendor/lib64/camera/components/com.qti.node.swmfnr.so vendor/lib64/camera/components/com.qti.node.swpdpc.so vendor/lib64/camera/components/com.qti.node.swpreprocess.so -vendor/lib64/camera/components/com.qti.node.swpreprocess.so vendor/lib64/camera/components/com.qti.node.swregistration.so -vendor/lib64/camera/components/com.qti.node.swregistration.so -vendor/lib64/camera/components/com.qti.stats.aec.so vendor/lib64/camera/components/com.qti.stats.aec.so vendor/lib64/camera/components/com.qti.stats.aecwrapper.so -vendor/lib64/camera/components/com.qti.stats.aecwrapper.so -vendor/lib64/camera/components/com.qti.stats.aecxcore.so vendor/lib64/camera/components/com.qti.stats.aecxcore.so vendor/lib64/camera/components/com.qti.stats.af.so -vendor/lib64/camera/components/com.qti.stats.af.so vendor/lib64/camera/components/com.qti.stats.afd.so -vendor/lib64/camera/components/com.qti.stats.afd.so -vendor/lib64/camera/components/com.qti.stats.afwrapper.so vendor/lib64/camera/components/com.qti.stats.afwrapper.so vendor/lib64/camera/components/com.qti.stats.asd.so -vendor/lib64/camera/components/com.qti.stats.asd.so -vendor/lib64/camera/components/com.qti.stats.awb.so vendor/lib64/camera/components/com.qti.stats.awb.so vendor/lib64/camera/components/com.qti.stats.awbwrapper.so -vendor/lib64/camera/components/com.qti.stats.awbwrapper.so -vendor/lib64/camera/components/com.qti.stats.cnndriver.so vendor/lib64/camera/components/com.qti.stats.cnndriver.so vendor/lib64/camera/components/com.qti.stats.haf.so -vendor/lib64/camera/components/com.qti.stats.haf.so -vendor/lib64/camera/components/com.qti.stats.hafoverride.so vendor/lib64/camera/components/com.qti.stats.hafoverride.so vendor/lib64/camera/components/com.qti.stats.pdlib.so -vendor/lib64/camera/components/com.qti.stats.pdlib.so -vendor/lib64/camera/components/com.qti.stats.pdlibsony.so vendor/lib64/camera/components/com.qti.stats.pdlibsony.so vendor/lib64/camera/components/com.qti.stats.pdlibwrapper.so -vendor/lib64/camera/components/com.qti.stats.pdlibwrapper.so -vendor/lib64/camera/components/com.qti.stats.tracker.so vendor/lib64/camera/components/com.qti.stats.tracker.so vendor/lib64/camera/components/com.qtistatic.stats.aec.so -vendor/lib64/camera/components/com.qtistatic.stats.aec.so -vendor/lib64/camera/components/com.qtistatic.stats.af.so vendor/lib64/camera/components/com.qtistatic.stats.af.so vendor/lib64/camera/components/com.qtistatic.stats.awb.so -vendor/lib64/camera/components/com.qtistatic.stats.awb.so -vendor/lib64/camera/components/com.qtistatic.stats.pdlib.so vendor/lib64/camera/components/com.qtistatic.stats.pdlib.so vendor/lib64/camera/components/com.vidhance.node.processing.so vendor/lib64/camera/components/libdepthmapwrapper.so vendor/lib64/camera/components/libdepthmapwrapper_secure.so -vendor/lib64/camera/components/libdepthmapwrapper_secure.so # Camera configs vendor/etc/camera/model/cap_model/ldc_cap_cache @@ -514,12 +510,10 @@ vendor/etc/camera/morpho_lowlight_2.0_sunny_s5khm2_main_i_4x.xml vendor/etc/camera/morpho_lowlight_2.0_sunny_s5khm2_main_i_6x.xml vendor/etc/camera/morpho_lowlight_2.0_sunny_s5khm2_main_i_8x.xml vendor/etc/camera/vidhance_calibration -vendor/etc/camera/vidhance_calibration vendor/etc/camera/vidhance_kernel1.bin vendor/etc/camera/vidhance_kernel2.bin # Camera sensors -vendor/lib64/libmmcamera_cac3.so vendor/lib64/libmmcamera_faceproc.so vendor/lib64/libmmcamera_faceproc2.so vendor/lib64/libmmcamera_lscv35.so @@ -528,6 +522,92 @@ vendor/lib64/libmmcamera_mfnr.so # Charger (Mi Turbo Charge) vendor/bin/batterysecret +# CDSP +vendor/bin/cdsprpcd +vendor/etc/init/vendor.qti.cdsprpc-service.rc +vendor/lib64/libcdsp_default_listener.so +vendor/lib64/libcdsprpc.so +vendor/lib64/libmdsprpc.so +vendor/lib64/libsdsprpc.so + +# CNE +vendor/app/CneApp/lib/arm64/libvndfwk_detect_jni.qti.so +-vendor/app/CneApp/CneApp.apk +vendor/bin/cnd +vendor/etc/cne/mwqem.conf +vendor/etc/cne/profileMwqem.xml +vendor/etc/default-permissions/com.qualcomm.qti.cne.xml +vendor/etc/init/cnd.rc +vendor/lib64/libcne.so +vendor/lib64/libcneapiclient.so +vendor/lib64/libcneoplookup.so +vendor/lib64/libcneqmiutils.so +vendor/lib64/libwms.so +vendor/lib64/libwqe.so +vendor/lib64/libxml.so +vendor/lib64/vendor.qti.data.factory@2.0.so +vendor/lib64/vendor.qti.data.factory@2.1.so +vendor/lib64/vendor.qti.data.factory@2.2.so +vendor/lib64/vendor.qti.data.factory@2.3.so +vendor/lib64/vendor.qti.data.mwqem@1.0.so +vendor/lib64/vendor.qti.data.slm@1.0.so +vendor/lib64/vendor.qti.hardware.data.cne.internal.api@1.0.so +vendor/lib64/vendor.qti.hardware.data.cne.internal.constants@1.0.so +vendor/lib64/vendor.qti.hardware.data.cne.internal.server@1.0.so +vendor/lib64/vendor.qti.hardware.data.dynamicdds@1.0.so +vendor/lib64/vendor.qti.hardware.data.iwlan@1.0.so +vendor/lib64/vendor.qti.hardware.data.latency@1.0.so +vendor/lib64/vendor.qti.hardware.data.lce@1.0.so +vendor/lib64/vendor.qti.hardware.data.qmi@1.0.so +vendor/lib64/vendor.qti.hardware.mwqemadapter@1.0.so +vendor/lib64/vendor.qti.hardware.slmadapter@1.0.so +vendor/lib64/vendor.qti.latency@2.0.so +vendor/lib64/vendor.qti.latency@2.1.so + +# CNE profiles +vendor/etc/cne/wqeclient/ATT/ATT_profile1.xml +vendor/etc/cne/wqeclient/ATT/ATT_profile2.xml +vendor/etc/cne/wqeclient/ATT/ATT_profile3.xml +vendor/etc/cne/wqeclient/ATT/ATT_profile4.xml +vendor/etc/cne/wqeclient/ATT/ATT_profile5.xml +vendor/etc/cne/wqeclient/ATT/ATT_profile6.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile1.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile15.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile16.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile17.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile18.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile19.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile2.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile20.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile21.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile3.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile32.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile4.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile5.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile6.xml +vendor/etc/cne/wqeclient/ROW/ROW_profile7.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile1.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile2.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile3.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile4.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile5.xml +vendor/etc/cne/wqeclient/VZW/VZW_profile6.xml + +# Computer Vision (FastCV) +vendor/lib64/libcvp_common.so +vendor/lib64/libcvpcpuRev_skel.so +vendor/lib64/libfastcvdsp_stub.so +-vendor/lib64/libfastcvopt.so +vendor/lib64/vendor.qti.hardware.cvp@1.0.so + +# Configstore +vendor/bin/hw/vendor.qti.hardware.capabilityconfigstore@1.0-service +vendor/etc/init/vendor.qti.hardware.capabilityconfigstore@1.0-service.rc +vendor/lib64/hw/vendor.qti.hardware.capabilityconfigstore@1.0-impl.so + +# Consumer IR +vendor/lib64/hw/consumerir.default.so:vendor/lib64/hw/consumerir.holi.so + # CVP Firmware vendor/firmware/evass-lt.b00 vendor/firmware/evass-lt.b01 @@ -574,24 +654,102 @@ vendor/firmware/evass.b19 vendor/firmware/evass.mbn vendor/firmware/evass.mdt +# Display +vendor/bin/qdcmss +vendor/etc/display/DPU660.xml +vendor/etc/display/DPU670.xml +vendor/etc/display/DPU720.xml +vendor/etc/display/DPU7__.xml +vendor/etc/display/advanced_sf_offsets.xml +vendor/etc/init/qdcmss.rc +vendor/lib64/libdisplayqos.so +vendor/lib64/libdisplayskuutils.so +vendor/lib64/libdpps.so +vendor/lib64/libhdr_tm.so +vendor/lib64/libqdcm-mode-parser.so +vendor/lib64/libqrtrclient.so +vendor/lib64/libqseed3.so +vendor/lib64/librcmask.so +vendor/lib64/libsdm-color.so +vendor/lib64/libsdm-colormgr-algo.so +vendor/lib64/libsdm-diag.so +vendor/lib64/libsdm-disp-vndapis.so +vendor/lib64/libsdmextension.so +vendor/lib64/libsnapdragoncolor-manager.so +vendor/lib64/libsnapdragoncolor-qdcm.so +vendor/lib64/libtinyxml2_1.so + # Display calibration vendor/etc/qdcm_calib_data_xiaomi_k6s_38_0c_0a_fhd_dsc_video_dsi_panel.xml -# Graphics firmware -vendor/firmware/a615_zap.b00 -vendor/firmware/a615_zap.b01 -vendor/firmware/a615_zap.b02 -vendor/firmware/a615_zap.elf -vendor/firmware/a615_zap.mdt -vendor/firmware/a619_gmu.bin -vendor/firmware/a630_sqe.fw -vendor/firmware/a660_gmu.bin -vendor/firmware/a660_sqe.fw -vendor/firmware/a660_zap.b00 -vendor/firmware/a660_zap.b01 -vendor/firmware/a660_zap.b02 -vendor/firmware/a660_zap.elf -vendor/firmware/a660_zap.mdt +# Display postprocessing +vendor/bin/hw/vendor.display.color@1.0-service +vendor/bin/ppd +vendor/etc/init/vendor.display.color@1.0-service.rc +vendor/lib64/libdisp-aba.so +vendor/lib64/vendor.display.color@1.0.so +vendor/lib64/vendor.display.color@1.1.so +vendor/lib64/vendor.display.color@1.2.so +vendor/lib64/vendor.display.color@1.3.so +vendor/lib64/vendor.display.color@1.4.so +vendor/lib64/vendor.display.color@1.5.so +vendor/lib64/vendor.display.postproc@1.0.so + +# DPM +system/framework/tcmclient.jar +system_ext/bin/dpmd +system_ext/etc/dpm/dpm.conf +system_ext/etc/init/dpmd.rc +system_ext/etc/permissions/com.qti.dpmframework.xml +system_ext/etc/permissions/dpmapi.xml +system_ext/framework/com.qti.dpmframework.jar +system_ext/framework/dpmapi.jar +system_ext/lib64/com.qualcomm.qti.dpm.api@1.0.so +system_ext/lib64/libdpmctmgr.so +system_ext/lib64/libdpmfdmgr.so +system_ext/lib64/libdpmframework.so +system_ext/lib64/libdpmtcm.so +-system_ext/priv-app/dpmserviceapp/dpmserviceapp.apk +vendor/bin/dpmQmiMgr +vendor/etc/init/dpmQmiMgr.rc +vendor/lib64/com.qualcomm.qti.dpm.api@1.0.so +vendor/lib64/libdpmqmihal.so + +# DRM +vendor/bin/qseecomd +vendor/etc/init/qseecomd.rc +vendor/etc/gpfspath_oem_config.xml +vendor/lib64/libGPreqcancel.so +vendor/lib64/libGPreqcancel_svc.so +vendor/lib64/libQSEEComAPI.so +vendor/lib64/libcpion.so +vendor/lib64/libdrmfs.so +vendor/lib64/libdrmtime.so +vendor/lib64/libminkdescriptor.so +vendor/lib64/libminksocket.so +vendor/lib64/liboemcrypto.so +vendor/lib64/libops.so +vendor/lib64/libqcbor.so +vendor/lib64/libqisl.so +vendor/lib64/librpmb.so +vendor/lib64/libssd.so +vendor/lib64/libtrustedapploader.so + +# DRM (Widevine) +vendor/bin/hw/android.hardware.drm@1.3-service.widevine +vendor/etc/init/android.hardware.drm@1.3-service.widevine.rc +-vendor/etc/vintf/manifest/manifest_android.hardware.drm@1.3-service.widevine.xml +vendor/lib64/mediadrm/libwvdrmengine.so +vendor/lib64/libwvhidl.so + +# DSP service +vendor/bin/dspservice +vendor/etc/init/vendor.qti.hardware.dsp@1.0-service.rc +vendor/etc/seccomp_policy/vendor.qti.hardware.dsp.policy +vendor/lib64/vendor.qti.hardware.dsp@1.0.so + +# Embedded Secure Element power manager +vendor/lib64/vendor.qti.esepowermanager@1.0.so # Fingerprint vendor/bin/hw/vendor.silead.hardware.fingerprintext@1.0-service @@ -614,12 +772,153 @@ vendor/lib64/vendor.silead.hardware.fingerprintext@1.0.so # Firmware vendor/firmware/fs1958.fsm +# Graphics +vendor/lib/egl/eglSubDriverAndroid.so +vendor/lib/egl/libEGL_adreno.so +vendor/lib/egl/libGLESv1_CM_adreno.so +vendor/lib/egl/libGLESv2_adreno.so +vendor/lib/egl/libq3dtools_adreno.so +vendor/lib/egl/libq3dtools_esx.so +vendor/lib/hw/vulkan.adreno.so +vendor/lib/libC2D2.so +vendor/lib/libCB.so +vendor/lib/libOpenCL.so +vendor/lib/libadreno_utils.so +vendor/lib/libc2d30_bltlib.so +vendor/lib/libgsl.so +vendor/lib/libllvm-glnext.so +vendor/lib/libllvm-qcom.so +vendor/lib64/egl/eglSubDriverAndroid.so +vendor/lib64/egl/libEGL_adreno.so +vendor/lib64/egl/libGLESv1_CM_adreno.so +vendor/lib64/egl/libGLESv2_adreno.so +vendor/lib64/egl/libq3dtools_adreno.so +vendor/lib64/egl/libq3dtools_esx.so +vendor/lib64/hw/vulkan.adreno.so +vendor/lib64/libC2D2.so +vendor/lib64/libCB.so +vendor/lib64/libOpenCL.so +vendor/lib64/libadreno_utils.so +vendor/lib64/libc2d30_bltlib.so +vendor/lib64/libgsl.so +vendor/lib64/libllvm-glnext.so +vendor/lib64/libllvm-qcom.so + +# Graphics firmware +vendor/firmware/a615_zap.b00 +vendor/firmware/a615_zap.b01 +vendor/firmware/a615_zap.b02 +vendor/firmware/a615_zap.elf +vendor/firmware/a615_zap.mdt +vendor/firmware/a619_gmu.bin +vendor/firmware/a630_sqe.fw +vendor/firmware/a660_gmu.bin +vendor/firmware/a660_sqe.fw +vendor/firmware/a660_zap.b00 +vendor/firmware/a660_zap.b01 +vendor/firmware/a660_zap.b02 +vendor/firmware/a660_zap.elf +vendor/firmware/a660_zap.mdt + +# Gatekeeper +vendor/bin/hw/android.hardware.gatekeeper@1.0-service-qti +vendor/etc/init/android.hardware.gatekeeper@1.0-service-qti.rc +vendor/lib64/hw/android.hardware.gatekeeper@1.0-impl-qti.so + +# GNSS +vendor/bin/loc_launcher +vendor/bin/lowi-server +vendor/bin/mlid +vendor/bin/xtra-daemon +-vendor/etc/vintf/manifest/vendor.qti.gnss@4.0-service.xml +vendor/lib64/hw/vendor.qti.gnss@4.0-impl.so +vendor/lib64/libaoa.so +vendor/lib64/libcdfw.so +vendor/lib64/libcdfw_remote_api.so +vendor/lib64/libdataitems.so +vendor/lib64/libizat_client_api.so +vendor/lib64/libizat_core.so +vendor/lib64/liblbs_core.so +vendor/lib64/libloc_api_v02.so +vendor/lib64/libloc_socket.so +vendor/lib64/liblocationservice.so +vendor/lib64/liblocationservice_glue.so +vendor/lib64/liblowi_client.so +vendor/lib64/liblowi_wifihal.so +vendor/lib64/libqcc_file_agent.so +vendor/lib64/libsynergy_loc_api.so +vendor/lib64/libxtadapter.so +vendor/lib64/vendor.qti.gnss@1.0.so +vendor/lib64/vendor.qti.gnss@1.1.so +vendor/lib64/vendor.qti.gnss@1.2.so +vendor/lib64/vendor.qti.gnss@2.0.so +vendor/lib64/vendor.qti.gnss@2.1.so +vendor/lib64/vendor.qti.gnss@3.0.so +vendor/lib64/vendor.qti.gnss@4.0-service.so +vendor/lib64/vendor.qti.gnss@4.0.so +vendor/lib64/vendor.qti.hardware.qccsyshal@1.0.so + # HotwordEnrollment -product/priv-app/HotwordEnrollmentOKGoogleHEXAGON/HotwordEnrollmentOKGoogleHEXAGON.apk -product/priv-app/HotwordEnrollmentXGoogleHEXAGON/HotwordEnrollmentXGoogleHEXAGON.apk system_ext/etc/permissions/com.android.hotwordenrollment.common.util.xml system_ext/framework/com.android.hotwordenrollment.common.util.jar +# IMS +-system_ext/app/uceShimService/uceShimService.apk +system_ext/lib64/lib-imsvideocodec.so +system_ext/lib64/lib-imsvt.so +system_ext/lib64/lib-imsvtextutils.so +system_ext/lib64/lib-imsvtutils.so +system_ext/lib64/libdiag_system.so +system_ext/lib64/libimscamera_jni.so +system_ext/lib64/libimsmedia_jni.so +system_ext/lib64/vendor.qti.diaghal@1.0.so +system_ext/lib64/vendor.qti.imsrtpservice@3.0.so +-system_ext/priv-app/ims/ims.apk +vendor/bin/ims_rtp_daemon +vendor/bin/imsdaemon +vendor/etc/init/ims_rtp_daemon.rc +vendor/etc/init/imsdaemon.rc +vendor/etc/seccomp_policy/imsrtp.policy +vendor/lib64/com.qualcomm.qti.imscmservice@1.0.so +vendor/lib64/com.qualcomm.qti.imscmservice@2.0.so +vendor/lib64/com.qualcomm.qti.imscmservice@2.1.so +vendor/lib64/com.qualcomm.qti.imscmservice@2.2.so +vendor/lib64/com.qualcomm.qti.uceservice@2.0.so +vendor/lib64/com.qualcomm.qti.uceservice@2.1.so +vendor/lib64/com.qualcomm.qti.uceservice@2.2.so +vendor/lib64/com.qualcomm.qti.uceservice@2.3.so +vendor/lib64/lib-imscommon.so +vendor/lib64/lib-imsdpl.so +vendor/lib64/lib-imsqimf.so +vendor/lib64/lib-imsrcsservice.so +vendor/lib64/lib-imsservice.so +vendor/lib64/lib-imsvtcore.so +vendor/lib64/lib-imsxml.so +vendor/lib64/lib-rtpcommon.so +vendor/lib64/lib-rtpcore.so +vendor/lib64/lib-rtpsl.so +vendor/lib64/librcc.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.0.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.1.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.2.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.3.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.4.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.5.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.6.so +vendor/lib64/vendor.qti.hardware.radio.ims@1.7.so +vendor/lib64/vendor.qti.ims.callcapability@1.0.so +vendor/lib64/vendor.qti.ims.callinfo@1.0.so +vendor/lib64/vendor.qti.ims.factory@1.0.so +vendor/lib64/vendor.qti.ims.factory@1.1.so +vendor/lib64/vendor.qti.ims.rcsconfig@1.0.so +vendor/lib64/vendor.qti.ims.rcsconfig@1.1.so +vendor/lib64/vendor.qti.ims.rcsconfig@2.0.so +vendor/lib64/vendor.qti.ims.rcsconfig@2.1.so +vendor/lib64/vendor.qti.imsrtpservice@3.0-service-Impl.so +vendor/lib64/vendor.qti.imsrtpservice@3.0.so + # IPA firmware vendor/firmware/ipa_fws.b00 vendor/firmware/ipa_fws.b01 @@ -629,6 +928,30 @@ vendor/firmware/ipa_fws.b04 vendor/firmware/ipa_fws.elf vendor/firmware/ipa_fws.mdt +# IRQ balance +vendor/bin/msm_irqbalance +vendor/etc/msm_irqbalance.conf + +# Keymaster +vendor/bin/hw/android.hardware.keymaster@4.1-service-qti +vendor/etc/init/android.hardware.keymaster@4.1-service-qti.rc +vendor/lib64/libkeymasterdeviceutils.so +vendor/lib64/libkeymasterprovision.so +vendor/lib64/libkeymasterutils.so +vendor/lib64/libqtikeymaster4.so + +# Listen +vendor/lib/hw/sound_trigger.primary.holi.so +vendor/lib/libcapiv2svacnn.so +vendor/lib/libcapiv2svarnn.so +vendor/lib/libcapiv2vop.so +vendor/lib/libgcs-calwrapper.so +vendor/lib/libgcs-ipc.so +vendor/lib/libgcs-osal.so +vendor/lib/libgcs.so +vendor/lib/liblistensoundmodel2.so +vendor/lib/libmulawdec.so + # Media (VPU firmware) vendor/firmware/vpu20_1v.b01 vendor/firmware/vpu20_1v.b02 @@ -697,6 +1020,353 @@ vendor/firmware/vpu20_4v.mbn vendor/firmware/vpu20_4v.mdt vendor/firmware/vpu20_4v_unsigned.mbn +# Media +system_ext/lib/libmmosal.so +system_ext/lib/libmmparser_lite.so +system_ext/lib64/libmmosal.so +system_ext/lib64/libmmparser_lite.so +vendor/bin/hw/vendor.qti.media.c2@1.0-service +vendor/etc/init/vendor.qti.media.c2@1.0-service.rc +vendor/etc/media_blair/video_system_specs.json +vendor/etc/media_holi/video_system_specs.json +vendor/etc/seccomp_policy/codec2.vendor.base-arm.policy +vendor/etc/seccomp_policy/codec2.vendor.ext-arm.policy +-vendor/etc/vintf/manifest/c2_manifest_vendor.xml +vendor/etc/video_system_specs.json +vendor/lib/libmmosal.so +vendor/lib/libqcodec2_base.so +vendor/lib/libqcodec2_basecodec.so +vendor/lib/libqcodec2_core.so +vendor/lib/libqcodec2_hooks.so +vendor/lib/libqcodec2_platform.so +vendor/lib/libqcodec2_utils.so +vendor/lib/libqcodec2_v4l2codec.so +vendor/lib64/libmmosal.so + +# Media Configs +vendor/etc/media_codecs.xml +vendor/etc/media_codecs_blair.xml +vendor/etc/media_codecs_dolby_audio.xml +vendor/etc/media_codecs_google_audio.xml +vendor/etc/media_codecs_google_c2.xml +vendor/etc/media_codecs_google_c2_audio.xml +vendor/etc/media_codecs_google_c2_video.xml +vendor/etc/media_codecs_google_telephony.xml +vendor/etc/media_codecs_google_video.xml +vendor/etc/media_codecs_google_video_le.xml +vendor/etc/media_codecs_holi.xml +vendor/etc/media_codecs_kona.xml +vendor/etc/media_codecs_performance.xml +vendor/etc/media_codecs_performance_blair.xml +vendor/etc/media_codecs_performance_holi.xml +vendor/etc/media_codecs_vendor_audio.xml +vendor/etc/media_profiles.xml +vendor/etc/media_profiles_V1_0.xml +vendor/etc/media_profiles_blair.xml +vendor/etc/media_profiles_holi.xml +vendor/etc/media_profiles_vendor.xml + +# Mlipay +vendor/bin/mlipayd@1.1 +vendor/etc/init/vendor.xiaomi.hardware.mlipay@1.1-service.rc +-vendor/etc/vintf/manifest/manifest_vendor.xiaomi.hardware.mlipay.xml +vendor/lib64/libmlipay.so +vendor/lib64/libmlipay@1.1.so +vendor/lib64/vendor.xiaomi.hardware.mlipay@1.0.so +vendor/lib64/vendor.xiaomi.hardware.mlipay@1.1.so +vendor/lib64/vendor.xiaomi.hardware.mtdservice@1.0.so + +# Neural networks +vendor/bin/hw/android.hardware.neuralnetworks@1.3-service-qti +vendor/etc/init/android.hardware.neuralnetworks@1.3-service-qti.rc +-vendor/etc/vintf/manifest/android.hardware.neuralnetworks@1.3-service-qti.xml +vendor/lib64/unnhal-acc-common.so +vendor/lib64/unnhal-acc-gpu.so +vendor/lib64/unnhal-acc-hvx.so + +# NFC +vendor/bin/hw/android.hardware.nfc@1.2-service +vendor/bin/nqnfcinfo +vendor/etc/init/android.hardware.nfc@1.2-service.rc +vendor/etc/init/init.veux.nfc.rc +vendor/etc/init/init.veux.se.rc +vendor/etc/permissions/com.nxp.nfc.xml:odm/etc/permissions/sku_nfc/com.nxp.nfc.xml +vendor/etc/libese-nxp.conf +vendor/etc/libnfc-mtp-SN100.conf +vendor/etc/libnfc-mtp-SN100_38_4MHZ.conf +vendor/etc/libnfc-nci.conf +vendor/etc/libnfc-nxp.conf +vendor/etc/libnfc-qrd-SN100_38_4MHZ.conf +vendor/lib64/ese_client.so +vendor/lib64/ese_spi_nxp.so +vendor/lib64/hal_libnfc.so +vendor/lib64/libpn557_fw.so +vendor/lib64/ls_client.so +vendor/lib64/nfc_nci_nxp.so +vendor/lib64/vendor.nxp.eventprocessor@1.0.so +vendor/lib64/vendor.nxp.nxpese@1.0.so +vendor/lib64/vendor.nxp.nxpnfc@2.0.so +vendor/lib64/vendor.nxp.nxpnfclegacy@1.0.so +vendor/libnfc-nxp_RF.conf + +# OMX +vendor/lib/libAlacSwDec.so +vendor/lib/libApeSwDec.so +vendor/lib/libMpeghSwEnc.so +vendor/lib/libOmxAacDec.so +vendor/lib/libOmxAlacDec.so +vendor/lib/libOmxAlacDecSw.so +vendor/lib/libOmxAmrwbplusDec.so +vendor/lib/libOmxApeDec.so +vendor/lib/libOmxApeDecSw.so +vendor/lib/libOmxDsdDec.so +vendor/lib/libOmxEvrcDec.so +vendor/lib/libOmxG711Dec.so +vendor/lib/libOmxMpeghDecSw.so +vendor/lib/libOmxMpeghEncSw.so +vendor/lib/libOmxQcelp13Dec.so +vendor/lib/libOmxVideoDSMode.so +vendor/lib/libOmxWmaDec.so +vendor/lib/libdsd2pcm.so +vendor/lib64/libAlacSwDec.so +vendor/lib64/libApeSwDec.so +vendor/lib64/libMpeghSwEnc.so +vendor/lib64/libOmxAacDec.so +vendor/lib64/libOmxAlacDec.so +vendor/lib64/libOmxAlacDecSw.so +vendor/lib64/libOmxAmrwbplusDec.so +vendor/lib64/libOmxApeDec.so +vendor/lib64/libOmxApeDecSw.so +vendor/lib64/libOmxEvrcDec.so +vendor/lib64/libOmxG711Dec.so +vendor/lib64/libOmxMpeghEncSw.so +vendor/lib64/libOmxQcelp13Dec.so +vendor/lib64/libOmxWmaDec.so + +# Perf +vendor/bin/hw/vendor.qti.hardware.perf@2.2-service +vendor/etc/init/vendor.qti.hardware.perf@2.2-service.rc +vendor/etc/perf/commonresourceconfigs.xml +vendor/etc/perf/perfboostsconfig.xml +vendor/etc/perf/perfconfigstore.xml +vendor/etc/perf/targetconfig.xml +vendor/etc/perf/targetresourceconfigs.xml +vendor/lib/libperfconfig.so +vendor/lib/libperfgluelayer.so +vendor/lib/libperfioctl.so +vendor/lib/libqti-perfd-client.so +vendor/lib/libqti-perfd.so +vendor/lib/libqti-util.so +vendor/lib/libqti-utils.so +vendor/lib/vendor.qti.memory.pasrmanager@1.0.so +vendor/lib/vendor.qti.memory.pasrmanager@1.1.so +vendor/lib64/liblearningmodule.so +vendor/lib64/libmeters.so +vendor/lib64/libperfconfig.so +vendor/lib64/libperfgluelayer.so +vendor/lib64/libperfioctl.so +vendor/lib64/libqti-perfd-client.so +vendor/lib64/libqti-perfd.so +vendor/lib64/libqti-util.so +vendor/lib64/libqti-utils.so +vendor/lib64/vendor.qti.memory.pasrmanager@1.0.so +vendor/lib64/vendor.qti.memory.pasrmanager@1.1.so + +# Peripheral manager +vendor/bin/pm-proxy +vendor/bin/pm-service +vendor/lib64/libperipheral_client.so + +# Power-off alarm +-product/app/PowerOffAlarm/PowerOffAlarm.apk +vendor/bin/hw/vendor.qti.hardware.alarm@1.0-service +vendor/bin/power_off_alarm +vendor/etc/init/vendor.qti.hardware.alarm@1.0-service.rc +vendor/lib64/hw/vendor.qti.hardware.alarm@1.0-impl.so +vendor/lib64/vendor.qti.hardware.alarm@1.0.so + +# QCV +vendor/bin/init.qti.qcv.sh +vendor/etc/init/init.qti.qcv.rc + +# QMI +system/etc/sysconfig/qti_whitelist.xml +vendor/bin/irsc_util +vendor/bin/qmipriod +vendor/bin/qrtr-lookup +vendor/bin/qrtr-ns +vendor/etc/init/qmipriod.rc +vendor/etc/sec_config +vendor/lib/libdiag.so +vendor/lib/libdsi_netctrl.so +vendor/lib/libdsutils.so +vendor/lib/libidl.so +vendor/lib/libqcci_legacy.so +vendor/lib/libqcmaputils.so +vendor/lib/libqdi.so +vendor/lib/libqdp.so +vendor/lib/libqmi.so +vendor/lib/libqmi_cci.so +vendor/lib/libqmi_client_helper.so +vendor/lib/libqmi_client_qmux.so +vendor/lib/libqmi_common_so.so +vendor/lib/libqmi_csi.so +vendor/lib/libqmi_encdec.so +vendor/lib/libqmi_legacy.so +vendor/lib/libqmiservices.so +vendor/lib64/libdiag.so +vendor/lib64/libdsi_netctrl.so +vendor/lib64/libdsutils.so +vendor/lib64/libidl.so +vendor/lib64/libqcci_legacy.so +vendor/lib64/libqcmaputils.so +vendor/lib64/libqdi.so +vendor/lib64/libqdp.so +vendor/lib64/libqmi.so +-vendor/lib64/libqmi_cci.so +vendor/lib64/libqmi_client_helper.so +vendor/lib64/libqmi_client_qmux.so +-vendor/lib64/libqmi_common_so.so +vendor/lib64/libqmi_csi.so +vendor/lib64/libqmi_encdec.so +vendor/lib64/libqmi_legacy.so +vendor/lib64/libqmiservices.so +vendor/lib64/libqrtr.so + +# RIL +system/etc/permissions/privapp-permissions-qti.xml +-system_ext/app/QtiTelephonyService/QtiTelephonyService.apk +-system_ext/app/atfwd/atfwd.apk +system_ext/etc/permissions/embms.xml +system_ext/etc/permissions/privapp-permissions-qti-system-ext.xml +system_ext/etc/permissions/qcrilhook.xml +system_ext/etc/permissions/qti_permissions.xml +system_ext/etc/permissions/telephonyservice.xml +-system_ext/framework/embmslibrary.jar +system_ext/framework/qcrilhook.jar +system_ext/lib64/vendor.qti.hardware.radio.am@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.internal.deviceinfo@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.lpa@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.lpa@1.1.so +system_ext/lib64/vendor.qti.hardware.radio.qcrilhook@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.0.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.1.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.2.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.3.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.4.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.5.so +system_ext/lib64/vendor.qti.hardware.radio.qtiradio@2.6.so +system_ext/lib64/vendor.qti.hardware.radio.uim@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.uim@1.1.so +system_ext/lib64/vendor.qti.hardware.radio.uim@1.2.so +system_ext/lib64/vendor.qti.hardware.radio.uim_remote_client@1.0.so +system_ext/lib64/vendor.qti.hardware.radio.uim_remote_client@1.1.so +system_ext/lib64/vendor.qti.hardware.radio.uim_remote_client@1.2.so +system_ext/lib64/vendor.qti.hardware.radio.uim_remote_server@1.0.so +-system_ext/priv-app/qcrilmsgtunnel/qcrilmsgtunnel.apk +-vendor/app/IWlanService/IWlanService.apk +vendor/bin/hw/qcrilNrd +vendor/bin/ATFWD-daemon +vendor/bin/adpl +vendor/bin/diag-router +vendor/bin/netmgrd +vendor/bin/pd-mapper +vendor/bin/port-bridge +vendor/bin/qrtr-cfg +vendor/bin/qti +vendor/bin/rmt_storage +vendor/bin/ssgtzd +vendor/bin/tftp_server +vendor/etc/data/dsi_config.xml +vendor/etc/data/netmgr_config.xml +vendor/etc/init/dataadpl.rc +vendor/etc/init/dataqti.rc +vendor/etc/init/init-qcril-data.rc +vendor/etc/init/netmgrd.rc +vendor/etc/init/port-bridge.rc +vendor/etc/init/qcrilNrd.rc +vendor/etc/init/ssgtzd.rc +vendor/etc/init/vendor.qti.rmt_storage.rc +vendor/etc/init/vendor.qti.tftp.rc +vendor/etc/qcril_database/upgrade/config/10.0_config.sql +vendor/etc/qcril_database/upgrade/config/6.0_config.sql +vendor/etc/qcril_database/upgrade/config/7.0_config.sql +vendor/etc/qcril_database/upgrade/config/8.0_config.sql +vendor/etc/qcril_database/upgrade/config/9.0_config.sql +vendor/etc/qcril_database/upgrade/other/0_initial_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/10_version_update_ecc_table.sql +vendor/etc/qcril_database/upgrade/other/1_version_intro_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/2_version_add_wps_config_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/3_version_update_wps_config_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/4_version_update_ecc_table_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/5_version_update_ecc_table_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/6_version_change_property_table_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/7_version_update_ecc_table_qcrilnr.sql +vendor/etc/qcril_database/upgrade/other/8_version_update_ecc_table.sql +vendor/etc/qcril_database/upgrade/other/9_version_update_ecc_table.sql +vendor/etc/qcril_database/qcrilNr.db +vendor/etc/seccomp_policy/atfwd@2.0.policy +vendor/etc/seccomp_policy/qcrilnr@2.0.policy +vendor/etc/seccomp_policy/qti-systemd.policy +vendor/etc/ssg/ta_config.json +vendor/etc/ssg/tz_whitelist.json +vendor/lib64/deviceInfoServiceModuleNr.so +vendor/lib64/libconfigdb.so +vendor/lib64/liblqe.so +vendor/lib64/libmdmdetect.so +vendor/lib64/libnetmgr.so +vendor/lib64/libnetmgr_common.so +vendor/lib64/libnetmgr_nr_fusion.so +vendor/lib64/libnetmgr_rmnet_ext.so +vendor/lib64/libnlnetmgr.so +vendor/lib64/libpdmapper.so +vendor/lib64/libpdnotifier.so +vendor/lib64/libqcrilNr.so +vendor/lib64/libqcrilNrFramework.so +vendor/lib64/libqcrilNrLogger.so +vendor/lib64/libqcrilNrQtiBus.so +vendor/lib64/libqcrilNrQtiMutex.so +vendor/lib64/libqcrildatactl.so +vendor/lib64/libqsap_sdk.so +vendor/lib64/libqsocket.so +vendor/lib64/libril-db.so +vendor/lib64/libril-qc-ltedirectdisc.so +vendor/lib64/libril-qc-radioconfig.so +vendor/lib64/libril-qcril-hook-oem.so +vendor/lib64/librilqmimiscservices.so +vendor/lib64/librilqmiservices.so +vendor/lib64/libsystem_health_mon.so +vendor/lib64/qcrilMarshal.so +vendor/lib64/qcrild_libqcrilnrutils.so +vendor/lib64/qtiril-utils.so +vendor/lib64/qtiwakelock.so +vendor/lib64/vendor.qti.hardware.data.connection@1.0.so +vendor/lib64/vendor.qti.hardware.data.connection@1.1.so +vendor/lib64/vendor.qti.hardware.radio.am@1.0.so +vendor/lib64/vendor.qti.hardware.radio.atcmdfwd@1.0.so +vendor/lib64/vendor.qti.hardware.radio.internal.deviceinfo@1.0.so +vendor/lib64/vendor.qti.hardware.radio.lpa@1.0.so +vendor/lib64/vendor.qti.hardware.radio.lpa@1.1.so +vendor/lib64/vendor.qti.hardware.radio.lpa@1.2.so +vendor/lib64/vendor.qti.hardware.radio.qcriNvOpt@1.0.so +vendor/lib64/vendor.qti.hardware.radio.qcrilhook@1.0.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@1.0.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.0.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.1.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.2.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.3.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.4.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.5.so +vendor/lib64/vendor.qti.hardware.radio.qtiradio@2.6.so +vendor/lib64/vendor.qti.hardware.radio.uim@1.0.so +vendor/lib64/vendor.qti.hardware.radio.uim@1.1.so +vendor/lib64/vendor.qti.hardware.radio.uim@1.2.so +vendor/lib64/vendor.qti.hardware.radio.uim_remote_client@1.0.so +vendor/lib64/vendor.qti.hardware.radio.uim_remote_client@1.1.so +vendor/lib64/vendor.qti.hardware.radio.uim_remote_client@1.2.so +vendor/lib64/vendor.qti.hardware.radio.uim_remote_server@1.0.so + # Sensors vendor/bin/hw/vendor.qti.hardware.sensorscalibrate@1.0-service vendor/bin/init.qcom.sensors.sh @@ -711,12 +1381,6 @@ vendor/lib64/hw/vendor.qti.hardware.sensorscalibrate@1.0-impl.so vendor/lib64/libnotifyaudiohal.so vendor/lib64/libsensorcal.so vendor/lib64/libsensorslog.so -vendor/lib64/libsns_device_mode_stub.so -vendor/lib64/libsns_fastRPC_util.so -vendor/lib64/libsns_low_lat_stream_stub.so -vendor/lib64/libsns_registry_skel.so -vendor/lib64/libsnsapi.so -vendor/lib64/libsnsdiaglog.so vendor/lib64/libssc.so vendor/lib64/libssc_default_listener.so vendor/lib64/sensors.elliptic.so @@ -777,11 +1441,48 @@ vendor/etc/sensors/hals.conf vendor/etc/sensors/sns_reg_config vendor/etc/elliptic_sensor.xml +# Secure element +vendor/bin/hw/android.hardware.secure_element@1.2-service +vendor/etc/init/android.hardware.secure_element@1.2-service.rc + +# Snapdragon Computer Vision Engine +vendor/lib/libscveCommon.so +vendor/lib/libscveCommon_stub.so +vendor/lib/libscveObjectSegmentation.so +vendor/lib/libscveObjectSegmentation_stub.so +vendor/lib/libscveObjectTracker.so +vendor/lib/libscveObjectTracker_stub.so +vendor/lib64/libscveCommon.so +vendor/lib64/libscveCommon_stub.so +vendor/lib64/libscveObjectSegmentation.so +vendor/lib64/libscveObjectSegmentation_stub.so +vendor/lib64/libscveObjectTracker.so +vendor/lib64/libscveObjectTracker_stub.so + +# Soter +vendor/bin/hw/vendor.qti.hardware.soter@1.0-service +vendor/etc/init/vendor.qti.hardware.soter@1.0-service.rc +vendor/lib64/hw/vendor.qti.hardware.soter@1.0-impl.so +vendor/lib64/vendor.qti.hardware.soter@1.0.so + +# Soter service (Tencent) +-system/app/SoterService/SoterService.apk + +# Time services +-vendor/app/TimeService/TimeService.apk +vendor/bin/time_daemon +vendor/etc/init/init.time_daemon.rc +vendor/lib64/libtime_genoff.so + # Touchscreen firmware vendor/firmware/goodix_cfg_group.bin vendor/firmware/goodix_firmware.bin -# Thermal config +# Thermal +vendor/bin/mi_thermald +vendor/lib64/libthermalclient.so + +# Thermal Config vendor/etc/thermal-camera.conf vendor/etc/thermal-class0.conf vendor/etc/thermal-engine.conf @@ -794,6 +1495,15 @@ vendor/etc/thermal-tgame.conf vendor/etc/thermal-video.conf vendor/etc/thermald-devices.conf +# Trusted Execution Environment connector +vendor/bin/hw/vendor.qti.hardware.qteeconnector@1.0-service +vendor/etc/init/vendor.qti.hardware.qteeconnector@1.0-service.rc +vendor/lib64/hw/vendor.qti.hardware.qteeconnector@1.0-impl.so +vendor/lib64/libGPQTEEC_vendor.so +vendor/lib64/libGPTEE_vendor.so +vendor/lib64/libQTEEConnector_vendor.so +vendor/lib64/vendor.qti.hardware.qteeconnector@1.0.so + # Vibrator firmware vendor/firmware/aw86214_haptic.bin vendor/firmware/aw8622x_haptic.bin @@ -806,3 +1516,18 @@ vendor/firmware/aw8624_rtp.bin vendor/firmware/aw8624_rtp_lighthouse.bin vendor/firmware/aw8624_rtp_silk.bin vendor/firmware/aw882xx_pid_2113_acf.bin + +# VPP +vendor/lib/vendor.qti.hardware.vpp@1.1.so +vendor/lib/vendor.qti.hardware.vpp@1.2.so +vendor/lib/vendor.qti.hardware.vpp@1.3.so +vendor/lib/vendor.qti.hardware.vpp@2.0.so +vendor/lib64/vendor.qti.hardware.vpp@1.1.so +vendor/lib64/vendor.qti.hardware.vpp@1.2.so +vendor/lib64/vendor.qti.hardware.vpp@1.3.so +vendor/lib64/vendor.qti.hardware.vpp@2.0.so + +# WiFi +vendor/bin/cnss-daemon +vendor/etc/wifi/aoa_cldb_falcon.bin +vendor/etc/wifi/aoa_cldb_swl14.bin diff --git a/releasetools.py b/releasetools.py new file mode 100644 index 0000000..56cbe0d --- /dev/null +++ b/releasetools.py @@ -0,0 +1,32 @@ +# +# Copyright (C) 2022 The LineageOS Project +# +# SPDX-License-Identifier: Apache-2.0 +# + +import common +import re + +def FullOTA_InstallEnd(info): + OTA_InstallEnd(info) + return + +def IncrementalOTA_InstallEnd(info): + OTA_InstallEnd(info) + return + +def AddImage(info, basename, dest): + path = "IMAGES/" + basename + if path not in info.input_zip.namelist(): + return + + data = info.input_zip.read(path) + common.ZipWriteStr(info.output_zip, basename, data) + info.script.AppendExtra('package_extract_file("%s", "%s");' % (basename, dest)) + +def OTA_InstallEnd(info): + info.script.Print("Patching firmware images...") + AddImage(info, "dtbo.img", "/dev/block/bootdevice/by-name/dtbo") + AddImage(info, "vbmeta.img", "/dev/block/bootdevice/by-name/vbmeta") + AddImage(info, "vbmeta_system.img", "/dev/block/bootdevice/by-name/vbmeta_system") + return diff --git a/reorder-libs.py b/reorder-libs.py index 82388d1..4153f04 100755 --- a/reorder-libs.py +++ b/reorder-libs.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright (C) 2021 The LineageOS Project +# Copyright (C) 2022 The LineageOS Project # # SPDX-License-Identifier: Apache-2.0 # diff --git a/rootdir/Android.mk b/rootdir/Android.mk new file mode 100644 index 0000000..7552c69 --- /dev/null +++ b/rootdir/Android.mk @@ -0,0 +1,124 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.class_main.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.class_main.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.mi.btmac.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.mi.btmac.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + + +include $(CLEAR_VARS) +LOCAL_MODULE := init.kernel.post_boot.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.kernel.post_boot.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.kernel.post_boot-blair.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.kernel.post_boot-blair.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.kernel.post_boot-holi.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.kernel.post_boot-holi.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.qcom.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.post_boot.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/init.qcom.post_boot.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := vendor_modprobe.sh +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := bin/vendor_modprobe.sh +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES) +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.batterysecret.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.batterysecret.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.nfc.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.nfc.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qcom.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.qcom.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qti.kernel.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.qti.kernel.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.qti.ufs.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.qti.ufs.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := init.target.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/init.target.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/init/hw +include $(BUILD_PREBUILT) + +include $(CLEAR_VARS) +LOCAL_MODULE := ueventd.qcom.rc +LOCAL_MODULE_STEM := ueventd.rc +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := ETC +LOCAL_SRC_FILES := etc/ueventd.qcom.rc +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR) +include $(BUILD_PREBUILT) diff --git a/rootdir/bin/init.class_main.sh b/rootdir/bin/init.class_main.sh new file mode 100755 index 0000000..05c3251 --- /dev/null +++ b/rootdir/bin/init.class_main.sh @@ -0,0 +1,155 @@ +#! /vendor/bin/sh + +# Copyright (c) 2013-2014, 2019 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# +# start ril-daemon only for targets on which radio is present +# +baseband=`getprop ro.baseband` +sgltecsfb=`getprop persist.vendor.radio.sglte_csfb` +datamode=`getprop persist.vendor.data.mode` +low_ram=`getprop ro.config.low_ram` +qcrild_status=true + +case "$baseband" in + "apq" | "sda" | "qcs" ) + setprop ro.vendor.radio.noril yes + stop vendor.ril-daemon + stop vendor.qcrild +esac + +case "$baseband" in + "msm" | "csfb" | "svlte2a" | "mdm" | "mdm2" | "sglte" | "sglte2" | "dsda2" | "unknown" | "dsda3" | "sdm" | "sdx" | "sm6") + + # For older modem packages launch ril-daemon. + if [ -f /vendor/firmware_mnt/verinfo/ver_info.txt ]; then + modem=`cat /vendor/firmware_mnt/verinfo/ver_info.txt | + sed -n 's/^[^:]*modem[^:]*:[[:blank:]]*//p' | + sed 's/.*MPSS.\(.*\)/\1/g' | cut -d \. -f 1` + if [ "$modem" = "AT" ]; then + version=`cat /vendor/firmware_mnt/verinfo/ver_info.txt | + sed -n 's/^[^:]*modem[^:]*:[[:blank:]]*//p' | + sed 's/.*AT.\(.*\)/\1/g' | cut -d \- -f 1` + if [ ! -z $version ]; then + if [ "$version" \< "3.1" ]; then + qcrild_status=false + fi + fi + elif [ "$modem" = "TA" ]; then + version=`cat /vendor/firmware_mnt/verinfo/ver_info.txt | + sed -n 's/^[^:]*modem[^:]*:[[:blank:]]*//p' | + sed 's/.*TA.\(.*\)/\1/g' | cut -d \- -f 1` + if [ ! -z $version ]; then + if [ "$version" \< "3.0" ]; then + qcrild_status=false + fi + fi + elif [ "$modem" = "JO" ]; then + version=`cat /vendor/firmware_mnt/verinfo/ver_info.txt | + sed -n 's/^[^:]*modem[^:]*:[[:blank:]]*//p' | + sed 's/.*JO.\(.*\)/\1/g' | cut -d \- -f 1` + if [ ! -z $version ]; then + if [ "$version" \< "3.2" ]; then + qcrild_status=false + fi + fi + elif [ "$modem" = "TH" ]; then + qcrild_status=false + fi + fi + + if [ "$qcrild_status" = "true" ]; then + # Make sure both rild, qcrild are not running at same time. + # This is possible with vanilla aosp system image. + stop vendor.ril-daemon + + start vendor.qcrild + else + start vendor.ril-daemon + fi + + case "$baseband" in + "svlte2a" | "csfb") + start qmiproxy + ;; + "sglte" | "sglte2" ) + if [ "x$sgltecsfb" != "xtrue" ]; then + start qmiproxy + else + setprop persist.vendor.radio.voice.modem.index 0 + fi + ;; + esac + + multisim=`getprop persist.radio.multisim.config` + + if [ "$multisim" = "dsds" ] || [ "$multisim" = "dsda" ]; then + if [ "$qcrild_status" = "true" ]; then + start vendor.qcrild2 + else + start vendor.ril-daemon2 + fi + elif [ "$multisim" = "tsts" ]; then + if [ "$qcrild_status" = "true" ]; then + start vendor.qcrild2 + start vendor.qcrild3 + else + start vendor.ril-daemon2 + start vendor.ril-daemon3 + fi + fi + + case "$datamode" in + "tethered") + start vendor.dataqti + if [ "$low_ram" != "true" ]; then + start vendor.dataadpl + fi + ;; + "concurrent") + start vendor.dataqti + if [ "$low_ram" != "true" ]; then + start vendor.dataadpl + fi + ;; + *) + ;; + esac +esac + +# +# Allow persistent faking of bms +# User needs to set fake bms charge in persist.vendor.bms.fake_batt_capacity +# +fake_batt_capacity=`getprop persist.vendor.bms.fake_batt_capacity` +case "$fake_batt_capacity" in + "") ;; #Do nothing here + * ) + echo "$fake_batt_capacity" > /sys/class/power_supply/battery/capacity + ;; +esac diff --git a/rootdir/bin/init.kernel.post_boot-blair.sh b/rootdir/bin/init.kernel.post_boot-blair.sh new file mode 100755 index 0000000..0c52026 --- /dev/null +++ b/rootdir/bin/init.kernel.post_boot-blair.sh @@ -0,0 +1,249 @@ +#============================================================================= +# Copyright (c) 2021 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +# +# Copyright (c) 2012-2013, 2016-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +function configure_zram_parameters() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + # Zram disk - 75% for < 2GB devices . + # For >2GB devices, size = 50% of RAM size. Limit the size to 4GB. + + let RamSizeGB="( $MemTotal / 1048576 ) + 1" + diskSizeUnit=M + if [ $RamSizeGB -le 2 ]; then + let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4" + else + let zRamSizeMB="( $RamSizeGB * 1024 ) / 2" + fi + + # use MB avoid 32 bit overflow + if [ $zRamSizeMB -gt 4096 ]; then + let zRamSizeMB=4096 + fi + + if [ -f /sys/block/zram0/disksize ]; then + if [ -f /sys/block/zram0/use_dedup ]; then + echo 1 > /sys/block/zram0/use_dedup + fi + echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize + + # ZRAM may use more memory than it saves if SLAB_STORE_USER + # debug option is enabled. + if [ -e /sys/kernel/slab/zs_handle ]; then + echo 0 > /sys/kernel/slab/zs_handle/store_user + fi + if [ -e /sys/kernel/slab/zspage ]; then + echo 0 > /sys/kernel/slab/zspage/store_user + fi + + mkswap /dev/block/zram0 + swapon /dev/block/zram0 -p 32758 + fi +} + +function configure_read_ahead_kb_values() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc) + + # Set 128 for <= 3GB & + # set 512 for >= 4GB targets. + if [ $MemTotal -le 3145728 ]; then + ra_kb=128 + else + ra_kb=512 + fi + if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then + echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb + fi + if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then + echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb + fi + for dm in $dmpts; do + echo $ra_kb > $dm + done +} + +function configure_memory_parameters() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + # Set Memory parameters. + + # Set swappiness to 100 for all targets + echo 100 > /proc/sys/vm/swappiness + + # Disable wsf for all targets beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + # Disable the feature of watermark boost for 8G and below device + if [ $MemTotal -le 8388608 ]; then + echo 0 > /proc/sys/vm/watermark_boost_factor + fi + configure_zram_parameters + configure_read_ahead_kb_values + + #Spawn 2 kswapd threads which can help in fast reclaiming of pages + echo 2 > /proc/sys/vm/kswapd_threads +} + +# Core control parameters for silver +echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred +echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus +echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres +echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres +echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms +echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + +# Enable Core control for Silver +echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/enable + +# Disable Core control on gold +echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + +# Setting b.L scheduler parameters +echo 65 > /proc/sys/kernel/sched_downmigrate +echo 71 > /proc/sys/kernel/sched_upmigrate +echo 85 > /proc/sys/kernel/sched_group_downmigrate +echo 100 > /proc/sys/kernel/sched_group_upmigrate +echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks +echo 0 > /proc/sys/kernel/sched_coloc_busy_hysteresis_enable_cpus +echo 0 > /proc/sys/kernel/sched_busy_hysteresis_enable_cpus +echo 5 > /proc/sys/kernel/sched_ravg_window_nr_ticks + +# disable unfiltering +echo 20000000 > /proc/sys/kernel/sched_task_unfilter_period + +# cpuset parameters +echo 0-2 > /dev/cpuset/background/cpus +echo 0-3 > /dev/cpuset/system-background/cpus +echo 4-7 > /dev/cpuset/foreground/boost/cpus +echo 0-2,4-7 > /dev/cpuset/foreground/cpus +echo 0-7 > /dev/cpuset/top-app/cpus + +# Turn off scheduler boost at the end +echo 0 > /proc/sys/kernel/sched_boost + +# configure governor settings for silver cluster +echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor +echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us +echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us +echo 1113600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq +echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + +# configure governor settings for gold cluster +echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/down_rate_limit_us +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/up_rate_limit_us +echo 1228800 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_freq +echo 691200 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq + +# Colocation V3 settings +echo 680000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/rtg_boost_freq +echo 51 > /proc/sys/kernel/sched_min_task_util_for_boost +echo 35 > /proc/sys/kernel/sched_min_task_util_for_colocation + +# sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. +echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost +echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost +echo 85 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_load + +# configure input boost settings +echo "0:1804800" > /sys/devices/system/cpu/cpu_boost/input_boost_freq +echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + +# Enable bus-dcvs +for device in /sys/devices/platform/soc +do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + cat $cpubw/available_frequencies | cut -d " " -f 1 > $cpubw/min_freq + echo "bw_hwmon" > $cpubw/governor + echo "762 1144 1720 2086 2597 2929 3879 5161 5931 6881 7980" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 40 > $cpubw/polling_interval + done + + # configure compute settings for silver latfloor + for latfloor in $device/*cpu0-cpu*latfloor/devfreq/*cpu0-cpu*latfloor + do + cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq + echo 8 > $latfloor/polling_interval + done + + # configure compute settings for gold latfloor + for latfloor in $device/*cpu6-cpu*latfloor/devfreq/*cpu6-cpu*latfloor + do + cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq + echo 8 > $latfloor/polling_interval + done + + # configure mem_latency settings for DDR scaling + for memlat in $device/*lat/devfreq/*lat + do + cat $memlat/available_frequencies | cut -d " " -f 1 > $memlat/min_freq + echo 8 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Gold CPU6 L3 ratio ceil + for l3gold in $device/*cpu6-cpu-l3-lat/devfreq/*cpu6-cpu-l3-lat + do + echo 4000 > $l3gold/mem_latency/ratio_ceil + echo 25000 > $l3gold/mem_latency/wb_filter_ratio + echo 60 > $l3gold/mem_latency/wb_pct_thres + done + + #Gold CPU7 L3 ratio ceil + for l3gold in $device/*cpu7-cpu-l3-lat/devfreq/*cpu7-cpu-l3-lat + do + echo 4000 > $l3gold/mem_latency/ratio_ceil + echo 25000 > $l3gold/mem_latency/wb_filter_ratio + echo 60 > $l3gold/mem_latency/wb_pct_thres + done + +done + +echo N > /sys/module/lpm_levels/parameters/sleep_disabled + +configure_memory_parameters + +setprop vendor.post_boot.parsed 1 diff --git a/rootdir/bin/init.kernel.post_boot-holi.sh b/rootdir/bin/init.kernel.post_boot-holi.sh new file mode 100755 index 0000000..7ee3ae8 --- /dev/null +++ b/rootdir/bin/init.kernel.post_boot-holi.sh @@ -0,0 +1,246 @@ +#============================================================================= +# Copyright (c) 2020-2021 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +# +# Copyright (c) 2012-2013, 2016-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +function configure_zram_parameters() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + # Zram disk - 75% for < 2GB devices . + # For >2GB devices, size = 50% of RAM size. Limit the size to 4GB. + + let RamSizeGB="( $MemTotal / 1048576 ) + 1" + diskSizeUnit=M + if [ $RamSizeGB -le 2 ]; then + let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4" + else + let zRamSizeMB="( $RamSizeGB * 1024 ) / 2" + fi + + # use MB avoid 32 bit overflow + if [ $zRamSizeMB -gt 4096 ]; then + let zRamSizeMB=4096 + fi + + if [ -f /sys/block/zram0/disksize ]; then + if [ -f /sys/block/zram0/use_dedup ]; then + echo 1 > /sys/block/zram0/use_dedup + fi + echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize + + # ZRAM may use more memory than it saves if SLAB_STORE_USER + # debug option is enabled. + if [ -e /sys/kernel/slab/zs_handle ]; then + echo 0 > /sys/kernel/slab/zs_handle/store_user + fi + if [ -e /sys/kernel/slab/zspage ]; then + echo 0 > /sys/kernel/slab/zspage/store_user + fi + + mkswap /dev/block/zram0 + swapon /dev/block/zram0 -p 32758 + fi +} + +function configure_read_ahead_kb_values() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc) + + # Set 128 for <= 3GB & + # set 512 for >= 4GB targets. + if [ $MemTotal -le 3145728 ]; then + ra_kb=128 + else + ra_kb=512 + fi + if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then + echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb + fi + if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then + echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb + fi + for dm in $dmpts; do + echo $ra_kb > $dm + done +} + +function configure_memory_parameters() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + # Set Memory parameters. + + # Set swappiness to 100 for all targets + echo 100 > /proc/sys/vm/swappiness + + # Disable wsf for all targets beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + # Disable the feature of watermark boost for 8G and below device + if [ $MemTotal -le 8388608 ]; then + echo 0 > /proc/sys/vm/watermark_boost_factor + fi + configure_zram_parameters + configure_read_ahead_kb_values + + #Spawn 2 kswapd threads which can help in fast reclaiming of pages + echo 2 > /proc/sys/vm/kswapd_threads +} + +# Core control parameters for silver +echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred +echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus +echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres +echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres +echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms +echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + +# Enable Core control for Silver +echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/enable + +# Disable Core control on gold +echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + +# Setting b.L scheduler parameters +echo 65 > /proc/sys/kernel/sched_downmigrate +echo 71 > /proc/sys/kernel/sched_upmigrate +echo 85 > /proc/sys/kernel/sched_group_downmigrate +echo 100 > /proc/sys/kernel/sched_group_upmigrate +echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks +echo 0 > /proc/sys/kernel/sched_coloc_busy_hysteresis_enable_cpus +echo 0 > /proc/sys/kernel/sched_busy_hysteresis_enable_cpus +echo 5 > /proc/sys/kernel/sched_ravg_window_nr_ticks + +# disable unfiltering +echo 20000000 > /proc/sys/kernel/sched_task_unfilter_period + +# cpuset parameters +echo 0-5 > /dev/cpuset/background/cpus +echo 0-5 > /dev/cpuset/system-background/cpus + +# Turn off scheduler boost at the end +echo 0 > /proc/sys/kernel/sched_boost + +# configure governor settings for silver cluster +echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor +echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us +echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us +echo 1190400 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq +echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + +# configure governor settings for gold cluster +echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/down_rate_limit_us +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/up_rate_limit_us +echo 1248000 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_freq +echo 768000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq + +# Colocation V3 settings +echo 680000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq +echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/rtg_boost_freq +echo 51 > /proc/sys/kernel/sched_min_task_util_for_boost +echo 35 > /proc/sys/kernel/sched_min_task_util_for_colocation + +# sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. +echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost +echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost +echo 85 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_load + +# configure input boost settings +echo "0:1190400" > /sys/devices/system/cpu/cpu_boost/input_boost_freq +echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + +# Enable bus-dcvs +for device in /sys/devices/platform/soc +do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + cat $cpubw/available_frequencies | cut -d " " -f 1 > $cpubw/min_freq + echo "bw_hwmon" > $cpubw/governor + echo "1144 1720 2086 2929 3879 5931 6881 8137" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 40 > $cpubw/polling_interval + done + + # configure compute settings for silver latfloor + for latfloor in $device/*cpu0-cpu*latfloor/devfreq/*cpu0-cpu*latfloor + do + cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq + echo 8 > $latfloor/polling_interval + done + + # configure compute settings for gold latfloor + for latfloor in $device/*cpu6-cpu*latfloor/devfreq/*cpu6-cpu*latfloor + do + cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq + echo 8 > $latfloor/polling_interval + done + + # configure mem_latency settings for DDR scaling + for memlat in $device/*lat/devfreq/*lat + do + cat $memlat/available_frequencies | cut -d " " -f 1 > $memlat/min_freq + echo 8 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Gold CPU6 L3 ratio ceil + for l3gold in $device/*cpu6-cpu-l3-lat/devfreq/*cpu6-cpu-l3-lat + do + echo 4000 > $l3gold/mem_latency/ratio_ceil + echo 25000 > $l3gold/mem_latency/wb_filter_ratio + echo 60 > $l3gold/mem_latency/wb_pct_thres + done + + #Gold CPU7 L3 ratio ceil + for l3gold in $device/*cpu7-cpu-l3-lat/devfreq/*cpu7-cpu-l3-lat + do + echo 4000 > $l3gold/mem_latency/ratio_ceil + echo 25000 > $l3gold/mem_latency/wb_filter_ratio + echo 60 > $l3gold/mem_latency/wb_pct_thres + done + +done + +echo N > /sys/module/lpm_levels/parameters/sleep_disabled + +configure_memory_parameters + +setprop vendor.post_boot.parsed 1 diff --git a/rootdir/bin/init.kernel.post_boot.sh b/rootdir/bin/init.kernel.post_boot.sh new file mode 100755 index 0000000..32468d9 --- /dev/null +++ b/rootdir/bin/init.kernel.post_boot.sh @@ -0,0 +1,49 @@ +#============================================================================= +# Copyright (c) 2020-2021 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +# +# Copyright (c) 2012-2013, 2016-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +if [ -f /sys/devices/soc0/chip_family ]; then + chipfamily=`cat /sys/devices/soc0/chip_family` +fi + +case "$chipfamily" in + "0x73") + /vendor/bin/sh /vendor/bin/init.kernel.post_boot-holi.sh + ;; + + "0x7c") + /vendor/bin/sh /vendor/bin/init.kernel.post_boot-blair.sh + ;; + *) + echo "***WARNING***: Invalid chip family\n\t No postboot settings applied!!\n" + ;; +esac diff --git a/rootdir/bin/init.mi.btmac.sh b/rootdir/bin/init.mi.btmac.sh new file mode 100755 index 0000000..66ec4b2 --- /dev/null +++ b/rootdir/bin/init.mi.btmac.sh @@ -0,0 +1,21 @@ +#!/vendor/bin/sh +# Copyright (C) 2021 KudProject Development +# SPDX-License-Identifier: GPL-3.0-or-later OR Apache-2.0 + +LOG_TAG="MiSetBtMac" +logi () { log -t "$LOG_TAG" -p i "$@"; } + +# hex binary containing mac address +BT_MAC_HEX_PATH="/data/vendor/mac_addr/bt.mac"; +if [ ! -f "$BT_MAC_HEX_PATH" ]; then + logi "bt.mac file not found, exiting" + exit +fi + +# raw mac address without colons +RAW_MAC=$(xxd -p "$BT_MAC_HEX_PATH"); +# convert it into format recognized by bluetooth hal +DEC_MAC=$(echo "$RAW_MAC" | sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!') +# set the mac address using persist property +setprop persist.vendor.service.bdroid.bdaddr "$DEC_MAC" +logi "bt.mac file found, setting mac addr" diff --git a/rootdir/bin/init.qcom.post_boot.sh b/rootdir/bin/init.qcom.post_boot.sh new file mode 100755 index 0000000..3a1eb13 --- /dev/null +++ b/rootdir/bin/init.qcom.post_boot.sh @@ -0,0 +1,6235 @@ +#! /vendor/bin/sh + +# Copyright (c) 2012-2013, 2016-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +function 8953_sched_dcvs_eas() +{ + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + #governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1401600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8953 and sdm450 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + + echo 652800 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + + #input boost params + echo 1401600 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 34 > $cpubw/bw_hwmon/io_percent + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 34 > $cpubw/bw_hwmon/low_power_io_percent + echo "1611 3221 5859 6445 7104" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1611 > $cpubw/min_freq + done + done + else + #governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1401600 > /sys/devices/system/cpu/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8953 and sdm450 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/schedutil/hispeed_load + + echo 652800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + fi +} + +function 8917_sched_dcvs_eas() +{ + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + #governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1094400 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8917 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + + echo 960000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + + #input boost params + echo 1094400 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 20 > $cpubw/bw_hwmon/io_percent + echo 30 > $cpubw/bw_hwmon/guard_band_mbps + done + done + else + #governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1094400 > /sys/devices/system/cpu/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8917 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/schedutil/hispeed_load + + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + fi + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + fi +} + +function 8937_sched_dcvs_eas() +{ + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1094400 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8937 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + + echo 960000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + + ## enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + #set the hispeed_freq + echo 768000 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8937 it should be 85 + echo 85 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/rtg_boost_freq + + echo 768000 > /sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq + + #input boost params + echo 109440 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 20 > $cpubw/bw_hwmon/io_percent + echo 30 > $cpubw/bw_hwmon/guard_band_mbps + done + done + else + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 1094400 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8937 it should be 85 + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + ## enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + #set the hispeed_freq + echo 768000 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for 8937 it should be 85 + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 768000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + fi + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + fi +} + +function configure_automotive_sku_parameters() { + + echo 1036800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1056000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 1171200 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq + echo 1785600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + echo 902400000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 902400000 > /sys/class/devfreq/18321110.qcom,cpu4-cpu-l3-lat/min_freq + echo 902400000 > /sys/class/devfreq/18321110.qcom,cpu7-cpu-l3-lat/min_freq + echo 1612800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 1612800000 > /sys/class/devfreq/18321110.qcom,cpu4-cpu-l3-lat/max_freq + echo 1612800000 > /sys/class/devfreq/18321110.qcom,cpu7-cpu-l3-lat/max_freq + echo 902400000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 902400000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/min_freq + echo 902400000 > /sys/class/devfreq/soc\:qcom,cpu7-cpu-l3-lat/min_freq + echo 1612800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 1612800000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/max_freq + echo 1612800000 > /sys/class/devfreq/soc\:qcom,cpu7-cpu-l3-lat/max_freq + +#read feature id from nvram +reg_val=`cat /sys/devices/platform/soc/780130.qfprom/qfprom0/nvmem | od -An -t d4` +feature_id=$(((reg_val >> 20) & 0xFF)) +log -t BOOT -p i "feature id '$feature_id'" +if [ $feature_id == 0 ]; then + echo " SKU Configured : SA8155P" + echo 2131200 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 2419200 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel +elif [ $feature_id == 1 ]; then + echo "SKU Configured : SA8150P" + echo 1920000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 2227200 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 3 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel +else + echo "unknown feature_id value" $feature_id +fi +} + +function configure_automotive_sku_parameters_sa8195() { + + #Setting the min supported frequencies + echo 1113600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1171200 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu4-cpu-l3-lat/min_freq + echo 1651200000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 1651200000 > /sys/class/devfreq/18321110.qcom,cpu4-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/min_freq + echo 1651200000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 1651200000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/max_freq + + #read feature id + reg_val=`cat /sys/devices/platform/soc/780130.qfprom/qfprom0/nvmem | od -An -t d4` + feature_id=$(((reg_val >> 20) & 0xFF)) + + #setting min gpu freq to 392 MHz + echo 4 > /sys/class/kgsl/kgsl-3d0/min_pwrlevel + if [ $feature_id == 0 ]; then + echo "feature_id is 0 for SA8195AA" + + #setting max cpu freq to 2.496GHz + echo 2496000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + #setting max gpu freq to 530 MHz + echo 3 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1804 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + elif [ $feature_id == 1 ] || [ $feature_id == 2 ]; then + echo "feature_id is 1 for external SA8195AB" + echo "feature_id is 2 for internal SA8195AB" + + #setting max cpu freq to 2.496GHz + echo 2496000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + #setting max gpu freq to 670 MHz + echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 2092 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + elif [ $feature_id == 3 ]; then + echo "feature_id is 3 for external SA8195AC" + else + echo "unknown feature_id value" $feature_id + fi +} + +function configure_sku_parameters() { + +#read feature id from nvram +reg_val=`cat /sys/devices/platform/soc/780130.qfprom/qfprom0/nvmem | od -An -t d4` +feature_id=$(((reg_val >> 20) & 0xFF)) +log -t BOOT -p i "feature id '$feature_id'" +if [ $feature_id == 6 ]; then + echo " SKU Configured : SA6145" + echo 748800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + echo 748800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + echo 748800 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + echo 748800 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + echo 748800 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 748800 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq + echo 1017600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq + echo 1017600 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 1017600000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/min_freq + echo 1017600000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 1017600000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/min_freq + echo 1017600000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/max_freq + echo 3 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1016 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + setprop vendor.sku_identified 1 + setprop vendor.sku_name "SA6145" +elif [ $feature_id == 5 ]; then + echo "SKU Configured : SA6150" + echo 748800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq + echo 998400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + echo 998400 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + echo 998400 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + echo 998400 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + echo 998400 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 998400 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq + echo 1708800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq + echo 1708800 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/max_freq + echo 2 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1333 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + setprop vendor.sku_identified 1 + setprop vendor.sku_name "SA6150" +elif [ $feature_id == 4 ] || [ $feature_id == 3 ]; then + echo "SKU Configured : SA6155" + echo 748800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq + echo 1593600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq + echo 1900800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq + echo 1900800 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/max_freq + echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1555 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + setprop vendor.sku_identified 1 + setprop vendor.sku_name "SA6155" +else + echo "SKU Configured : SA6155" + echo 748800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 748800 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + echo 1017600 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq + echo 1593600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + echo 1593600 > /sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq + echo 1900800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq + echo 1900800 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/18321110.qcom,cpu6-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/min_freq + echo 1363200000 > /sys/class/devfreq/soc\:qcom,cpu6-cpu-l3-lat/max_freq + echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1555 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + setprop vendor.sku_identified 1 + setprop vendor.sku_name "SA6155" +fi +} + +function 8953_sched_dcvs_hmp() +{ + #scheduler settings + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + #task packing settings + echo 0 > /sys/devices/system/cpu/cpu0/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu1/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu2/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu3/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu4/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu5/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu6/sched_static_cpu_pwr_cost + echo 0 > /sys/devices/system/cpu/cpu7/sched_static_cpu_pwr_cost + # spill load is set to 100% by default in the kernel + echo 3 > /proc/sys/kernel/sched_spill_nr_run + # Apply inter-cluster load balancer restrictions + echo 1 > /proc/sys/kernel/sched_restrict_cluster_spill + # set sync wakee policy tunable + echo 1 > /proc/sys/kernel/sched_prefer_sync_wakee_to_waker + + #governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "19000 1401600:39000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpufreq/interactive/timer_rate + echo 1401600 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "85 1401600:80" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 39000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + echo 19 > /proc/sys/kernel/sched_upmigrate_min_nice + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpufreq/interactive/use_migration_notif + echo 200000 > /proc/sys/kernel/sched_freq_inc_notify + echo 200000 > /proc/sys/kernel/sched_freq_dec_notify + +} + +function 8917_sched_dcvs_hmp() +{ + # HMP scheduler settings + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + echo 1 > /proc/sys/kernel/sched_restrict_tasks_spread + # HMP Task packing settings + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + + echo 0 > /sys/devices/system/cpu/cpu0/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu1/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu2/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu3/sched_prefer_idle + + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "19000 1094400:39000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpufreq/interactive/timer_rate + echo 1094400 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "1 960000:85 1094400:90" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpufreq/interactive/use_migration_notif + echo 50000 > /proc/sys/kernel/sched_freq_inc_notify + echo 50000 > /proc/sys/kernel/sched_freq_dec_notify +} + +function 8937_sched_dcvs_hmp() +{ + # HMP scheduler settings + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + # HMP Task packing settings + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_load + + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_nr_run + + echo 0 > /sys/devices/system/cpu/cpu0/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu1/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu2/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu3/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu4/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu5/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu6/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu7/sched_prefer_idle + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "19000 1094400:39000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1094400 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "1 960000:85 1094400:90 1344000:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/sampling_down_factor + + # enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 39000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 768000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "1 768000:90" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/sampling_down_factor + + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 50000 > /proc/sys/kernel/sched_freq_inc_notify + echo 50000 > /proc/sys/kernel/sched_freq_dec_notify + +} + +function sdm660_sched_interactive_dcvs() { + + echo 0 > /proc/sys/kernel/sched_select_prev_cpu_us + echo 400000 > /proc/sys/kernel/sched_freq_inc_notify + echo 400000 > /proc/sys/kernel/sched_freq_dec_notify + echo 5 > /proc/sys/kernel/sched_spill_nr_run + echo 1 > /proc/sys/kernel/sched_restrict_cluster_spill + echo 100000 > /proc/sys/kernel/sched_short_burst_ns + echo 1 > /proc/sys/kernel/sched_prefer_sync_wakee_to_waker + echo 20 > /proc/sys/kernel/sched_small_wakee_task_load + + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + + # online CPU0 + echo 1 > /sys/devices/system/cpu/cpu0/online + # configure governor settings for little cluster + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo "19000 1401600:39000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1401600 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "85 1747200:95" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 39000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 633600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/ignore_hispeed_on_notif + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/fast_ramp_down + # online CPU4 + echo 1 > /sys/devices/system/cpu/cpu4/online + # configure governor settings for big cluster + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo "19000 1401600:39000" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 1401600 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "85 1401600:90 2150400:95" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 39000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 59000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + echo 1113600 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/ignore_hispeed_on_notif + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/fast_ramp_down + + # bring all cores online + echo 1 > /sys/devices/system/cpu/cpu0/online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # configure LPM + echo N > /sys/module/lpm_levels/system/pwr/cpu0/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu1/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu2/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu3/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu4/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu5/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu6/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu7/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-dynret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-dynret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-ret/idle_enabled + + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + echo "1525 3143 5859 7759 9887 10327 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 85 > $cpubw/bw_hwmon/io_percent + echo 100 > $cpubw/bw_hwmon/decay_rate + echo 50 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/low_power_ceil_mbps + echo 34 > $cpubw/bw_hwmon/low_power_io_percent + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor +} + +function sdm660_sched_schedutil_dcvs() { + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 633600 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 902400 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + echo 1113600 > /sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/rtg_boost_freq + else + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + fi + + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + #if the kernel version >=4.19,set input_boost_freq accordingly + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + echo "0:1401600" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 40 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + else + echo "0:1401600" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + fi + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + echo "1525 3143 5859 7759 9887 10327 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 85 > $cpubw/bw_hwmon/io_percent + echo 100 > $cpubw/bw_hwmon/decay_rate + echo 50 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -le 14 ]; then + for memlat in $device/*cpu*-lat/devfreq/*cpu*-lat + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + for latfloor in $device/*cpu*-ddr-latfloor*/devfreq/*cpu-ddr-latfloor* + do + echo "compute" > $latfloor/governor + echo 10 > $latfloor/polling_interval + done + fi + done + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + fi + +} + +target=`getprop ro.board.platform` + +KernelVersionStr=`cat /proc/sys/kernel/osrelease` +KernelVersionS=${KernelVersionStr:2:2} +KernelVersionA=${KernelVersionStr:0:1} +KernelVersionB=${KernelVersionS%.*} + +function configure_zram_parameters() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + low_ram=`getprop ro.config.low_ram` + + # Zram disk - 75% for Go devices. + # For 512MB Go device, size = 384MB, set same for Non-Go. + # For 1GB Go device, size = 768MB, set same for Non-Go. + # For 2GB Go device, size = 1536MB, set same for Non-Go. + # For >2GB Non-Go devices, size = 50% of RAM size. Limit the size to 4GB. + # And enable lz4 zram compression for Go targets. + + let RamSizeGB="( $MemTotal / 1048576 ) + 1" + diskSizeUnit=M + if [ $RamSizeGB -le 2 ]; then + let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4" + else + let zRamSizeMB="( $RamSizeGB * 1024 ) / 2" + fi + + # use MB avoid 32 bit overflow + if [ $zRamSizeMB -gt 4096 ]; then + let zRamSizeMB=4096 + fi + + if [ "$low_ram" == "true" ]; then + echo lz4 > /sys/block/zram0/comp_algorithm + fi + + if [ -f /sys/block/zram0/disksize ]; then + if [ -f /sys/block/zram0/use_dedup ]; then + echo 1 > /sys/block/zram0/use_dedup + fi + echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize + + # ZRAM may use more memory than it saves if SLAB_STORE_USER + # debug option is enabled. + if [ -e /sys/kernel/slab/zs_handle ]; then + echo 0 > /sys/kernel/slab/zs_handle/store_user + fi + if [ -e /sys/kernel/slab/zspage ]; then + echo 0 > /sys/kernel/slab/zspage/store_user + fi + + mkswap /dev/block/zram0 + swapon /dev/block/zram0 -p 32758 + fi +} + +function configure_read_ahead_kb_values() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc) + + # Set 128 for <= 3GB & + # set 512 for >= 4GB targets. + if [ $MemTotal -le 3145728 ]; then + echo 128 > /sys/block/mmcblk0/bdi/read_ahead_kb + echo 128 > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb + for dm in $dmpts; do + echo 128 > $dm + done + else + echo 512 > /sys/block/mmcblk0/bdi/read_ahead_kb + echo 512 > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb + for dm in $dmpts; do + echo 512 > $dm + done + fi +} + +function disable_core_ctl() { + if [ -f /sys/devices/system/cpu/cpu0/core_ctl/enable ]; then + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + else + echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/disable + fi +} + +function enable_swap() { + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + SWAP_ENABLE_THRESHOLD=1048576 + swap_enable=`getprop ro.vendor.qti.config.swap` + + # Enable swap initially only for 1 GB targets + if [ "$MemTotal" -le "$SWAP_ENABLE_THRESHOLD" ] && [ "$swap_enable" == "true" ]; then + # Static swiftness + echo 1 > /proc/sys/vm/swap_ratio_enable + echo 70 > /proc/sys/vm/swap_ratio + + # Swap disk - 200MB size + if [ ! -f /data/vendor/swap/swapfile ]; then + dd if=/dev/zero of=/data/vendor/swap/swapfile bs=1m count=200 + fi + mkswap /data/vendor/swap/swapfile + swapon /data/vendor/swap/swapfile -p 32758 + fi +} + +function disable_ppr() +{ + if [ -f /sys/module/process_reclaim/parameters/enable_process_reclaim ]; then + echo 0 > /sys/module/process_reclaim/parameters/enable_process_reclaim + fi +} + +function configure_memory_parameters() { + # Set Memory parameters. + # + # Set per_process_reclaim tuning parameters + # All targets will use vmpressure range 50-70, + # All targets will use 512 pages swap size. + # + # Set Low memory killer minfree parameters + # 32 bit Non-Go, all memory configurations will use 15K series + # 32 bit Go, all memory configurations will use uLMK + Memcg + # 64 bit will use Google default LMK series. + # + # Set ALMK parameters (usually above the highest minfree values) + # vmpressure_file_min threshold is always set slightly higher + # than LMK minfree's last bin value for all targets. It is calculated as + # vmpressure_file_min = (last bin - second last bin ) + last bin + # + # Set allocstall_threshold to 0 for all targets. + # + +ProductName=`getprop ro.product.name` +low_ram=`getprop ro.config.low_ram` + +if [ "$ProductName" == "msmnile" ] || [ "$ProductName" == "kona" ] || [ "$ProductName" == "sdmshrike_au" ]; then + # Enable ZRAM + configure_zram_parameters + configure_read_ahead_kb_values + echo 0 > /proc/sys/vm/page-cluster + echo 100 > /proc/sys/vm/swappiness +else + arch_type=`uname -m` + + # Set parameters for 32-bit Go targets. + if [ "$low_ram" == "true" ]; then + # Disable KLMK, ALMK, PPR & Core Control for Go devices + echo 0 > /sys/module/lowmemorykiller/parameters/enable_lmk + echo 0 > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk + echo 0 > /sys/module/process_reclaim/parameters/enable_process_reclaim + disable_core_ctl + # Enable oom_reaper for Go devices + if [ -f /proc/sys/vm/reap_mem_on_sigkill ]; then + echo 1 > /proc/sys/vm/reap_mem_on_sigkill + fi + else + + # Read adj series and set adj threshold for PPR and ALMK. + # This is required since adj values change from framework to framework. + adj_series=`cat /sys/module/lowmemorykiller/parameters/adj` + adj_1="${adj_series#*,}" + set_almk_ppr_adj="${adj_1%%,*}" + + # PPR and ALMK should not act on HOME adj and below. + # Normalized ADJ for HOME is 6. Hence multiply by 6 + # ADJ score represented as INT in LMK params, actual score can be in decimal + # Hence add 6 considering a worst case of 0.9 conversion to INT (0.9*6). + # For uLMK + Memcg, this will be set as 6 since adj is zero. + set_almk_ppr_adj=$(((set_almk_ppr_adj * 6) + 6)) + echo $set_almk_ppr_adj > /sys/module/lowmemorykiller/parameters/adj_max_shift + + # Calculate vmpressure_file_min as below & set for 64 bit: + # vmpressure_file_min = last_lmk_bin + (last_lmk_bin - last_but_one_lmk_bin) + if [ "$arch_type" == "aarch64" ]; then + minfree_series=`cat /sys/module/lowmemorykiller/parameters/minfree` + minfree_1="${minfree_series#*,}" ; rem_minfree_1="${minfree_1%%,*}" + minfree_2="${minfree_1#*,}" ; rem_minfree_2="${minfree_2%%,*}" + minfree_3="${minfree_2#*,}" ; rem_minfree_3="${minfree_3%%,*}" + minfree_4="${minfree_3#*,}" ; rem_minfree_4="${minfree_4%%,*}" + minfree_5="${minfree_4#*,}" + + vmpres_file_min=$((minfree_5 + (minfree_5 - rem_minfree_4))) + echo $vmpres_file_min > /sys/module/lowmemorykiller/parameters/vmpressure_file_min + else + # Set LMK series, vmpressure_file_min for 32 bit non-go targets. + # Disable Core Control, enable KLMK for non-go 8909. + if [ "$ProductName" == "msm8909" ]; then + disable_core_ctl + echo 1 > /sys/module/lowmemorykiller/parameters/enable_lmk + fi + echo "15360,19200,23040,26880,34415,43737" > /sys/module/lowmemorykiller/parameters/minfree + echo 53059 > /sys/module/lowmemorykiller/parameters/vmpressure_file_min + fi + + # Enable adaptive LMK for all targets & + # use Google default LMK series for all 64-bit targets >=2GB. + echo 1 > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk + + # Enable oom_reaper + if [ -f /sys/module/lowmemorykiller/parameters/oom_reaper ]; then + echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper + fi + + if [[ "$ProductName" != "bengal"* ]]; then + #bengal has appcompaction enabled. So not needed + # Set PPR parameters for other targets + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + case "$soc_id" in + # Do not set PPR parameters for premium targets + # sdm845 - 321, 341 + # msm8998 - 292, 319 + # msm8996 - 246, 291, 305, 312 + "321" | "341" | "292" | "319" | "246" | "291" | "305" | "312") + ;; + *) + #Set PPR parameters for all other targets. + echo $set_almk_ppr_adj > /sys/module/process_reclaim/parameters/min_score_adj + echo 1 > /sys/module/process_reclaim/parameters/enable_process_reclaim + echo 50 > /sys/module/process_reclaim/parameters/pressure_min + echo 70 > /sys/module/process_reclaim/parameters/pressure_max + echo 30 > /sys/module/process_reclaim/parameters/swap_opt_eff + echo 512 > /sys/module/process_reclaim/parameters/per_swap_size + ;; + esac + fi + fi + + if [[ "$ProductName" == "bengal"* ]]; then + #Set PPR nomap parameters for bengal targets + echo 1 > /sys/module/process_reclaim/parameters/enable_process_reclaim + echo 50 > /sys/module/process_reclaim/parameters/pressure_min + echo 70 > /sys/module/process_reclaim/parameters/pressure_max + echo 30 > /sys/module/process_reclaim/parameters/swap_opt_eff + echo 0 > /sys/module/process_reclaim/parameters/per_swap_size + echo 7680 > /sys/module/process_reclaim/parameters/tsk_nomap_swap_sz + fi + + # Set allocstall_threshold to 0 for all targets. + # Set swappiness to 100 for all targets + echo 0 > /sys/module/vmpressure/parameters/allocstall_threshold + echo 100 > /proc/sys/vm/swappiness + + # Disable wsf for all targets beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + + configure_zram_parameters + + configure_read_ahead_kb_values + + enable_swap +fi +} + +function enable_memory_features() +{ + MemTotalStr=`cat /proc/meminfo | grep MemTotal` + MemTotal=${MemTotalStr:16:8} + + if [ $MemTotal -le 2097152 ]; then + #Enable B service adj transition for 2GB or less memory + setprop ro.vendor.qti.sys.fw.bservice_enable true + setprop ro.vendor.qti.sys.fw.bservice_limit 5 + setprop ro.vendor.qti.sys.fw.bservice_age 5000 + + #Enable Delay Service Restart + setprop ro.vendor.qti.am.reschedule_service true + fi +} + +function start_hbtp() +{ + # Start the Host based Touch processing but not in the power off mode. + bootmode=`getprop ro.bootmode` + if [ "charger" != $bootmode ]; then + start vendor.hbtp + fi +} + +case "$target" in + "msm7201a_ffa" | "msm7201a_surf" | "msm7627_ffa" | "msm7627_6x" | "msm7627a" | "msm7627_surf" | \ + "qsd8250_surf" | "qsd8250_ffa" | "msm7630_surf" | "msm7630_1x" | "msm7630_fusion" | "qsd8650a_st1x") + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + ;; +esac + +case "$target" in + "msm7201a_ffa" | "msm7201a_surf") + echo 500000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + ;; +esac + +case "$target" in + "msm7630_surf" | "msm7630_1x" | "msm7630_fusion") + echo 75000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 1 > /sys/module/pm2/parameters/idle_sleep_mode + ;; +esac + +case "$target" in + "msm7201a_ffa" | "msm7201a_surf" | "msm7627_ffa" | "msm7627_6x" | "msm7627_surf" | "msm7630_surf" | "msm7630_1x" | "msm7630_fusion" | "msm7627a" ) + echo 245760 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + ;; +esac + +case "$target" in + "msm8660") + echo 1 > /sys/module/rpm_resources/enable_low_power/L2_cache + echo 1 > /sys/module/rpm_resources/enable_low_power/pxo + echo 2 > /sys/module/rpm_resources/enable_low_power/vdd_dig + echo 2 > /sys/module/rpm_resources/enable_low_power/vdd_mem + echo 1 > /sys/module/rpm_resources/enable_low_power/rpm_cpu + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 4 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + echo 384000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 384000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + chown -h root.system /sys/devices/system/cpu/mfreq + chmod -h 220 /sys/devices/system/cpu/mfreq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + ;; +esac + +case "$target" in + "msm8960") + echo 1 > /sys/module/rpm_resources/enable_low_power/L2_cache + echo 1 > /sys/module/rpm_resources/enable_low_power/pxo + echo 1 > /sys/module/rpm_resources/enable_low_power/vdd_dig + echo 1 > /sys/module/rpm_resources/enable_low_power/vdd_mem + echo 1 > /sys/module/msm_pm/modes/cpu0/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 4 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential + echo 70 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core + echo 3 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential_multi_core + echo 918000 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq + echo 1026000 > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq + echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load + chown -h system /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + chown -h system /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + chown -h system /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 384000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 384000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 384000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 384000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 1 > /sys/module/msm_thermal/core_control/enabled + chown -h root.system /sys/devices/system/cpu/mfreq + chmod -h 220 /sys/devices/system/cpu/mfreq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + # set DCVS parameters for CPU + echo 40000 > /sys/module/msm_dcvs/cores/cpu0/slack_time_max_us + echo 40000 > /sys/module/msm_dcvs/cores/cpu0/slack_time_min_us + echo 100000 > /sys/module/msm_dcvs/cores/cpu0/em_win_size_min_us + echo 500000 > /sys/module/msm_dcvs/cores/cpu0/em_win_size_max_us + echo 0 > /sys/module/msm_dcvs/cores/cpu0/slack_mode_dynamic + echo 1000000 > /sys/module/msm_dcvs/cores/cpu0/disable_pc_threshold + echo 25000 > /sys/module/msm_dcvs/cores/cpu1/slack_time_max_us + echo 25000 > /sys/module/msm_dcvs/cores/cpu1/slack_time_min_us + echo 100000 > /sys/module/msm_dcvs/cores/cpu1/em_win_size_min_us + echo 500000 > /sys/module/msm_dcvs/cores/cpu1/em_win_size_max_us + echo 0 > /sys/module/msm_dcvs/cores/cpu1/slack_mode_dynamic + echo 1000000 > /sys/module/msm_dcvs/cores/cpu1/disable_pc_threshold + echo 25000 > /sys/module/msm_dcvs/cores/cpu2/slack_time_max_us + echo 25000 > /sys/module/msm_dcvs/cores/cpu2/slack_time_min_us + echo 100000 > /sys/module/msm_dcvs/cores/cpu2/em_win_size_min_us + echo 500000 > /sys/module/msm_dcvs/cores/cpu2/em_win_size_max_us + echo 0 > /sys/module/msm_dcvs/cores/cpu2/slack_mode_dynamic + echo 1000000 > /sys/module/msm_dcvs/cores/cpu2/disable_pc_threshold + echo 25000 > /sys/module/msm_dcvs/cores/cpu3/slack_time_max_us + echo 25000 > /sys/module/msm_dcvs/cores/cpu3/slack_time_min_us + echo 100000 > /sys/module/msm_dcvs/cores/cpu3/em_win_size_min_us + echo 500000 > /sys/module/msm_dcvs/cores/cpu3/em_win_size_max_us + echo 0 > /sys/module/msm_dcvs/cores/cpu3/slack_mode_dynamic + echo 1000000 > /sys/module/msm_dcvs/cores/cpu3/disable_pc_threshold + # set DCVS parameters for GPU + echo 20000 > /sys/module/msm_dcvs/cores/gpu0/slack_time_max_us + echo 20000 > /sys/module/msm_dcvs/cores/gpu0/slack_time_min_us + echo 0 > /sys/module/msm_dcvs/cores/gpu0/slack_mode_dynamic + # set msm_mpdecision parameters + echo 45000 > /sys/module/msm_mpdecision/slack_time_max_us + echo 15000 > /sys/module/msm_mpdecision/slack_time_min_us + echo 100000 > /sys/module/msm_mpdecision/em_win_size_min_us + echo 1000000 > /sys/module/msm_mpdecision/em_win_size_max_us + echo 3 > /sys/module/msm_mpdecision/online_util_pct_min + echo 25 > /sys/module/msm_mpdecision/online_util_pct_max + echo 97 > /sys/module/msm_mpdecision/em_max_util_pct + echo 2 > /sys/module/msm_mpdecision/rq_avg_poll_ms + echo 10 > /sys/module/msm_mpdecision/mp_em_rounding_point_min + echo 85 > /sys/module/msm_mpdecision/mp_em_rounding_point_max + echo 50 > /sys/module/msm_mpdecision/iowait_threshold_pct + #set permissions for the nodes needed by display on/off hook + chown -h system /sys/module/msm_dcvs/cores/cpu0/slack_time_max_us + chown -h system /sys/module/msm_dcvs/cores/cpu0/slack_time_min_us + chown -h system /sys/module/msm_mpdecision/slack_time_max_us + chown -h system /sys/module/msm_mpdecision/slack_time_min_us + chmod -h 664 /sys/module/msm_dcvs/cores/cpu0/slack_time_max_us + chmod -h 664 /sys/module/msm_dcvs/cores/cpu0/slack_time_min_us + chmod -h 664 /sys/module/msm_mpdecision/slack_time_max_us + chmod -h 664 /sys/module/msm_mpdecision/slack_time_min_us + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + case "$soc_id" in + "130") + echo 230 > /sys/class/gpio/export + echo 228 > /sys/class/gpio/export + echo 229 > /sys/class/gpio/export + echo "in" > /sys/class/gpio/gpio230/direction + echo "rising" > /sys/class/gpio/gpio230/edge + echo "in" > /sys/class/gpio/gpio228/direction + echo "rising" > /sys/class/gpio/gpio228/edge + echo "in" > /sys/class/gpio/gpio229/direction + echo "rising" > /sys/class/gpio/gpio229/edge + echo 253 > /sys/class/gpio/export + echo 254 > /sys/class/gpio/export + echo 257 > /sys/class/gpio/export + echo 258 > /sys/class/gpio/export + echo 259 > /sys/class/gpio/export + echo "out" > /sys/class/gpio/gpio253/direction + echo "out" > /sys/class/gpio/gpio254/direction + echo "out" > /sys/class/gpio/gpio257/direction + echo "out" > /sys/class/gpio/gpio258/direction + echo "out" > /sys/class/gpio/gpio259/direction + chown -h media /sys/class/gpio/gpio253/value + chown -h media /sys/class/gpio/gpio254/value + chown -h media /sys/class/gpio/gpio257/value + chown -h media /sys/class/gpio/gpio258/value + chown -h media /sys/class/gpio/gpio259/value + chown -h media /sys/class/gpio/gpio253/direction + chown -h media /sys/class/gpio/gpio254/direction + chown -h media /sys/class/gpio/gpio257/direction + chown -h media /sys/class/gpio/gpio258/direction + chown -h media /sys/class/gpio/gpio259/direction + echo 0 > /sys/module/rpm_resources/enable_low_power/vdd_dig + echo 0 > /sys/module/rpm_resources/enable_low_power/vdd_mem + ;; + esac + ;; +esac + +case "$target" in + "msm8974") + echo 4 > /sys/module/lpm_levels/enable_low_power/l2 + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/retention/idle_enabled + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + case "$soc_id" in + "208" | "211" | "214" | "217" | "209" | "212" | "215" | "218" | "194" | "210" | "213" | "216") + for devfreq_gov in /sys/class/devfreq/qcom,cpubw*/governor + do + echo "cpubw_hwmon" > $devfreq_gov + done + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor + echo "20000 1400000:40000 1700000:20000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 1190400 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "85 1500000:90 1800000:70" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 20 > /sys/module/cpu_boost/parameters/boost_ms + echo 1728000 > /sys/module/cpu_boost/parameters/sync_threshold + echo 100000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + echo 1497600 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + ;; + *) + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 2 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential + echo 70 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core + echo 3 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential_multi_core + echo 960000 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq + echo 960000 > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq + echo 1190400 > /sys/devices/system/cpu/cpufreq/ondemand/input_boost + echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load + ;; + esac + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1 > /sys/module/msm_thermal/core_control/enabled + chown -h root.system /sys/devices/system/cpu/mfreq + chmod -h 220 /sys/devices/system/cpu/mfreq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + echo 1 > /dev/cpuctl/apps/cpu.notify_on_migrate + ;; +esac + +case "$target" in + "msm8916") + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + case "$soc_id" in + "206") + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 2 > /sys/class/net/rmnet0/queues/rx-0/rps_cpus + ;; + "247" | "248" | "249" | "250") + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + ;; + "239" | "241" | "263") + if [ -f /sys/devices/soc0/revision ]; then + revision=`cat /sys/devices/soc0/revision` + else + revision=`cat /sys/devices/system/soc/soc0/revision` + fi + echo 10 > /sys/class/net/rmnet0/queues/rx-0/rps_cpus + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + fi + case "$soc_id" in + "239") + case "$hw_platform" in + "Surf") + case "$platform_subtype_id" in + "1" | "2") + start_hbtp + ;; + esac + ;; + "MTP") + case "$platform_subtype_id" in + "3") + start_hbtp + ;; + esac + ;; + esac + ;; + esac + ;; + "268" | "269" | "270" | "271") + echo 10 > /sys/class/net/rmnet0/queues/rx-0/rps_cpus + ;; + "233" | "240" | "242") + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + ;; + esac + ;; +esac + +case "$target" in + "msm8226") + echo 4 > /sys/module/lpm_levels/enable_low_power/l2 + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/idle_enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 2 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential + echo 70 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential_multi_core + echo 787200 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq + echo 300000 > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq + echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + ;; +esac + +case "$target" in + "msm8610") + echo 4 > /sys/module/lpm_levels/enable_low_power/l2 + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/idle_enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 2 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential + echo 70 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core + echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential_multi_core + echo 787200 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq + echo 300000 > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq + echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + setprop ro.qualcomm.perf.min_freq 7 + echo 1 > /sys/kernel/mm/ksm/deferred_timer + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + ;; +esac + +case "$target" in + "msm8916") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + # HMP scheduler settings for 8916, 8936, 8939, 8929 + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + + # Apply governor settings for 8916 + case "$soc_id" in + "206" | "247" | "248" | "249" | "250") + + # HMP scheduler load tracking settings + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + + # HMP Task packing settings for 8916 + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /proc/sys/kernel/sched_mostly_idle_load + echo 3 > /proc/sys/kernel/sched_mostly_idle_nr_run + + # disable thermal core_control to update scaling_min_freq + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 800000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + # enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + echo "25000 1094400:50000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 30000 > /sys/devices/system/cpu/cpufreq/interactive/timer_rate + echo 998400 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "1 800000:85 998400:90 1094400:80" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + ;; + esac + + # Apply governor settings for 8936 + case "$soc_id" in + "233" | "240" | "242") + + # HMP scheduler load tracking settings + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + + # HMP Task packing settings for 8936 + echo 50 > /proc/sys/kernel/sched_small_task + echo 50 > /proc/sys/kernel/sched_mostly_idle_load + echo 10 > /proc/sys/kernel/sched_mostly_idle_nr_run + + # disable thermal core_control to update scaling_min_freq, interactive gov + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 800000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + # enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + echo "25000 1113600:50000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 30000 > /sys/devices/system/cpu/cpufreq/interactive/timer_rate + echo 960000 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "1 800000:85 1113600:90 1267200:80" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + for gpu_bimc_io_percent in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + ;; + esac + + # Apply governor settings for 8939 + case "$soc_id" in + "239" | "241" | "263" | "268" | "269" | "270" | "271") + + if [ `cat /sys/devices/soc0/revision` != "3.0" ]; then + # Apply 1.0 and 2.0 specific Sched & Governor settings + + # HMP scheduler load tracking settings + echo 5 > /proc/sys/kernel/sched_ravg_hist_size + + # HMP Task packing settings for 8939, 8929 + echo 20 > /proc/sys/kernel/sched_small_task + + for devfreq_gov in /sys/class/devfreq/*qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/*qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + # disable thermal core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "20000 1113600:50000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1113600 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "1 960000:85 1113600:90 1344000:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 50000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 50000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/sampling_down_factor + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo "25000 800000:50000" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 998400 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "1 800000:90" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/sampling_down_factor + echo 800000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + # enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # HMP scheduler (big.Little cluster related) settings + echo 75 > /proc/sys/kernel/sched_upmigrate + echo 60 > /proc/sys/kernel/sched_downmigrate + + # cpu idle load threshold + echo 30 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_load + + # cpu idle nr run threshold + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_nr_run + + else + # Apply 3.0 specific Sched & Governor settings + # HMP scheduler settings for 8939 V3.0 + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + echo 20000000 > /proc/sys/kernel/sched_ravg_window + + # HMP Task packing settings for 8939 V3.0 + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /proc/sys/kernel/sched_mostly_idle_load + echo 3 > /proc/sys/kernel/sched_mostly_idle_nr_run + + echo 0 > /sys/devices/system/cpu/cpu0/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu1/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu2/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu3/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu4/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu5/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu6/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu7/sched_prefer_idle + + for devfreq_gov in /sys/class/devfreq/*qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/*qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + # disable thermal core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "19000 1113600:39000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1113600 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "1 960000:85 1113600:90 1344000:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/sampling_down_factor + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 39000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 800000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "1 800000:90" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/sampling_down_factor + echo 800000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + # enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # HMP scheduler (big.Little cluster related) settings + echo 93 > /proc/sys/kernel/sched_upmigrate + echo 83 > /proc/sys/kernel/sched_downmigrate + + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 50000 > /proc/sys/kernel/sched_freq_inc_notify + echo 50000 > /proc/sys/kernel/sched_freq_dec_notify + + # Enable core control +# insmod /system/lib/modules/core_ctl.ko + echo 2 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus + echo 68 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + case "$revision" in + "3.0") + # Enable dynamic clock gatin + echo 1 > /sys/module/lpm_levels/lpm_workarounds/dynamic_clock_gating + ;; + esac + fi + ;; + esac + # Set Memory parameters + configure_memory_parameters + ;; +esac + +case "$target" in + "msm8952") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + case "$soc_id" in + "264" | "289") + # Apply Scheduler and Governor settings for 8952 + + # HMP scheduler settings + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + echo 20000000 > /proc/sys/kernel/sched_ravg_window + + # HMP Task packing settings + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_load + + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_nr_run + + echo 0 > /sys/devices/system/cpu/cpu0/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu1/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu2/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu3/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu4/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu5/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu6/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu7/sched_prefer_idle + + echo 0 > /proc/sys/kernel/sched_boost + + for devfreq_gov in /sys/class/devfreq/*qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/*qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + for cpu_guard_band in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/guard_band_mbps + do + echo 30 > $cpu_guard_band + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + # disable thermal & BCL core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "19000 1113600:39000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1113600 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "1 960000:85 1113600:90 1344000:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/sampling_down_factor + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 39000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 806400 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "1 806400:90" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/sampling_down_factor + echo 806400 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable Low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # HMP scheduler (big.Little cluster related) settings + echo 93 > /proc/sys/kernel/sched_upmigrate + echo 83 > /proc/sys/kernel/sched_downmigrate + + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 50000 > /proc/sys/kernel/sched_freq_inc_notify + echo 50000 > /proc/sys/kernel/sched_freq_dec_notify + + # Enable core control + echo 2 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus + echo 68 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + + # re-enable thermal & BCL core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # Enable dynamic clock gating + echo 1 > /sys/module/lpm_levels/lpm_workarounds/dynamic_clock_gating + # Enable timer migration to little cluster + echo 1 > /proc/sys/kernel/power_aware_timer_migration + + # Set Memory parameters + configure_memory_parameters + + ;; + *) + panel=`cat /sys/class/graphics/fb0/modes` + if [ "${panel:5:1}" == "x" ]; then + panel=${panel:2:3} + else + panel=${panel:2:4} + fi + + # Apply Scheduler and Governor settings for 8976 + # SoC IDs are 266, 274, 277, 278 + + # HMP scheduler (big.Little cluster related) settings + echo 95 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_downmigrate + + echo 2 > /proc/sys/kernel/sched_window_stats_policy + echo 5 > /proc/sys/kernel/sched_ravg_hist_size + + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_nr_run + + for devfreq_gov in /sys/class/devfreq/*qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/*qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + for cpu_guard_band in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/guard_band_mbps + do + echo 30 > $cpu_guard_band + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + # disable thermal & BCL core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # enable governor for power cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 691200 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # enable governor for perf cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/sampling_down_factor + echo 883200 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 60000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + + if [ $panel -gt 1080 ]; then + #set texture cache size for resolution greater than 1080p + setprop ro.hwui.texture_cache_size 72 + fi + + echo 59000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 1305600 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo "1 691200:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 1382400 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo "19000 1382400:39000" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo "85 1382400:90 1747200:80" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + # HMP Task packing settings for 8976 + echo 30 > /proc/sys/kernel/sched_small_task + echo 20 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu4/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu5/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu6/sched_mostly_idle_load + echo 20 > /sys/devices/system/cpu/cpu7/sched_mostly_idle_load + + echo 0 > /proc/sys/kernel/sched_boost + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + #Disable CPU retention modes for 32bit builds + ProductName=`getprop ro.product.name` + if [ "$ProductName" == "msm8952_32" ] || [ "$ProductName" == "msm8952_32_LMT" ]; then + echo N > /sys/module/lpm_levels/system/a72/cpu4/retention/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/cpu5/retention/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/cpu6/retention/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/cpu7/retention/idle_enabled + fi + + if [ `cat /sys/devices/soc0/revision` == "1.0" ]; then + # Disable l2-pc and l2-gdhs low power modes + echo N > /sys/module/lpm_levels/system/a53/a53-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/a72-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/a53/a53-l2-pc/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/a72-l2-pc/idle_enabled + fi + + # Enable LPM Prediction + echo 1 > /sys/module/lpm_levels/parameters/lpm_prediction + + # Enable Low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + # Disable L2 GDHS on 8976 + echo N > /sys/module/lpm_levels/system/a53/a53-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/a72/a72-l2-gdhs/idle_enabled + + # Enable sched guided freq control + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 50000 > /proc/sys/kernel/sched_freq_inc_notify + echo 50000 > /proc/sys/kernel/sched_freq_dec_notify + + # Enable core control + #for 8976 + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/max_cpus + echo 68 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/is_big_cluster + + # re-enable thermal & BCL core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # Enable timer migration to little cluster + echo 1 > /proc/sys/kernel/power_aware_timer_migration + + case "$soc_id" in + "277" | "278") + # Start energy-awareness for 8976 + start energy-awareness + ;; + esac + + #enable sched colocation and colocation inheritance + echo 130 > /proc/sys/kernel/sched_grp_upmigrate + echo 110 > /proc/sys/kernel/sched_grp_downmigrate + echo 1 > /proc/sys/kernel/sched_enable_thread_grouping + + # Set Memory parameters + configure_memory_parameters + + ;; + esac + #Enable Memory Features + enable_memory_features + restorecon -R /sys/devices/system/cpu + ;; +esac + +case "$target" in + "msm8953") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + echo 0 > /proc/sys/kernel/sched_boost + + case "$soc_id" in + "293" | "304" | "338" | "351") + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" ) + #if this directory is present, it means that a + #1200p panel is connected to the device. + dir="/sys/bus/i2c/devices/3-0038" + if [ ! -d "$dir" ]; then + start_hbtp + fi + ;; + esac + + if [ $soc_id -eq "338" ]; then + case "$hw_platform" in + "QRD" ) + if [ $platform_subtype_id -eq "1" ]; then + start_hbtp + fi + ;; + esac + fi + + #init task load, restrict wakeups to preferred cluster + echo 15 > /proc/sys/kernel/sched_init_task_load + + for devfreq_gov in /sys/class/devfreq/qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/soc:qcom,cpubw/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/io_percent + do + echo 34 > $cpu_io_percent + done + for cpu_guard_band in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/guard_band_mbps + do + echo 0 > $cpu_guard_band + done + for cpu_hist_memory in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/hist_memory + do + echo 20 > $cpu_hist_memory + done + for cpu_hyst_length in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/hyst_length + do + echo 10 > $cpu_hyst_length + done + for cpu_idle_mbps in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/idle_mbps + do + echo 1600 > $cpu_idle_mbps + done + for cpu_low_power_delay in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/low_power_delay + do + echo 20 > $cpu_low_power_delay + done + for cpu_low_power_io_percent in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/low_power_io_percent + do + echo 34 > $cpu_low_power_io_percent + done + for cpu_mbps_zones in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/mbps_zones + do + echo "1611 3221 5859 6445 7104" > $cpu_mbps_zones + done + for cpu_sample_ms in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/sample_ms + do + echo 4 > $cpu_sample_ms + done + for cpu_up_scale in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/up_scale + do + echo 250 > $cpu_up_scale + done + for cpu_min_freq in /sys/class/devfreq/soc:qcom,cpubw/min_freq + do + echo 1611 > $cpu_min_freq + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/soc:qcom,gpubw/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + + # disable thermal & BCL core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + #if the kernel version >=4.9,use the schedutil governor + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 9 ]; then + 8953_sched_dcvs_eas + else + 8953_sched_dcvs_hmp + echo 652800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + fi + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # re-enable thermal & BCL core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # SMP scheduler + echo 85 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_downmigrate + + # Set Memory parameters + configure_memory_parameters + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + disable_ppr + fi + ;; + esac + case "$soc_id" in + "349" | "350") + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + esac + + for devfreq_gov in /sys/class/devfreq/qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo "1611 3221 5859 6445 7104" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 34 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + # Configure DCC module to capture critical register contents when device crashes + for DCC_PATH in /sys/bus/platform/devices/*.dcc* + do + echo 0 > $DCC_PATH/enable + echo cap > $DCC_PATH/func_type + echo sram > $DCC_PATH/data_sink + echo 1 > $DCC_PATH/config_reset + + # Register specifies APC CPR closed-loop settled voltage for current voltage corner + echo 0xb1d2c18 1 > $DCC_PATH/config + + # Register specifies SW programmed open-loop voltage for current voltage corner + echo 0xb1d2900 1 > $DCC_PATH/config + + # Register specifies APM switch settings and APM FSM state + echo 0xb1112b0 1 > $DCC_PATH/config + + # Register specifies CPR mode change state and also #online cores input to CPR HW + echo 0xb018798 1 > $DCC_PATH/config + + echo 1 > $DCC_PATH/enable + done + + # disable thermal & BCL core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # configure governor settings for little cluster + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1363200 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for sdm632 it should be 85 + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + # sched_load_boost as -6 is equivalent to target load as 85. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + + # configure governor settings for big cluster + echo 1 > /sys/devices/system/cpu/cpu4/online + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + #default value for hispeed_load is 90, for sdm632 it should be 85 + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + # sched_load_boost as -6 is equivalent to target load as 85. + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + + echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 633600 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + # choose idle CPU for top app tasks + echo 1 > /dev/stune/top-app/schedtune.prefer_idle + + # re-enable thermal & BCL core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # Disable Core control + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + echo 0 > /sys/devices/system/cpu/cpu4/core_ctl/enable + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # Set Memory parameters + configure_memory_parameters + + # Setting b.L scheduler parameters + echo 76 > /proc/sys/kernel/sched_downmigrate + echo 86 > /proc/sys/kernel/sched_upmigrate + echo 80 > /proc/sys/kernel/sched_group_downmigrate + echo 90 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # Enable min frequency adjustment for big cluster + if [ -f /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_cluster ]; then + echo "4-7" > /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_cluster + fi + echo 1 > /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_adjust + + ;; + esac + ;; +esac + +case "$target" in + "msm8937") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + # Socid 386 = Pukeena + case "$soc_id" in + "303" | "307" | "308" | "309" | "320" | "386" | "436") + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" ) + start_hbtp + ;; + esac + + case "$hw_platform" in + "Surf" | "RCM" ) + if [ $platform_subtype_id -ne "4" ]; then + start_hbtp + fi + ;; + esac + # Apply Scheduler and Governor settings for 8917 / 8920 + + echo 20000000 > /proc/sys/kernel/sched_ravg_window + + #disable sched_boost in 8917 + echo 0 > /proc/sys/kernel/sched_boost + + # core_ctl is not needed for 8917. Disable it. + disable_core_ctl + + if [ $KernelVersionA -le 4 ] && [ $KernelVersionB -le 9 ]; then + for devfreq_gov in /sys/class/devfreq/qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/soc:qcom,cpubw/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + for cpu_guard_band in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/guard_band_mbps + do + echo 30 > $cpu_guard_band + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/soc:qcom,gpubw/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + fi + + # disable thermal core_control to update interactive gov settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 9 ]; then + 8917_sched_dcvs_eas + else + 8917_sched_dcvs_hmp + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + fi + + # re-enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Disable L2-GDHS low power modes + echo N > /sys/module/lpm_levels/perf/perf-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/perf/perf-l2-gdhs/suspend_enabled + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # Set rps mask + echo 2 > /sys/class/net/rmnet0/queues/rx-0/rps_cpus + + # Enable dynamic clock gating + echo 1 > /sys/module/lpm_levels/lpm_workarounds/dynamic_clock_gating + # Enable timer migration to little cluster + echo 1 > /proc/sys/kernel/power_aware_timer_migration + # Set Memory parameters + configure_memory_parameters + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + disable_ppr + fi + ;; + *) + ;; + esac + + case "$soc_id" in + "294" | "295" | "313" ) + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" ) + start_hbtp + ;; + esac + + # Apply Scheduler and Governor settings for 8937/8940 + + # HMP scheduler settings + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + echo 20000000 > /proc/sys/kernel/sched_ravg_window + + #disable sched_boost in 8937 + echo 0 > /proc/sys/kernel/sched_boost + + if [ $KernelVersionA -le 4 ] && [ $KernelVersionB -le 9 ]; then + for devfreq_gov in /sys/class/devfreq/qcom,mincpubw*/governor + do + echo "cpufreq" > $devfreq_gov + done + + for devfreq_gov in /sys/class/devfreq/soc:qcom,cpubw/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_io_percent in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/io_percent + do + echo 20 > $cpu_io_percent + done + for cpu_guard_band in /sys/class/devfreq/soc:qcom,cpubw/bw_hwmon/guard_band_mbps + do + echo 30 > $cpu_guard_band + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/soc:qcom,gpubw/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + fi + + # disable thermal core_control to update interactive gov and core_ctl settings + echo 0 > /sys/module/msm_thermal/core_control/enabled + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 9 ]; then + 8937_sched_dcvs_eas + else + 8937_sched_dcvs_hmp + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 768000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + fi + # Disable L2-GDHS low power modes + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-gdhs/suspend_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-gdhs/suspend_enabled + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # HMP scheduler (big.Little cluster related) settings + echo 93 > /proc/sys/kernel/sched_upmigrate + echo 83 > /proc/sys/kernel/sched_downmigrate + + # Enable core control + echo 2 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus + echo 68 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + + # re-enable thermal core_control + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Enable dynamic clock gating + echo 1 > /sys/module/lpm_levels/lpm_workarounds/dynamic_clock_gating + # Enable timer migration to little cluster + echo 1 > /proc/sys/kernel/power_aware_timer_migration + # Set Memory parameters + configure_memory_parameters + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + disable_ppr + fi + ;; + *) + + ;; + esac + + case "$soc_id" in + "354" | "364" | "353" | "363" ) + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + esac + + # Apply settings for sdm429/sda429/sdm439/sda439 + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 20 > $cpubw/bw_hwmon/io_percent + echo 30 > $cpubw/bw_hwmon/guard_band_mbps + done + done + else + for cpubw in /sys/class/devfreq/*qcom,mincpubw* + do + echo "cpufreq" > $cpubw/governor + done + + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 20 > $cpubw/bw_hwmon/io_percent + echo 30 > $cpubw/bw_hwmon/guard_band_mbps + done + + for gpu_bimc_io_percent in /sys/class/devfreq/soc:qcom,gpubw/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + fi + + case "$soc_id" in + "353" | "363" ) + # Apply settings for sdm439/sda439 + echo 1 > /sys/devices/system/cpu/cpu0/online + echo 1 > /sys/devices/system/cpu/cpu4/online + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # configure schedutil governor settings + # enable governor for perf cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 1497600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 80 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + echo 960000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + + #input boost params + echo 1497600 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + ## enable governor for power cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 998400 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + echo 85 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/rtg_boost_freq + echo 768000 > /sys/devices/system/cpu/cpufreq/policy4/scaling_min_freq + else + # configure schedutil governor settings + # enable governor for perf cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 1497600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + ## enable governor for power cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 998400 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + echo 768000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + fi + + # sched_load_boost as -6 is equivalent to target load as 85. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + + # EAS scheduler (big.Little cluster related) settings + echo 93 > /proc/sys/kernel/sched_upmigrate + echo 83 > /proc/sys/kernel/sched_downmigrate + echo 140 > /proc/sys/kernel/sched_group_upmigrate + echo 120 > /proc/sys/kernel/sched_group_downmigrate + + # cpuset settings + #echo 0-3 > /dev/cpuset/background/cpus + #echo 0-3 > /dev/cpuset/system-background/cpus + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # Enable core control + echo 2 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus + echo 68 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + + # Big cluster min frequency adjust settings + if [ -f /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_cluster ]; then + echo "0-3" > /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_cluster + fi + echo 1305600 > /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_floor + ;; + *) + # Apply settings for sdm429/sda429 + # configure schedutil governor settings + echo 1 > /sys/devices/system/cpu/cpu0/online + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 1305600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 80 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_load + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + echo 960000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + #input boost params + + echo 1305600 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + else + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + + #set the hispeed_freq + echo 1305600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + fi + + # sched_load_boost as -6 is equivalent to target load as 85. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + ;; + esac + + # Set Memory parameters + configure_memory_parameters + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 19 ]; then + disable_ppr + fi + + #disable sched_boost + echo 0 > /proc/sys/kernel/sched_boost + + # Disable L2-GDHS low power modes + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-gdhs/suspend_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-gdhs/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-gdhs/suspend_enabled + + # Enable low power modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + case "$soc_id" in + "353" | "363" ) + echo 1 > /sys/module/big_cluster_min_freq_adjust/parameters/min_freq_adjust + ;; + esac + ;; + esac + + case "$soc_id" in + "386" | "436") + + # Start Host based Touch processing + case "$hw_platform" in + "QRD" ) + start_hbtp + ;; + esac + ;; + esac + ;; +esac + +case "$target" in + "sdm660") + + # Set the default IRQ affinity to the primary cluster. When a + # CPU is isolated/hotplugged, the IRQ affinity is adjusted + # to one of the CPU from the default IRQ affinity mask. + echo f > /proc/irq/default_smp_affinity + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + panel=`cat /sys/class/graphics/fb0/modes` + if [ "${panel:5:1}" == "x" ]; then + panel=${panel:2:3} + else + panel=${panel:2:4} + fi + + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -le 14 ]; then + if [ $panel -gt 1080 ]; then + echo 2 > /proc/sys/kernel/sched_window_stats_policy + echo 5 > /proc/sys/kernel/sched_ravg_hist_size + else + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + fi + fi + #Apply settings for sdm660, sdm636,sda636 + case "$soc_id" in + "317" | "324" | "325" | "326" | "345" | "346" ) + + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/is_big_cluster + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 96 > /proc/sys/kernel/sched_upmigrate + echo 90 > /proc/sys/kernel/sched_downmigrate + echo 140 > /proc/sys/kernel/sched_group_upmigrate + echo 120 > /proc/sys/kernel/sched_group_downmigrate + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + #if the kernel version >=4.14,use the schedutil governor + if [ $KernelVersionA -ge 4 ] && [ $KernelVersionB -ge 14 ]; then + sdm660_sched_schedutil_dcvs + else + sdm660_sched_interactive_dcvs + fi + + # Set Memory parameters + configure_memory_parameters + + # enable LPM + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # Start cdsprpcd only for sdm660 and disable for sdm630 + start vendor.cdsprpcd + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + esac + ;; + esac + #Apply settings for sdm630 and Tahaa + case "$soc_id" in + "318" | "327" | "385" ) + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + esac + + # Disable cdsprpcd daemon for sdm630 + setprop vendor.fastrpc.disable.cdsprpcd.daemon 1 + + # Setting b.L scheduler parameters + echo 85 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_downmigrate + echo 900 > /proc/sys/kernel/sched_group_upmigrate + echo 900 > /proc/sys/kernel/sched_group_downmigrate + echo 0 > /proc/sys/kernel/sched_select_prev_cpu_us + echo 400000 > /proc/sys/kernel/sched_freq_inc_notify + echo 400000 > /proc/sys/kernel/sched_freq_dec_notify + echo 3 > /proc/sys/kernel/sched_spill_nr_run + + #init task load, restrict wakeups to preferred cluster + echo 15 > /proc/sys/kernel/sched_init_task_load + echo 1 > /proc/sys/kernel/sched_restrict_cluster_spill + echo 50000 > /proc/sys/kernel/sched_short_burst_ns + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # online CPU0 + echo 1 > /sys/devices/system/cpu/cpu0/online + # configure governor settings for Big cluster(CPU0 to CPU3) + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo "19000 1344000:39000" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1344000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "85 1344000:80" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 39000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 787200 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/ignore_hispeed_on_notif + + # online CPU4 + echo 1 > /sys/devices/system/cpu/cpu4/online + # configure governor settings for Little cluster(CPU4 to CPU7) + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo "19000 1094400:39000" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 1094400 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "85 1094400:80" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 39000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + echo 614400 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/ignore_hispeed_on_notif + + # bring all cores online + echo 1 > /sys/devices/system/cpu/cpu0/online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 1 > /sys/devices/system/cpu/cpu4/online + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + + # configure LPM + echo N > /sys/module/lpm_levels/system/perf/cpu0/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu1/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu2/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu3/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu4/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu5/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu6/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu7/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-dynret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-dynret/idle_enabled + # enable LPM + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + echo "1525 3143 4173 5195 5859 7759 9887 10327" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 85 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 100 > $cpubw/bw_hwmon/decay_rate + echo 50 > $cpubw/bw_hwmon/bw_step + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/low_power_ceil_mbps + echo 50 > $cpubw/bw_hwmon/low_power_io_percent + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor + ;; + esac + ;; +esac + +case "$target" in + "sdm710") + + #Apply settings for sdm710 + # Set the default IRQ affinity to the silver cluster. When a + # CPU is isolated/hotplugged, the IRQ affinity is adjusted + # to one of the CPU from the default IRQ affinity mask. + echo 3f > /proc/irq/default_smp_affinity + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + case "$soc_id" in + "336" | "337" | "347" | "360" | "393" ) + + # Start Host based Touch processing + case "$hw_platform" in + "MTP" | "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + esac + + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 96 > /proc/sys/kernel/sched_upmigrate + echo 90 > /proc/sys/kernel/sched_downmigrate + echo 140 > /proc/sys/kernel/sched_group_upmigrate + echo 120 > /proc/sys/kernel/sched_group_downmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/rate_limit_us + echo 1344000 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + echo 652800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + + echo "0:1209600" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo "1144 1720 2086 2929 3879 5931 6881" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + #Enable mem_latency governor for DDR scaling + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable mem_latency governor for L3 scaling + for memlat in /sys/class/devfreq/*qcom,l3-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable userspace governor for L3 cdsp nodes + for l3cdsp in /sys/class/devfreq/*qcom,l3-cdsp* + do + echo "userspace" > $l3cdsp/governor + chown -h system $l3cdsp/userspace/set_freq + done + + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor + + # Disable CPU Retention + echo N > /sys/module/lpm_levels/L3/cpu0/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu1/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu2/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu3/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu4/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu5/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu6/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu7/ret/idle_enabled + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac + ;; +esac + +case "$target" in + "trinket") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + case "$soc_id" in + "394" | "467" | "468" ) + + # Core control parameters on big + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/is_big_cluster + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 67 > /proc/sys/kernel/sched_downmigrate + echo 77 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1305600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + echo 1056000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type` + ddr_type4="07" + ddr_type3="05" + + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 762 > $cpubw/min_freq + if [ ${ddr_type:4:2} == $ddr_type4 ]; then + # LPDDR4 + echo "2288 3440 4173 5195 5859 7759 10322 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 85 > $cpubw/bw_hwmon/io_percent + fi + if [ ${ddr_type:4:2} == $ddr_type3 ]; then + # LPDDR3 + echo "1525 3440 5195 5859 7102" > $cpubw/bw_hwmon/mbps_zones + echo 34 > $cpubw/bw_hwmon/io_percent + fi + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 90 > $cpubw/bw_hwmon/decay_rate + echo 190 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # colcoation v3 disabled + echo 0 > /proc/sys/kernel/sched_min_task_util_for_boost + echo 0 > /proc/sys/kernel/sched_min_task_util_for_colocation + echo 0 > /proc/sys/kernel/sched_little_cluster_coloc_fmin_khz + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + ;; + esac + ;; +esac + +case "$target" in + "sm6150") + + #Apply settings for sm6150 + # Set the default IRQ affinity to the silver cluster. When a + # CPU is isolated/hotplugged, the IRQ affinity is adjusted + # to one of the CPU from the default IRQ affinity mask. + echo 3f > /proc/irq/default_smp_affinity + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + case "$soc_id" in + "355" | "369" | "377" | "380" | "384" ) + target_type=`getprop ro.hardware.type` + if [ "$target_type" == "automotive" ]; then + # update frequencies + configure_sku_parameters + sku_identified=`getprop vendor.sku_identified` + else + sku_identified=0 + fi + + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + + + # Setting b.L scheduler parameters + # default sched up and down migrate values are 90 and 85 + echo 65 > /proc/sys/kernel/sched_downmigrate + echo 71 > /proc/sys/kernel/sched_upmigrate + # default sched up and down migrate values are 100 and 95 + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # colocation v3 settings + echo 740000 > /proc/sys/kernel/sched_little_cluster_coloc_fmin_khz + + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + if [ $sku_identified != 1 ]; then + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + fi + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + if [ $sku_identified != 1 ]; then + echo 768000 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + fi + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + + echo "0:1209600" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1144 1720 2086 2929 3879 5931 6881" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 68 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 0 > $llccbw/bw_hwmon/hyst_length + echo 80 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 40 > $llccbw/polling_interval + done + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac + + #Apply settings for moorea + case "$soc_id" in + "365" | "366" ) + + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + + # Setting b.L scheduler parameters + # default sched up and down migrate values are 71 and 65 + echo 65 > /proc/sys/kernel/sched_downmigrate + echo 71 > /proc/sys/kernel/sched_upmigrate + # default sched up and down migrate values are 100 and 95 + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + #colocation v3 settings + echo 740000 > /proc/sys/kernel/sched_little_cluster_coloc_fmin_khz + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1248000 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us + echo 1324600 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + echo 652800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + + echo "0:1248000" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1144 1720 2086 2929 3879 5931 6881" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 68 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 0 > $llccbw/bw_hwmon/hyst_length + echo 80 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 40 > $llccbw/polling_interval + done + + for npubw in $device/*npu-npu-ddr-bw/devfreq/*npu-npu-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo "1144 1720 2086 2929 3879 5931 6881" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 10 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac + + ;; +esac + + +case "$target" in + "lito") + + #Apply settings for lito + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + fi + + case "$soc_id" in + "400" | "440" | "476" ) + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + + # Disable Core control on gold, prime + echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + echo 0 > /sys/devices/system/cpu/cpu7/core_ctl/enable + + # Setting b.L scheduler parameters + echo 65 85 > /proc/sys/kernel/sched_downmigrate + echo 71 95 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + echo 0 > /proc/sys/kernel/sched_coloc_busy_hyst_ns + echo 0 > /proc/sys/kernel/sched_coloc_busy_hysteresis_enable_cpus + echo 0 > /proc/sys/kernel/sched_coloc_busy_hyst_max_ms + + # disable unfiltering + echo 20000000 > /proc/sys/kernel/sched_task_unfilter_period + echo 1 > /proc/sys/kernel/sched_task_unfilter_nr_windows + + # configure governor settings for silver cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1228800 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 650000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + + # configure governor settings for gold cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/down_rate_limit_us + echo 1228800 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_freq + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/pl + echo 672000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/rtg_boost_freq + + # configure governor settings for gold+ cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/down_rate_limit_us + echo 1228800 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + echo 85 > /sys/devices/system/cpu/cpu7/cpufreq/schedutil/hispeed_load + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/pl + echo 672000 > /sys/devices/system/cpu/cpufreq/policy7/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/rtg_boost_freq + + # colocation v3 settings + echo 51 > /proc/sys/kernel/sched_min_task_util_for_boost + echo 35 > /proc/sys/kernel/sched_min_task_util_for_colocation + + # Enable conservative pl + echo 1 > /proc/sys/kernel/sched_conservative_pl + + echo "0:1228800" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + if [ `cat /sys/devices/soc0/revision` == "2.0" ]; then + # r2.0 related changes + echo "0:1075200" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 610000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + echo 1075200 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 1152000 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_freq + echo 1401600 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + echo 614400 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 652800 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq + echo 806400 > /sys/devices/system/cpu/cpufreq/policy7/scaling_min_freq + echo 83 > /proc/sys/kernel/sched_asym_cap_sibling_freq_match_pct + fi + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236 16265" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1144 1720 2086 2929 3879 5931 6881 7980" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 68 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 0 > $llccbw/bw_hwmon/hyst_length + echo 80 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 50 > $llccbw/polling_interval + done + + for npubw in $device/*npu*-ddr-bw/devfreq/*npu*-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo "1144 1720 2086 2929 3879 5931 6881 7980" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 10 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + + for npullccbw in $device/*npu*-llcc-bw/devfreq/*npu*-llcc-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npullccbw/governor + echo "2288 4577 7110 9155 12298 14236 16265" > $npullccbw/bw_hwmon/mbps_zones + echo 4 > $npullccbw/bw_hwmon/sample_ms + echo 100 > $npullccbw/bw_hwmon/io_percent + echo 20 > $npullccbw/bw_hwmon/hist_memory + echo 10 > $npullccbw/bw_hwmon/hyst_length + echo 30 > $npullccbw/bw_hwmon/down_thres + echo 0 > $npullccbw/bw_hwmon/guard_band_mbps + echo 250 > $npullccbw/bw_hwmon/up_scale + echo 40 > $npullccbw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + done + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 0 + setprop vendor.dcvs.prop 1 + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac + + #Apply settings for lagoon + case "$soc_id" in + "434" | "459" ) + + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + + # Disable Core control on gold + echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + + + # disable unfiltering + echo 20000000 > /proc/sys/kernel/sched_task_unfilter_period + + # Setting b.L scheduler parameters + # default sched up and down migrate values are 95 and 85 + echo 65 > /proc/sys/kernel/sched_downmigrate + echo 71 > /proc/sys/kernel/sched_upmigrate + + # default sched up and down migrate values are 100 and 95 + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + echo 0 > /proc/sys/kernel/sched_coloc_busy_hyst_ns + echo 0 > /proc/sys/kernel/sched_coloc_busy_hysteresis_enable_cpus + echo 0 > /proc/sys/kernel/sched_coloc_busy_hyst_max_ms + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1248000 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us + echo 1248000 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + echo 652800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + + #colocation v3 settings + echo 740000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq + echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/rtg_boost_freq + echo 51 > /proc/sys/kernel/sched_min_task_util_for_boost + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + + # Enable conservative pl + echo 1 > /proc/sys/kernel/sched_conservative_pl + + echo "0:1248000" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1144 1720 2086 2929 3879 5931 6881 8137" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 68 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 0 > $llccbw/bw_hwmon/hyst_length + echo 80 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 40 > $llccbw/polling_interval + done + + for npubw in $device/*npu*-ddr-bw/devfreq/*npu*-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo "1144 1720 2086 2929 3879 5931 6881 7980" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 10 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + + for npullccbw in $device/*npu*-llcc-bw/devfreq/*npu*-llcc-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npullccbw/governor + echo "2288 4577 7110 9155 12298 14236 16265" > $npullccbw/bw_hwmon/mbps_zones + echo 4 > $npullccbw/bw_hwmon/sample_ms + echo 100 > $npullccbw/bw_hwmon/io_percent + echo 20 > $npullccbw/bw_hwmon/hist_memory + echo 10 > $npullccbw/bw_hwmon/hyst_length + echo 30 > $npullccbw/bw_hwmon/down_thres + echo 0 > $npullccbw/bw_hwmon/guard_band_mbps + echo 250 > $npullccbw/bw_hwmon/up_scale + echo 40 > $npullccbw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + done + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn off sleep modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac +esac + +case "$target" in + "bengal") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + case "$soc_id" in + "417" | "420" | "444" | "445" | "469" | "470" ) + + # Core control is temporarily disabled till bring up + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + # Core control parameters on big + echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 67 > /proc/sys/kernel/sched_downmigrate + echo 77 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1305600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rtg_boost_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + echo 1401600 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + echo 1056000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/rtg_boost_freq + + echo "0:1017600" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 80 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type` + ddr_type4="07" + ddr_type3="05" + + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + if [ ${ddr_type:4:2} == $ddr_type4 ]; then + # LPDDR4 + echo "2288 3440 4173 5195 5859 7759 10322 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 85 > $cpubw/bw_hwmon/io_percent + fi + if [ ${ddr_type:4:2} == $ddr_type3 ]; then + # LPDDR3 + echo "1525 3440 5195 5859 7102" > $cpubw/bw_hwmon/mbps_zones + echo 34 > $cpubw/bw_hwmon/io_percent + fi + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 90 > $cpubw/bw_hwmon/decay_rate + echo 190 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + done + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # colcoation v3 disabled + echo 0 > /proc/sys/kernel/sched_min_task_util_for_boost + echo 0 > /proc/sys/kernel/sched_min_task_util_for_colocation + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + ;; + esac + + #power/perf tunings for khaje + case "$soc_id" in + "518" ) + + # Core control parameters on big + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 40 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 65 > /proc/sys/kernel/sched_downmigrate + echo 71 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + + # cpuset settings + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1516800 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 691200 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rtg_boost_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/down_rate_limit_us + echo 1344000 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + echo 1056000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/rtg_boost_freq + + echo "0:1190000" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 80 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu4/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu5/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_load + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + echo "2288 3440 4173 5195 5859 7759 10322 11863 13763 15960" > $cpubw/bw_hwmon/mbps_zones + echo 85 > $cpubw/bw_hwmon/io_percent + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 90 > $cpubw/bw_hwmon/decay_rate + echo 190 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + done + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # colcoation v3 disabled + echo 0 > /proc/sys/kernel/sched_min_task_util_for_boost + echo 0 > /proc/sys/kernel/sched_min_task_util_for_colocation + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + ;; + esac + + # Scuba perf/power tunings + case "$soc_id" in + "441" | "471" | "473" | "474" ) + + # Quad-core device. disable core_ctl + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + + # Configure schedutil governor settings + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1305600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rtg_boost_freq + + # sched_load_boost as -6 is equivalent to target load as 85. + echo 0 > /proc/sys/kernel/sched_boost + echo -6 > /sys/devices/system/cpu/cpu0/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu1/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu2/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu3/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_load + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type` + ddr_type4="07" + ddr_type3="05" + + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 762 > $cpubw/min_freq + if [ ${ddr_type:4:2} == $ddr_type4 ]; then + # LPDDR4 + echo "2288 3440 4173 5195 5859 7759 10322 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 85 > $cpubw/bw_hwmon/io_percent + fi + if [ ${ddr_type:4:2} == $ddr_type3 ]; then + # LPDDR3 + echo "1525 3440 5195 5859 7102" > $cpubw/bw_hwmon/mbps_zones + echo 34 > $cpubw/bw_hwmon/io_percent + fi + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 90 > $cpubw/bw_hwmon/decay_rate + echo 190 > $cpubw/bw_hwmon/bw_step + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + done + + # Disable low power modes. Enable it after LPM stable + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; + esac + + ;; +esac + + +#Apply settings for atoll +case "$target" in + "atoll") + + # Core control parameters on silver + echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable + + # Setting b.L scheduler parameters + # default sched up and down migrate values are 95 and 85 + echo 65 > /proc/sys/kernel/sched_downmigrate + echo 71 > /proc/sys/kernel/sched_upmigrate + # default sched up and down migrate values are 100 and 95 + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + #colocation v3 settings + echo 740000 > /proc/sys/kernel/sched_little_cluster_coloc_fmin_khz + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us + echo 1248000 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us + echo 1267200 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + echo 652800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + + # sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable. + echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost + echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost + echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load + + echo "0:1248000" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Set Memory parameters + configure_memory_parameters + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 50 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1144 1720 2086 2929 3879 5931 6881 8137" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 68 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 0 > $llccbw/bw_hwmon/hyst_length + echo 80 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 40 > $llccbw/polling_interval + done + + for npubw in $device/*npu*-npu-ddr-bw/devfreq/*npu*-npu-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo "1144 1720 2086 2929 3879 5931 6881 8137" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 10 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + ;; +esac + + +case "$target" in + "qcs605") + + #Apply settings for qcs605 + # Set the default IRQ affinity to the silver cluster. When a + # CPU is isolated/hotplugged, the IRQ affinity is adjusted + # to one of the CPU from the default IRQ affinity mask. + echo 3f > /proc/irq/default_smp_affinity + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + case "$soc_id" in + "347" ) + + # Start Host based Touch processing + case "$hw_platform" in + "Surf" | "RCM" | "QRD" ) + start_hbtp + ;; + "MTP" ) + if [ $platform_subtype_id != 5 ]; then + start_hbtp + fi + ;; + esac + + # Core control parameters on silver + echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres + echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/is_big_cluster + echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 96 > /proc/sys/kernel/sched_upmigrate + echo 90 > /proc/sys/kernel/sched_downmigrate + echo 140 > /proc/sys/kernel/sched_group_upmigrate + echo 120 > /proc/sys/kernel/sched_group_downmigrate + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/rate_limit_us + echo 1344000 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq + echo 825600 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq + + echo "0:1209600" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo "1144 1720 2086 2929 3879 5931 6881" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 68 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 0 > $cpubw/bw_hwmon/hyst_length + echo 80 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/low_power_ceil_mbps + echo 68 > $cpubw/bw_hwmon/low_power_io_percent + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + #Enable mem_latency governor for DDR scaling + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable mem_latency governor for L3 scaling + for memlat in /sys/class/devfreq/*qcom,l3-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor + + # cpuset parameters + echo 0-5 > /dev/cpuset/background/cpus + echo 0-5 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + echo 100 > /proc/sys/vm/swappiness + ;; + esac + ;; +esac + +case "$target" in + "apq8084") + echo 4 > /sys/module/lpm_levels/enable_low_power/l2 + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/retention/idle_enabled + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + for devfreq_gov in /sys/class/devfreq/qcom,cpubw*/governor + do + echo "cpubw_hwmon" > $devfreq_gov + done + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo "interactive" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor + echo "20000 1400000:40000 1700000:20000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 1497600 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo "85 1500000:90 1800000:70" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 20 > /sys/module/cpu_boost/parameters/boost_ms + echo 1728000 > /sys/module/cpu_boost/parameters/sync_threshold + echo 100000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + echo 1497600 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + echo 1 > /dev/cpuctl/apps/cpu.notify_on_migrate + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 1 > /sys/module/msm_thermal/core_control/enabled + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h root.system /sys/devices/system/cpu/mfreq + chmod -h 220 /sys/devices/system/cpu/mfreq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + ;; +esac + +case "$target" in + "mpq8092") + echo 4 > /sys/module/lpm_levels/enable_low_power/l2 + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu0/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu1/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu2/retention/idle_enabled + echo 1 > /sys/module/msm_pm/modes/cpu3/retention/idle_enabled + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo "ondemand" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold + echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 300000 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq + echo 1 > /sys/module/msm_thermal/core_control/enabled + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq + chown -h system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + chown -h root.system /sys/devices/system/cpu/mfreq + chmod -h 220 /sys/devices/system/cpu/mfreq + chown -h root.system /sys/devices/system/cpu/cpu1/online + chown -h root.system /sys/devices/system/cpu/cpu2/online + chown -h root.system /sys/devices/system/cpu/cpu3/online + chmod -h 664 /sys/devices/system/cpu/cpu1/online + chmod -h 664 /sys/devices/system/cpu/cpu2/online + chmod -h 664 /sys/devices/system/cpu/cpu3/online + ;; +esac + +case "$target" in + "msm8992") + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo -n disable > /sys/devices/soc.*/qcom,bcl.*/mode + bcl_hotplug_mask=`cat /sys/devices/soc.*/qcom,bcl.*/hotplug_mask` + echo 0 > /sys/devices/soc.*/qcom,bcl.*/hotplug_mask + echo -n enable > /sys/devices/soc.*/qcom,bcl.*/mode + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + # configure governor settings for little cluster + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 80000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 384000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + # online CPU4 + echo 1 > /sys/devices/system/cpu/cpu4/online + # configure governor settings for big cluster + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 1536000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo 85 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 80000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + echo 384000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + echo -n disable > /sys/devices/soc.*/qcom,bcl.*/mode + echo $bcl_hotplug_mask > /sys/devices/soc.*/qcom,bcl.*/hotplug_mask + echo $bcl_soc_hotplug_mask > /sys/devices/soc.*/qcom,bcl.*/hotplug_soc_mask + echo -n enable > /sys/devices/soc.*/qcom,bcl.*/mode + # plugin remaining A57s + echo 1 > /sys/devices/system/cpu/cpu5/online + # input boost configuration + echo 0:1248000 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + # Enable task migration fixups in the scheduler + echo 1 > /proc/sys/kernel/sched_migration_fixup + for devfreq_gov in /sys/class/devfreq/qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + done + #enable rps static configuration + echo 8 > /sys/class/net/rmnet_ipa0/queues/rx-0/rps_cpus + echo 30 > /proc/sys/kernel/sched_small_task + ;; +esac + +case "$target" in + "msm8994") + # ensure at most one A57 is online when thermal hotplug is disabled + echo 0 > /sys/devices/system/cpu/cpu5/online + echo 0 > /sys/devices/system/cpu/cpu6/online + echo 0 > /sys/devices/system/cpu/cpu7/online + # in case CPU4 is online, limit its frequency + echo 960000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + # Limit A57 max freq from msm_perf module in case CPU 4 is offline + echo "4:960000 5:960000 6:960000 7:960000" > /sys/module/msm_performance/parameters/cpu_max_freq + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + bcl_hotplug_mask=`cat $hotplug_mask` + echo 0 > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + bcl_soc_hotplug_mask=`cat $hotplug_soc_mask` + echo 0 > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + # configure governor settings for little cluster + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 80000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 384000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + # online CPU4 + echo 1 > /sys/devices/system/cpu/cpu4/online + # Best effort limiting for first time boot if msm_performance module is absent + echo 960000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + # configure governor settings for big cluster + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo "19000 1400000:39000 1700000:19000" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 1248000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "85 1500000:90 1800000:70" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 40000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 80000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + echo 384000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + # restore A57's max + cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_max_freq > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n disable > $mode + done + for hotplug_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_mask + do + echo $bcl_hotplug_mask > $hotplug_mask + done + for hotplug_soc_mask in /sys/devices/soc.0/qcom,bcl.*/hotplug_soc_mask + do + echo $bcl_soc_hotplug_mask > $hotplug_soc_mask + done + for mode in /sys/devices/soc.0/qcom,bcl.*/mode + do + echo -n enable > $mode + done + # plugin remaining A57s + echo 1 > /sys/devices/system/cpu/cpu5/online + echo 1 > /sys/devices/system/cpu/cpu6/online + echo 1 > /sys/devices/system/cpu/cpu7/online + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + # Restore CPU 4 max freq from msm_performance + echo "4:4294967295 5:4294967295 6:4294967295 7:4294967295" > /sys/module/msm_performance/parameters/cpu_max_freq + # input boost configuration + echo 0:1344000 > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + # Setting b.L scheduler parameters + echo 1 > /proc/sys/kernel/sched_migration_fixup + echo 30 > /proc/sys/kernel/sched_small_task + echo 20 > /proc/sys/kernel/sched_mostly_idle_load + echo 3 > /proc/sys/kernel/sched_mostly_idle_nr_run + echo 99 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_downmigrate + echo 400000 > /proc/sys/kernel/sched_freq_inc_notify + echo 400000 > /proc/sys/kernel/sched_freq_dec_notify + #enable rps static configuration + echo 8 > /sys/class/net/rmnet_ipa0/queues/rx-0/rps_cpus + for devfreq_gov in /sys/class/devfreq/qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + done + ;; +esac + +case "$target" in + "msm8996") + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo -n disable > /sys/devices/soc/soc:qcom,bcl/mode + bcl_hotplug_mask=`cat /sys/devices/soc/soc:qcom,bcl/hotplug_mask` + echo 0 > /sys/devices/soc/soc:qcom,bcl/hotplug_mask + bcl_soc_hotplug_mask=`cat /sys/devices/soc/soc:qcom,bcl/hotplug_soc_mask` + echo 0 > /sys/devices/soc/soc:qcom,bcl/hotplug_soc_mask + echo -n enable > /sys/devices/soc/soc:qcom,bcl/mode + # set sync wakee policy tunable + echo 1 > /proc/sys/kernel/sched_prefer_sync_wakee_to_waker + # configure governor settings for little cluster + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 960000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo 80 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 79000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 300000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/ignore_hispeed_on_notif + # online CPU2 + echo 1 > /sys/devices/system/cpu/cpu2/online + # configure governor settings for big cluster + echo "interactive" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/use_migration_notif + echo "19000 1400000:39000 1700000:19000 2100000:79000" > /sys/devices/system/cpu/cpu2/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/timer_rate + echo 1248000 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/io_is_busy + echo "85 1500000:90 1800000:70 2100000:95" > /sys/devices/system/cpu/cpu2/cpufreq/interactive/target_loads + echo 19000 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/min_sample_time + echo 79000 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/max_freq_hysteresis + echo 300000 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu2/cpufreq/interactive/ignore_hispeed_on_notif + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + echo -n disable > /sys/devices/soc/soc:qcom,bcl/mode + echo $bcl_hotplug_mask > /sys/devices/soc/soc:qcom,bcl/hotplug_mask + echo $bcl_soc_hotplug_mask > /sys/devices/soc/soc:qcom,bcl/hotplug_soc_mask + echo -n enable > /sys/devices/soc/soc:qcom,bcl/mode + # input boost configuration + echo "0:1324800 2:1324800" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + # Setting b.L scheduler parameters + echo 0 > /proc/sys/kernel/sched_boost + echo 1 > /proc/sys/kernel/sched_migration_fixup + echo 45 > /proc/sys/kernel/sched_downmigrate + echo 45 > /proc/sys/kernel/sched_upmigrate + echo 400000 > /proc/sys/kernel/sched_freq_inc_notify + echo 400000 > /proc/sys/kernel/sched_freq_dec_notify + echo 3 > /proc/sys/kernel/sched_spill_nr_run + echo 100 > /proc/sys/kernel/sched_init_task_load + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 1525 > $cpubw/min_freq + echo "1525 5195 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 34 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 0 > $cpubw/bw_hwmon/low_power_ceil_mbps + echo 34 > $cpubw/bw_hwmon/low_power_io_percent + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + done + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor + + soc_revision=`cat /sys/devices/soc0/revision` + if [ "$soc_revision" == "2.0" ]; then + #Disable suspend for v2.0 + echo pwr_dbg > /sys/power/wake_lock + elif [ "$soc_revision" == "2.1" ]; then + # Enable C4.D4.E4.M3 LPM modes + # Disable D3 state + echo 0 > /sys/module/lpm_levels/system/pwr/pwr-l2-gdhs/idle_enabled + echo 0 > /sys/module/lpm_levels/system/perf/perf-l2-gdhs/idle_enabled + # Disable DEF-FPC mode + echo N > /sys/module/lpm_levels/system/pwr/cpu0/fpc-def/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu1/fpc-def/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu2/fpc-def/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu3/fpc-def/idle_enabled + else + # Enable all LPMs by default + # This will enable C4, D4, D3, E4 and M3 LPMs + echo N > /sys/module/lpm_levels/parameters/sleep_disabled + fi + echo N > /sys/module/lpm_levels/parameters/sleep_disabled + # Starting io prefetcher service + start iop + + # Set Memory parameters + configure_memory_parameters + ;; +esac + +case "$target" in + "sdm845") + + # Set the default IRQ affinity to the silver cluster. When a + # CPU is isolated/hotplugged, the IRQ affinity is adjusted + # to one of the CPU from the default IRQ affinity mask. + echo f > /proc/irq/default_smp_affinity + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + case "$soc_id" in + "321" | "341") + # Start Host based Touch processing + case "$hw_platform" in + "QRD" ) + case "$platform_subtype_id" in + "32") #QVR845 do nothing + ;; + *) + start_hbtp + ;; + esac + ;; + *) + start_hbtp + ;; + esac + ;; + esac + # Core control parameters + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/is_big_cluster + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 95 > /proc/sys/kernel/sched_upmigrate + echo 85 > /proc/sys/kernel/sched_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 95 > /proc/sys/kernel/sched_group_downmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # configure governor settings for little cluster + echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/pl + echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + + # configure governor settings for big cluster + echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 0 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/rate_limit_us + echo 1574400 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/schedutil/pl + echo "0:1324800" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 120 > /sys/module/cpu_boost/parameters/input_boost_ms + # Limit the min frequency to 825MHz + echo 825000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + + # Enable oom_reaper + echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper + + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo "2288 4577 6500 8132 9155 10681" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 50 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + for llccbw in /sys/class/devfreq/*qcom,llccbw* + do + echo "bw_hwmon" > $llccbw/governor + echo 50 > $llccbw/polling_interval + echo "1720 2929 3879 5931 6881" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 80 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 10 > $llccbw/bw_hwmon/hyst_length + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + done + + #Enable mem_latency governor for DDR scaling + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable mem_latency governor for L3 scaling + for memlat in /sys/class/devfreq/*qcom,l3-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable userspace governor for L3 cdsp nodes + for l3cdsp in /sys/class/devfreq/*qcom,l3-cdsp* + do + echo "userspace" > $l3cdsp/governor + chown -h system $l3cdsp/userspace/set_freq + done + + #Gold L3 ratio ceil + echo 4000 > /sys/class/devfreq/soc:qcom,l3-cpu4/mem_latency/ratio_ceil + + echo "compute" > /sys/class/devfreq/soc:qcom,mincpubw/governor + echo 10 > /sys/class/devfreq/soc:qcom,mincpubw/polling_interval + + # cpuset parameters + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + # Disable CPU Retention + echo N > /sys/module/lpm_levels/L3/cpu0/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu1/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu2/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu3/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu4/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu5/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu6/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/cpu7/ret/idle_enabled + echo N > /sys/module/lpm_levels/L3/l3-dyn-ret/idle_enabled + # Turn on sleep modes. + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + echo 100 > /proc/sys/vm/swappiness + echo 120 > /proc/sys/vm/watermark_scale_factor + ;; +esac + +case "$target" in + "msmnile") + # cpuset parameters + target_varient=`getprop ro.build.product` + if [ "$target_varient" == "msmnile_gvmq" ]; then + echo 4-7 > /dev/cpuset/background/cpus + echo 4-7 > /dev/cpuset/system-background/cpus + + # Enable oom_reaper + if [ -f /sys/module/lowmemorykiller/parameters/oom_reaper ]; then + echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper + else + echo 1 > /proc/sys/vm/reap_mem_on_sigkill + fi + # Disable wsf, beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + + # Disable wsf, beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + # Enable oom_reaper + echo 1 > /proc/sys/vm/reap_mem_on_sigkill + + else + # Core control parameters for gold + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 3 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Core control parameters for gold+ + echo 0 > /sys/devices/system/cpu/cpu7/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu7/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu7/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu7/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/task_thres + # Controls how many more tasks should be eligible to run on gold CPUs + # w.r.t number of gold CPUs available to trigger assist (max number of + # tasks eligible to run on previous cluster minus number of CPUs in + # the previous cluster). + # + # Setting to 1 by default which means there should be at least + # 4 tasks eligible to run on gold cluster (tasks running on gold cores + # plus misfit tasks on silver cores) to trigger assitance from gold+. + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/nr_prev_assist_thresh + + # Disable Core control on silver + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + + # Setting b.L scheduler parameters + echo 95 95 > /proc/sys/kernel/sched_upmigrate + echo 85 85 > /proc/sys/kernel/sched_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 10 > /proc/sys/kernel/sched_group_downmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # configure governor settings for silver cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + + # configure governor settings for gold cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1612800 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + + # configure governor settings for gold+ cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1612800 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/pl + + # configure input boost settings + echo "0:1324800" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 120 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Disable wsf, beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + + # Enable oom_reaper + if [ -f /sys/module/lowmemorykiller/parameters/oom_reaper ]; then + echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper + else + echo 1 > /proc/sys/vm/reap_mem_on_sigkill + fi + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "2288 4577 7110 9155 12298 14236 15258" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 50 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 30 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 14236 > $cpubw/max_freq + echo 40 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo "1720 2929 3879 5931 6881 7980" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 80 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 10 > $llccbw/bw_hwmon/hyst_length + echo 30 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 6881 > $llccbw/max_freq + echo 40 > $llccbw/polling_interval + done + + for npubw in $device/*npu-npu-ddr-bw/devfreq/*npu-npu-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo "1720 2929 3879 5931 6881 7980" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 6 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + done + + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 1 + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + case "$hw_platform" in + "MTP" | "Surf" | "RCM" ) + # Start Host based Touch processing + case "$platform_subtype_id" in + "0" | "1" | "2" | "3" | "4") + start_hbtp + ;; + esac + ;; + "HDK" ) + if [ -d /sys/kernel/hbtpsensor ] ; then + start_hbtp + fi + ;; + esac + + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + configure_memory_parameters + target_type=`getprop ro.hardware.type` + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + if [ "$target_type" == "automotive" ]; then + # update frequencies + if [ "$soc_id" == "340" ] | [ "$soc_id" == "405" ]; then #sa8195 + configure_automotive_sku_parameters_sa8195 + else #sa8155 + configure_automotive_sku_parameters + fi + fi + fi + ;; +esac + +case "$target" in + "sdmshrike") + # Core control parameters for gold + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 3 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Core control parameters for gold+ + echo 0 > /sys/devices/system/cpu/cpu7/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu7/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu7/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu7/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/task_thres + # Controls how many more tasks should be eligible to run on gold CPUs + # w.r.t number of gold CPUs available to trigger assist (max number of + # tasks eligible to run on previous cluster minus number of CPUs in + # the previous cluster). + # + # Setting to 1 by default which means there should be at least + # 4 tasks eligible to run on gold cluster (tasks running on gold cores + # plus misfit tasks on silver cores) to trigger assitance from gold+. + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/nr_prev_assist_thresh + + # Disable Core control on silver + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + + # Setting b.L scheduler parameters + echo 95 95 > /proc/sys/kernel/sched_upmigrate + echo 85 85 > /proc/sys/kernel/sched_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 10 > /proc/sys/kernel/sched_group_downmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + + # cpuset parameters + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # configure governor settings for silver cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 1209600 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + + # configure governor settings for gold cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/down_rate_limit_us + echo 1612800 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + + # configure governor settings for gold+ cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/up_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/down_rate_limit_us + echo 1612800 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/pl + + # configure input boost settings + echo "0:1324800" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 120 > /sys/module/cpu_boost/parameters/input_boost_ms + + # Disable wsf, beacause we are using efk. + # wsf Range : 1..1000 So set to bare minimum value 1. + echo 1 > /proc/sys/vm/watermark_scale_factor + + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + # Enable oom_reaper + if [ -f /sys/module/lowmemorykiller/parameters/oom_reaper ]; then + echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper + else + echo 1 > /proc/sys/vm/reap_mem_on_sigkill + fi + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo 40 > $cpubw/polling_interval + echo "2288 4577 7110 9155 12298 14236 15258" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 50 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 30 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 14236 > $cpubw/max_freq + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + echo 40 > $llccbw/polling_interval + echo "1720 2929 3879 5931 6881 7980" > $llccbw/bw_hwmon/mbps_zones + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 80 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 10 > $llccbw/bw_hwmon/hyst_length + echo 30 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 6881 > $llccbw/max_freq + done + + for npubw in $device/*npu-npu-ddr-bw/devfreq/*npu-npu-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + echo 40 > $npubw/polling_interval + echo "1720 2929 3879 5931 6881 7980" > $npubw/bw_hwmon/mbps_zones + echo 4 > $npubw/bw_hwmon/sample_ms + echo 80 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 6 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 0 > $npubw/bw_hwmon/idle_mbps + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + + #Enable mem_latency governor for L3, LLCC, and DDR scaling + for memlat in $device/*cpu*-lat/devfreq/*cpu*-lat + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + + #Enable userspace governor for L3 cdsp nodes + for l3cdsp in $device/*cdsp-cdsp-l3-lat/devfreq/*cdsp-cdsp-l3-lat + do + echo "cdspl3" > $l3cdsp/governor + done + + #Enable compute governor for gold latfloor + for latfloor in $device/*cpu-ddr-latfloor*/devfreq/*cpu-ddr-latfloor* + do + echo "compute" > $latfloor/governor + echo 10 > $latfloor/polling_interval + done + + #Gold L3 ratio ceil + for l3gold in $device/*cpu4-cpu-l3-lat/devfreq/*cpu4-cpu-l3-lat + do + echo 4000 > $l3gold/mem_latency/ratio_ceil + done + + #Prime L3 ratio ceil + for l3prime in $device/*cpu7-cpu-l3-lat/devfreq/*cpu7-cpu-l3-lat + do + echo 20000 > $l3prime/mem_latency/ratio_ceil + done + done + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + case "$hw_platform" in + "MTP" | "Surf" | "RCM" ) + # Start Host based Touch processing + case "$platform_subtype_id" in + "0" | "1") + start_hbtp + ;; + esac + ;; + "HDK" ) + if [ -d /sys/kernel/hbtpsensor ] ; then + start_hbtp + fi + ;; + esac + + #Setting the min and max supported frequencies + reg_val=`cat /sys/devices/platform/soc/780130.qfprom/qfprom0/nvmem | od -An -t d4` + feature_id=$(((reg_val >> 20) & 0xFF)) + + #Setting the min supported frequencies + echo 1113600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1171200 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/min_freq + echo 940800000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/min_freq + echo 1651200000 > /sys/class/devfreq/soc\:qcom,cpu0-cpu-l3-lat/max_freq + echo 1651200000 > /sys/class/devfreq/soc\:qcom,cpu4-cpu-l3-lat/max_freq + #setting min gpu freq to 392 MHz + echo 4 > /sys/class/kgsl/kgsl-3d0/min_pwrlevel + if [ $feature_id == 0 ]; then + echo "feature_id is 0 for SA8195AA" + + #setting max cpu freq to 2.496GHz + echo 2496000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + #setting max gpu freq to 530 MHz + echo 3 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 1804 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + elif [ $feature_id == 1 ] || [ $feature_id == 2 ]; then + echo "feature_id is 1 for external SA8195AB" + echo "feature_id is 2 for internal SA8195AB" + + #setting max cpu freq to 2.496GHz + echo 2496000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq + #setting max gpu freq to 670 MHz + echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel + echo 2092 > /sys/devices/platform/soc/soc:aop-set-ddr-freq/set_ddr_capped_freq + elif [ $feature_id == 3 ]; then + echo "feature_id is 3 for external SA8195AC" + else + echo "unknown feature_id value" $feature_id + fi + + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + configure_memory_parameters + ;; +esac + +case "$target" in + "kona") + rev=`cat /sys/devices/soc0/revision` + ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type` + ddr_type4="07" + ddr_type5="08" + + # Core control parameters for gold + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 3 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Core control parameters for gold+ + echo 0 > /sys/devices/system/cpu/cpu7/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu7/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu7/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu7/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/task_thres + # Controls how many more tasks should be eligible to run on gold CPUs + # w.r.t number of gold CPUs available to trigger assist (max number of + # tasks eligible to run on previous cluster minus number of CPUs in + # the previous cluster). + # + # Setting to 1 by default which means there should be at least + # 4 tasks eligible to run on gold cluster (tasks running on gold cores + # plus misfit tasks on silver cores) to trigger assitance from gold+. + echo 1 > /sys/devices/system/cpu/cpu7/core_ctl/nr_prev_assist_thresh + + # Disable Core control on silver + echo 0 > /sys/devices/system/cpu/cpu0/core_ctl/enable + + # Setting b.L scheduler parameters + echo 95 95 > /proc/sys/kernel/sched_upmigrate + echo 85 85 > /proc/sys/kernel/sched_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 85 > /proc/sys/kernel/sched_group_downmigrate + echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks + echo 400000000 > /proc/sys/kernel/sched_coloc_downmigrate_ns + + # cpuset parameters + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + + # Turn off scheduler boost at the end + echo 0 > /proc/sys/kernel/sched_boost + + # configure governor settings for silver cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us + if [ $rev == "2.0" ] || [ $rev == "2.1" ]; then + echo 1248000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + else + echo 1228800 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq + fi + echo 691200 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/pl + + # configure input boost settings + echo "0:1324800" > /sys/devices/system/cpu/cpu_boost/input_boost_freq + echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms + + # configure governor settings for gold cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/down_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/up_rate_limit_us + echo 1574400 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpufreq/policy4/schedutil/pl + + # configure governor settings for gold+ cluster + echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/down_rate_limit_us + echo 0 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/up_rate_limit_us + if [ $rev == "2.0" ] || [ $rev == "2.1" ]; then + echo 1632000 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + else + echo 1612800 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/hispeed_freq + fi + echo 1 > /sys/devices/system/cpu/cpufreq/policy7/schedutil/pl + + # Enable bus-dcvs + for device in /sys/devices/platform/soc + do + for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw + do + echo "bw_hwmon" > $cpubw/governor + echo "4577 7110 9155 12298 14236 15258" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 50 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 30 > $cpubw/bw_hwmon/down_thres + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + echo 14236 > $cpubw/max_freq + echo 40 > $cpubw/polling_interval + done + + for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw + do + echo "bw_hwmon" > $llccbw/governor + if [ ${ddr_type:4:2} == $ddr_type4 ]; then + echo "1720 2086 2929 3879 5161 5931 6881 7980" > $llccbw/bw_hwmon/mbps_zones + elif [ ${ddr_type:4:2} == $ddr_type5 ]; then + echo "1720 2086 2929 3879 5931 6881 7980 10437" > $llccbw/bw_hwmon/mbps_zones + fi + echo 4 > $llccbw/bw_hwmon/sample_ms + echo 80 > $llccbw/bw_hwmon/io_percent + echo 20 > $llccbw/bw_hwmon/hist_memory + echo 10 > $llccbw/bw_hwmon/hyst_length + echo 30 > $llccbw/bw_hwmon/down_thres + echo 0 > $llccbw/bw_hwmon/guard_band_mbps + echo 250 > $llccbw/bw_hwmon/up_scale + echo 1600 > $llccbw/bw_hwmon/idle_mbps + echo 6881 > $llccbw/max_freq + echo 40 > $llccbw/polling_interval + done + + for npubw in $device/*npu*-ddr-bw/devfreq/*npu*-ddr-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npubw/governor + if [ ${ddr_type:4:2} == $ddr_type4 ]; then + echo "1720 2086 2929 3879 5931 6881 7980" > $npubw/bw_hwmon/mbps_zones + elif [ ${ddr_type:4:2} == $ddr_type5 ]; then + echo "1720 2086 2929 3879 5931 6881 7980 10437" > $npubw/bw_hwmon/mbps_zones + fi + echo 4 > $npubw/bw_hwmon/sample_ms + echo 160 > $npubw/bw_hwmon/io_percent + echo 20 > $npubw/bw_hwmon/hist_memory + echo 10 > $npubw/bw_hwmon/hyst_length + echo 30 > $npubw/bw_hwmon/down_thres + echo 0 > $npubw/bw_hwmon/guard_band_mbps + echo 250 > $npubw/bw_hwmon/up_scale + echo 1600 > $npubw/bw_hwmon/idle_mbps + echo 40 > $npubw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + + for npullccbw in $device/*npu*-llcc-bw/devfreq/*npu*-llcc-bw + do + echo 1 > /sys/devices/virtual/npu/msm_npu/pwr + echo "bw_hwmon" > $npullccbw/governor + echo "4577 7110 9155 12298 14236 15258" > $npullccbw/bw_hwmon/mbps_zones + echo 4 > $npullccbw/bw_hwmon/sample_ms + echo 160 > $npullccbw/bw_hwmon/io_percent + echo 20 > $npullccbw/bw_hwmon/hist_memory + echo 10 > $npullccbw/bw_hwmon/hyst_length + echo 30 > $npullccbw/bw_hwmon/down_thres + echo 0 > $npullccbw/bw_hwmon/guard_band_mbps + echo 250 > $npullccbw/bw_hwmon/up_scale + echo 1600 > $npullccbw/bw_hwmon/idle_mbps + echo 40 > $npullccbw/polling_interval + echo 0 > /sys/devices/virtual/npu/msm_npu/pwr + done + done + # memlat specific settings are moved to seperate file under + # device/target specific folder + setprop vendor.dcvs.prop 0 + setprop vendor.dcvs.prop 1 + echo N > /sys/module/lpm_levels/parameters/sleep_disabled + configure_memory_parameters + ;; +esac + +case "$target" in + "msm8998" | "apq8098_latv") + + echo 2 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus + echo 60 > /sys/devices/system/cpu/cpu4/core_ctl/busy_up_thres + echo 30 > /sys/devices/system/cpu/cpu4/core_ctl/busy_down_thres + echo 100 > /sys/devices/system/cpu/cpu4/core_ctl/offline_delay_ms + echo 1 > /sys/devices/system/cpu/cpu4/core_ctl/is_big_cluster + echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/task_thres + + # Setting b.L scheduler parameters + echo 1 > /proc/sys/kernel/sched_migration_fixup + echo 95 > /proc/sys/kernel/sched_upmigrate + echo 90 > /proc/sys/kernel/sched_downmigrate + echo 100 > /proc/sys/kernel/sched_group_upmigrate + echo 95 > /proc/sys/kernel/sched_group_downmigrate + echo 0 > /proc/sys/kernel/sched_select_prev_cpu_us + echo 400000 > /proc/sys/kernel/sched_freq_inc_notify + echo 400000 > /proc/sys/kernel/sched_freq_dec_notify + echo 5 > /proc/sys/kernel/sched_spill_nr_run + echo 1 > /proc/sys/kernel/sched_restrict_cluster_spill + echo 1 > /proc/sys/kernel/sched_prefer_sync_wakee_to_waker + start iop + + # disable thermal bcl hotplug to switch governor + echo 0 > /sys/module/msm_thermal/core_control/enabled + + # online CPU0 + echo 1 > /sys/devices/system/cpu/cpu0/online + # configure governor settings for little cluster + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/timer_rate + echo 1248000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/io_is_busy + echo "83 1804800:95" > /sys/devices/system/cpu/cpu0/cpufreq/interactive/target_loads + echo 19000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/min_sample_time + echo 79000 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/max_freq_hysteresis + echo 518400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/interactive/ignore_hispeed_on_notif + # online CPU4 + echo 1 > /sys/devices/system/cpu/cpu4/online + # configure governor settings for big cluster + echo "interactive" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_sched_load + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/use_migration_notif + echo 19000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/go_hispeed_load + echo 20000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/timer_rate + echo 1574400 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/hispeed_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/io_is_busy + echo "83 1939200:90 2016000:95" > /sys/devices/system/cpu/cpu4/cpufreq/interactive/target_loads + echo 19000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/min_sample_time + echo 79000 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/max_freq_hysteresis + echo 806400 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq + echo 1 > /sys/devices/system/cpu/cpu4/cpufreq/interactive/ignore_hispeed_on_notif + + # re-enable thermal and BCL hotplug + echo 1 > /sys/module/msm_thermal/core_control/enabled + + # Enable input boost configuration + echo "0:1324800" > /sys/module/cpu_boost/parameters/input_boost_freq + echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms + # Enable bus-dcvs + for cpubw in /sys/class/devfreq/*qcom,cpubw* + do + echo "bw_hwmon" > $cpubw/governor + echo 50 > $cpubw/polling_interval + echo 1525 > $cpubw/min_freq + echo "3143 5859 11863 13763" > $cpubw/bw_hwmon/mbps_zones + echo 4 > $cpubw/bw_hwmon/sample_ms + echo 34 > $cpubw/bw_hwmon/io_percent + echo 20 > $cpubw/bw_hwmon/hist_memory + echo 10 > $cpubw/bw_hwmon/hyst_length + echo 0 > $cpubw/bw_hwmon/low_power_ceil_mbps + echo 34 > $cpubw/bw_hwmon/low_power_io_percent + echo 20 > $cpubw/bw_hwmon/low_power_delay + echo 0 > $cpubw/bw_hwmon/guard_band_mbps + echo 250 > $cpubw/bw_hwmon/up_scale + echo 1600 > $cpubw/bw_hwmon/idle_mbps + done + + for memlat in /sys/class/devfreq/*qcom,memlat-cpu* + do + echo "mem_latency" > $memlat/governor + echo 10 > $memlat/polling_interval + echo 400 > $memlat/mem_latency/ratio_ceil + done + echo "cpufreq" > /sys/class/devfreq/soc:qcom,mincpubw/governor + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + if [ -f /sys/devices/soc0/platform_version ]; then + platform_version=`cat /sys/devices/soc0/platform_version` + platform_major_version=$((10#${platform_version}>>16)) + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + + case "$soc_id" in + "292") #msm8998 apq8098_latv + # Start Host based Touch processing + case "$hw_platform" in + "QRD") + case "$platform_subtype_id" in + "0") + start_hbtp + ;; + "16") + if [ $platform_major_version -lt 6 ]; then + start_hbtp + fi + ;; + esac + + ;; + esac + ;; + esac + + echo N > /sys/module/lpm_levels/system/pwr/cpu0/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu1/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu2/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/cpu3/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu4/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu5/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu6/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/cpu7/ret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-dynret/idle_enabled + echo N > /sys/module/lpm_levels/system/pwr/pwr-l2-ret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-dynret/idle_enabled + echo N > /sys/module/lpm_levels/system/perf/perf-l2-ret/idle_enabled + echo N > /sys/module/lpm_levels/parameters/sleep_disabled + + echo 0-3 > /dev/cpuset/background/cpus + echo 0-3 > /dev/cpuset/system-background/cpus + echo 0 > /proc/sys/kernel/sched_boost + + # Set Memory parameters + configure_memory_parameters + ;; +esac + +case "$target" in + "msm8909") + + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + # HMP scheduler settings for 8909 similiar to 8917 + echo 3 > /proc/sys/kernel/sched_window_stats_policy + echo 3 > /proc/sys/kernel/sched_ravg_hist_size + + echo 1 > /proc/sys/kernel/sched_restrict_tasks_spread + + echo 20 > /proc/sys/kernel/sched_small_task + echo 30 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_load + echo 30 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_load + + echo 3 > /sys/devices/system/cpu/cpu0/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu1/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu2/sched_mostly_idle_nr_run + echo 3 > /sys/devices/system/cpu/cpu3/sched_mostly_idle_nr_run + + echo 0 > /sys/devices/system/cpu/cpu0/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu1/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu2/sched_prefer_idle + echo 0 > /sys/devices/system/cpu/cpu3/sched_prefer_idle + + # Apply governor settings for 8909 + + # disable thermal core_control to update scaling_min_freq + echo 0 > /sys/module/msm_thermal/core_control/enabled + echo 1 > /sys/devices/system/cpu/cpu0/online + echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + echo 800000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq + # enable thermal core_control now + echo 1 > /sys/module/msm_thermal/core_control/enabled + + echo "29000 1094400:49000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay + echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load + echo 30000 > /sys/devices/system/cpu/cpufreq/interactive/timer_rate + echo 998400 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq + echo 0 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy + echo "1 800000:85 998400:90 1094400:80" > /sys/devices/system/cpu/cpufreq/interactive/target_loads + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time + echo 50000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor + + # Bring up all cores online + echo 1 > /sys/devices/system/cpu/cpu1/online + echo 1 > /sys/devices/system/cpu/cpu2/online + echo 1 > /sys/devices/system/cpu/cpu3/online + echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled + + for devfreq_gov in /sys/class/devfreq/*qcom,cpubw*/governor + do + echo "bw_hwmon" > $devfreq_gov + for cpu_bimc_bw_step in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/bw_step + do + echo 60 > $cpu_bimc_bw_step + done + for cpu_guard_band_mbps in /sys/class/devfreq/*qcom,cpubw*/bw_hwmon/guard_band_mbps + do + echo 30 > $cpu_guard_band_mbps + done + done + + for gpu_bimc_io_percent in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/io_percent + do + echo 40 > $gpu_bimc_io_percent + done + for gpu_bimc_bw_step in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/bw_step + do + echo 60 > $gpu_bimc_bw_step + done + for gpu_bimc_guard_band_mbps in /sys/class/devfreq/*qcom,gpubw*/bw_hwmon/guard_band_mbps + do + echo 30 > $gpu_bimc_guard_band_mbps + done + + # Set Memory parameters + configure_memory_parameters + restorecon -R /sys/devices/system/cpu + ;; +esac + +case "$target" in + "msm7627_ffa" | "msm7627_surf" | "msm7627_6x") + echo 25000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + ;; +esac + +case "$target" in + "qsd8250_surf" | "qsd8250_ffa" | "qsd8650a_st1x") + echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + ;; +esac + +case "$target" in + "qsd8650a_st1x") + mount -t debugfs none /sys/kernel/debug + ;; +esac + +chown -h system /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate +chown -h system /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor +chown -h system /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy + +emmc_boot=`getprop vendor.boot.emmc` +case "$emmc_boot" + in "true") + chown -h system /sys/devices/platform/rs300000a7.65536/force_sync + chown -h system /sys/devices/platform/rs300000a7.65536/sync_sts + chown -h system /sys/devices/platform/rs300100a7.65536/force_sync + chown -h system /sys/devices/platform/rs300100a7.65536/sync_sts + ;; +esac + +case "$target" in + "msm8960" | "msm8660" | "msm7630_surf") + echo 10 > /sys/devices/platform/msm_sdcc.3/idle_timeout + ;; + "msm7627a") + echo 10 > /sys/devices/platform/msm_sdcc.1/idle_timeout + ;; +esac + +# Post-setup services +case "$target" in + "msm8660" | "msm8960" | "msm8226" | "msm8610" | "mpq8092" ) + start mpdecision + ;; + "msm8974") + start mpdecision + echo 512 > /sys/block/mmcblk0/bdi/read_ahead_kb + ;; + "msm8909" | "msm8916" | "msm8937" | "msm8952" | "msm8953" | "msm8994" | "msm8992" | "msm8996" | "msm8998" | "sdm660" | "apq8098_latv" | "sdm845" | "sdm710" | "msmnile" | "msmsteppe" | "sm6150" | "kona" | "lito" | "trinket" | "atoll" | "bengal" | "sdmshrike") + setprop vendor.post_boot.parsed 1 + ;; + "apq8084") + rm /data/system/perfd/default_values + start mpdecision + echo 512 > /sys/block/mmcblk0/bdi/read_ahead_kb + echo 512 > /sys/block/sda/bdi/read_ahead_kb + echo 512 > /sys/block/sdb/bdi/read_ahead_kb + echo 512 > /sys/block/sdc/bdi/read_ahead_kb + echo 512 > /sys/block/sdd/bdi/read_ahead_kb + echo 512 > /sys/block/sde/bdi/read_ahead_kb + echo 512 > /sys/block/sdf/bdi/read_ahead_kb + echo 512 > /sys/block/sdg/bdi/read_ahead_kb + echo 512 > /sys/block/sdh/bdi/read_ahead_kb + ;; + "msm7627a") + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + case "$soc_id" in + "127" | "128" | "129") + start mpdecision + ;; + esac + ;; +esac + +# Enable Power modes and set the CPU Freq Sampling rates +case "$target" in + "msm7627a") + start qosmgrd + echo 1 > /sys/module/pm2/modes/cpu0/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/pm2/modes/cpu1/standalone_power_collapse/idle_enabled + echo 1 > /sys/module/pm2/modes/cpu0/standalone_power_collapse/suspend_enabled + echo 1 > /sys/module/pm2/modes/cpu1/standalone_power_collapse/suspend_enabled + #SuspendPC: + echo 1 > /sys/module/pm2/modes/cpu0/power_collapse/suspend_enabled + #IdlePC: + echo 1 > /sys/module/pm2/modes/cpu0/power_collapse/idle_enabled + echo 25000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate + ;; +esac + +# Change adj level and min_free_kbytes setting for lowmemory killer to kick in +case "$target" in + "msm7627a") + echo 0,1,2,4,9,12 > /sys/module/lowmemorykiller/parameters/adj + echo 5120 > /proc/sys/vm/min_free_kbytes + ;; +esac + +# Install AdrenoTest.apk if not already installed +if [ -f /data/prebuilt/AdrenoTest.apk ]; then + if [ ! -d /data/data/com.qualcomm.adrenotest ]; then + pm install /data/prebuilt/AdrenoTest.apk + fi +fi + +# Install SWE_Browser.apk if not already installed +if [ -f /data/prebuilt/SWE_AndroidBrowser.apk ]; then + if [ ! -d /data/data/com.android.swe.browser ]; then + pm install /data/prebuilt/SWE_AndroidBrowser.apk + fi +fi + +# Change adj level and min_free_kbytes setting for lowmemory killer to kick in +case "$target" in + "msm8660") + start qosmgrd + echo 0,1,2,4,9,12 > /sys/module/lowmemorykiller/parameters/adj + echo 5120 > /proc/sys/vm/min_free_kbytes + ;; +esac +# Let kernel know our image version/variant/crm_version +if [ -f /sys/devices/soc0/select_image ]; then + image_version="10:" + image_version+=`getprop ro.build.id` + image_version+=":" + image_version+=`getprop ro.build.version.incremental` + image_variant=`getprop ro.product.name` + image_variant+="-" + image_variant+=`getprop ro.build.type` + oem_version=`getprop ro.build.version.codename` + echo 10 > /sys/devices/soc0/select_image + echo $image_version > /sys/devices/soc0/image_version + echo $image_variant > /sys/devices/soc0/image_variant + echo $oem_version > /sys/devices/soc0/image_crm_version +fi + +# Change console log level as per console config property +console_config=`getprop persist.vendor.console.silent.config` +case "$console_config" in + "1") + echo "Enable console config to $console_config" + echo 0 > /proc/sys/kernel/printk + ;; + *) + echo "Enable console config to $console_config" + ;; +esac + +# Parse misc partition path and set property +misc_link=$(ls -l /dev/block/bootdevice/by-name/misc) +real_path=${misc_link##*>} +setprop persist.vendor.mmi.misc_dev_path $real_path diff --git a/rootdir/bin/init.qcom.sh b/rootdir/bin/init.qcom.sh new file mode 100755 index 0000000..b80e98a --- /dev/null +++ b/rootdir/bin/init.qcom.sh @@ -0,0 +1,465 @@ +#! /vendor/bin/sh + +# Copyright (c) 2009-2016, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +target=`getprop ro.board.platform` +low_ram=`getprop ro.config.low_ram` +if [ -f /sys/devices/soc0/soc_id ]; then + platformid=`cat /sys/devices/soc0/soc_id` +else + platformid=`cat /sys/devices/system/soc/soc0/id` +fi + +start_battery_monitor() +{ + if ls /sys/bus/spmi/devices/qpnp-bms-*/fcc_data ; then + chown -h root.system /sys/module/pm8921_bms/parameters/* + chown -h root.system /sys/module/qpnp_bms/parameters/* + chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_data + chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_temp + chown -h root.system /sys/bus/spmi/devices/qpnp-bms-*/fcc_chgcyl + chmod 0660 /sys/module/qpnp_bms/parameters/* + chmod 0660 /sys/module/pm8921_bms/parameters/* + mkdir -p /data/bms + chown -h root.system /data/bms + chmod 0770 /data/bms + start battery_monitor + fi +} + +start_charger_monitor() +{ + if ls /sys/module/qpnp_charger/parameters/charger_monitor; then + chown -h root.system /sys/module/qpnp_charger/parameters/* + chown -h root.system /sys/class/power_supply/battery/input_current_max + chown -h root.system /sys/class/power_supply/battery/input_current_trim + chown -h root.system /sys/class/power_supply/battery/input_current_settled + chown -h root.system /sys/class/power_supply/battery/voltage_min + chmod 0664 /sys/class/power_supply/battery/input_current_max + chmod 0664 /sys/class/power_supply/battery/input_current_trim + chmod 0664 /sys/class/power_supply/battery/input_current_settled + chmod 0664 /sys/class/power_supply/battery/voltage_min + chmod 0664 /sys/module/qpnp_charger/parameters/charger_monitor + start charger_monitor + fi +} + +start_vm_bms() +{ + if [ -e /dev/vm_bms ]; then + chown -h root.system /sys/class/power_supply/bms/current_now + chown -h root.system /sys/class/power_supply/bms/voltage_ocv + chmod 0664 /sys/class/power_supply/bms/current_now + chmod 0664 /sys/class/power_supply/bms/voltage_ocv + start vm_bms + fi +} + +start_msm_irqbalance_8939() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + case "$platformid" in + "239" | "293" | "294" | "295" | "304" | "338" | "313" | "353" | "354") + start vendor.msm_irqbalance;; + "349" | "350" ) + start vendor.msm_irqbal_lb;; + esac + fi +} + +start_msm_irqbalance_msmnile() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + start vendor.msm_irqbalance + fi +} + +start_msm_irqbalance_kona() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + start vendor.msm_irqbalance + fi +} + +start_msm_irqbalance_lito() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + start vendor.msm_irqbalance + fi +} + +start_msm_irqbalance_atoll() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + start vendor.msm_irqbalance + fi +} + +start_msm_irqbalance660() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + case "$platformid" in + "317" | "321" | "324" | "325" | "326" | "336" | "345" | "346" | "360" | "393") + start vendor.msm_irqbalance;; + "318" | "327" | "385") + start vendor.msm_irqbl_sdm630;; + esac + fi +} + +start_msm_irqbalance() +{ + if [ -f /vendor/bin/msm_irqbalance ]; then + start vendor.msm_irqbalance + fi +} + +baseband=`getprop ro.baseband` +echo 1 > /proc/sys/net/ipv6/conf/default/accept_ra_defrtr + +case "$baseband" in + "svlte2a") + start bridgemgrd + ;; +esac + +case "$target" in + "msm7630_surf" | "msm7630_1x" | "msm7630_fusion") + if [ -f /sys/devices/soc0/hw_platform ]; then + value=`cat /sys/devices/soc0/hw_platform` + else + value=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + case "$value" in + "Fluid") + start profiler_daemon;; + esac + ;; + "msm8660" ) + if [ -f /sys/devices/soc0/hw_platform ]; then + platformvalue=`cat /sys/devices/soc0/hw_platform` + else + platformvalue=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + case "$platformvalue" in + "Fluid") + start profiler_daemon;; + esac + ;; + "msm8960") + case "$baseband" in + "msm") + start_battery_monitor;; + esac + + if [ -f /sys/devices/soc0/hw_platform ]; then + platformvalue=`cat /sys/devices/soc0/hw_platform` + else + platformvalue=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + case "$platformvalue" in + "Fluid") + start profiler_daemon;; + "Liquid") + start profiler_daemon;; + esac + ;; + "msm8974") + platformvalue=`cat /sys/devices/soc0/hw_platform` + case "$platformvalue" in + "Fluid") + start profiler_daemon;; + "Liquid") + start profiler_daemon;; + esac + case "$baseband" in + "msm") + start_battery_monitor + ;; + esac + start_charger_monitor + ;; + "sdm660") + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + + case "$soc_id" in + "317" | "324" | "325" | "326" | "318" | "327" ) + case "$hw_platform" in + "Surf") + setprop qemu.hw.mainkeys 0 + ;; + "MTP") + setprop qemu.hw.mainkeys 0 + ;; + "RCM") + setprop qemu.hw.mainkeys 0 + ;; + "QRD") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + esac + start_msm_irqbalance660 + ;; + "apq8084") + platformvalue=`cat /sys/devices/soc0/hw_platform` + case "$platformvalue" in + "Fluid") + start profiler_daemon;; + "Liquid") + start profiler_daemon;; + esac + ;; + "msm8226") + start_charger_monitor + ;; + "msm8610") + start_charger_monitor + ;; + "msm8916") + start_vm_bms + start_msm_irqbalance_8939 + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/platform_subtype_id ]; then + platform_subtype_id=`cat /sys/devices/soc0/platform_subtype_id` + fi + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + fi + case "$soc_id" in + "239") + case "$hw_platform" in + "Surf") + case "$platform_subtype_id" in + "1") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + "MTP") + case "$platform_subtype_id" in + "3") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + esac + ;; + esac + ;; + "msm8994" | "msm8992" | "msm8998" | "apq8098_latv" | "sdm845" | "sdm710" | "qcs605" | "sm6150" | "trinket" | "bengal") + start_msm_irqbalance + ;; + "msm8996") + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + fi + case "$hw_platform" in + "MTP" | "CDP") + #Loop through the sysfs nodes and determine the correct sysfs to change the permission and ownership. + for count in 0 1 2 3 4 5 6 7 8 9 10 + do + dir="/sys/devices/soc/75ba000.i2c/i2c-12/12-0020/input/input"$count + if [ -d "$dir" ]; then + chmod 0660 $dir/secure_touch_enable + chmod 0440 $dir/secure_touch + chown system.drmrpc $dir/secure_touch_enable + chown system.drmrpc $dir/secure_touch + break + fi + done + ;; + esac + ;; + "msm8909") + start_vm_bms + ;; + "msmnile") + start_msm_irqbalance_msmnile + ;; + "kona") + start_msm_irqbalance_kona + ;; + "lito") + start_msm_irqbalance_lito + ;; + "atoll") + start_msm_irqbalance_atoll + ;; + "msm8937") + start_msm_irqbalance_8939 + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + if [ "$low_ram" != "true" ]; then + case "$soc_id" in + "294" | "295" | "303" | "307" | "308" | "309" | "313" | "320" | "353" | "354" | "363" | "364") + case "$hw_platform" in + "Surf") + setprop qemu.hw.mainkeys 0 + ;; + "MTP") + setprop qemu.hw.mainkeys 0 + ;; + "RCM") + setprop qemu.hw.mainkeys 0 + ;; + "QRD") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + esac + fi + ;; + "msm8953") + start_msm_irqbalance_8939 + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + case "$soc_id" in + "293" | "304" | "338" | "351" | "349" | "350" ) + case "$hw_platform" in + "Surf") + setprop qemu.hw.mainkeys 0 + ;; + "MTP") + setprop qemu.hw.mainkeys 0 + ;; + "RCM") + setprop qemu.hw.mainkeys 0 + ;; + "QRD") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + esac + ;; + "sdm710") + if [ -f /sys/devices/soc0/soc_id ]; then + soc_id=`cat /sys/devices/soc0/soc_id` + else + soc_id=`cat /sys/devices/system/soc/soc0/id` + fi + + if [ -f /sys/devices/soc0/hw_platform ]; then + hw_platform=`cat /sys/devices/soc0/hw_platform` + else + hw_platform=`cat /sys/devices/system/soc/soc0/hw_platform` + fi + case "$soc_id" in + "336" | "337" | "347" | "360" | "393" ) + case "$hw_platform" in + "Surf") + setprop qemu.hw.mainkeys 0 + ;; + "MTP") + setprop qemu.hw.mainkeys 0 + ;; + "RCM") + setprop qemu.hw.mainkeys 0 + ;; + "QRD") + setprop qemu.hw.mainkeys 0 + ;; + esac + ;; + esac + ;; +esac + +# +# Make modem config folder and copy firmware config to that folder for RIL +# +if [ -f /data/vendor/modem_config/ver_info.txt ]; then + prev_version_info=`cat /data/vendor/modem_config/ver_info.txt` +else + prev_version_info="" +fi + +cur_version_info=`cat /vendor/firmware_mnt/verinfo/ver_info.txt` +if [ ! -f /vendor/firmware_mnt/verinfo/ver_info.txt -o "$prev_version_info" != "$cur_version_info" ]; then + # add W for group recursively before delete + chmod g+w -R /data/vendor/modem_config/* + rm -rf /data/vendor/modem_config/* + # preserve the read only mode for all subdir and files + cp --preserve=m -dr /vendor/firmware_mnt/image/modem_pr/mcfg/configs/* /data/vendor/modem_config + cp --preserve=m -d /vendor/firmware_mnt/verinfo/ver_info.txt /data/vendor/modem_config/ + cp --preserve=m -d /vendor/firmware_mnt/image/modem_pr/mbn_ota.txt /data/vendor/modem_config/ + # the group must be root, otherwise this script could not add "W" for group recursively + chown -hR radio.root /data/vendor/modem_config/* +fi +chmod g-w /data/vendor/modem_config +setprop ro.vendor.ril.mbn_copy_completed 1 + +#check build variant for printk logging +#current default minimum boot-time-default +buildvariant=`getprop ro.build.type` +case "$buildvariant" in + "userdebug" | "eng") + #set default loglevel to KERN_INFO + echo "4 6 1 7" > /proc/sys/kernel/printk + ;; + *) + #set default loglevel to KERN_WARNING + echo "4 4 1 4" > /proc/sys/kernel/printk + ;; +esac diff --git a/rootdir/bin/vendor_modprobe.sh b/rootdir/bin/vendor_modprobe.sh new file mode 100755 index 0000000..cb54050 --- /dev/null +++ b/rootdir/bin/vendor_modprobe.sh @@ -0,0 +1,38 @@ +#! /vendor/bin/sh +#============================================================================= +# Copyright (c) 2019-2020 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +#============================================================================= + +#default to /vendor/lib/modules +MODULES_PATH="/vendor/lib/modules/" +GKI_MOD_PATH="/vendor/lib/modules/5.4-gki" + +MODPROBE="/vendor/bin/modprobe" +MODULES=`${MODPROBE} -d ${MODULES_PATH} -l` + +# Find the first non-blacklisted module and try +# inserting it. If insertion fails the module is not +# compatible with the current kernel. Change the modules +# directory to gki. +for MODULE in ${MODULES}; do + cat ${MODULES_PATH}/modules.blocklist | grep $MODULE + if [ $? -ne 0 ]; then + break + fi +done + +${MODPROBE} -a -b -d ${MODULES_PATH} ${MODULE} +if [ $? -ne 0 ];then + MODULES_PATH=$GKI_MOD_PATH + MODULES=`${MODPROBE} -d ${MODULES_PATH} -l` +fi + +# Iterate over module list and modprobe them in background. +for MODULE in ${MODULES}; do + ${MODPROBE} -a -b -d ${MODULES_PATH} ${MODULE} & +done + +# Wait until all the modprobes are finished +wait diff --git a/rootdir/etc/charger_fstab.qti b/rootdir/etc/charger_fstab.qti new file mode 100644 index 0000000..87dd4a9 --- /dev/null +++ b/rootdir/etc/charger_fstab.qti @@ -0,0 +1,33 @@ +# Copyright (c) 2019 - 2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Android fstab file. +# The filesystem that contains the filesystem checker binary (typically /system) cannot +# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK + +# +/dev/block/bootdevice/by-name/modem /vendor/firmware_mnt vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait,slotselect diff --git a/rootdir/etc/fstab.default b/rootdir/etc/fstab.default new file mode 100644 index 0000000..ada9eb1 --- /dev/null +++ b/rootdir/etc/fstab.default @@ -0,0 +1,51 @@ +# Copyright (c) 2019-2020 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted (subject to the limitations in the +# disclaimer below) provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE +# GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT +# HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Android fstab file. +# The filesystem that contains the filesystem checker binary (typically /system) cannot +# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK + +# +system /system ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey +system_ext /system_ext ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount +product /product ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount +vendor /vendor ext4 ro,barrier=1,discard wait,slotselect,avb,logical,first_stage_mount +odm /odm ext4 ro,barrier=1,discard wait,slotselect,avb,logical,first_stage_mount +/dev/block/by-name/metadata /metadata ext4 noatime,nosuid,nodev,discard wait,check,formattable,first_stage_mount +/dev/block/bootdevice/by-name/persist /mnt/vendor/persist ext4 noatime,nosuid,nodev,barrier=1 wait,check +/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,inlinecrypt,reserve_root=32768,resgid=1065,fsync_mode=nobarrier latemount,wait,check,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+inlinecrypt_optimized+wrappedkey_v0,keydirectory=/metadata/vold/metadata_encryption,metadata_encryption=aes-256-xts:wrappedkey_v0,quota,reservedsize=128M,checkpoint=fs +/dev/block/bootdevice/by-name/misc /misc emmc defaults defaults +/devices/platform/soc/4784000.sdhci/mmc_host* /storage/sdcard1 vfat nosuid,nodev wait,voldmanaged=sdcard1:auto,encryptable=footer +/devices/platform/soc/*.ssusb/*.dwc3/xhci-hcd.*.auto* /storage/usbotg vfat nosuid,nodev wait,voldmanaged=usbotg:auto +/dev/block/bootdevice/by-name/modem /vendor/firmware_mnt vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait,slotselect +/dev/block/bootdevice/by-name/dsp /vendor/dsp ext4 ro,nosuid,nodev,barrier=1 wait,slotselect +/dev/block/bootdevice/by-name/bluetooth /vendor/bt_firmware vfat ro,shortname=lower,uid=1002,gid=3002,dmask=227,fmask=337,context=u:object_r:bt_firmware_file:s0 wait,slotselect diff --git a/rootdir/etc/fstab.emmc b/rootdir/etc/fstab.emmc new file mode 100644 index 0000000..9e20177 --- /dev/null +++ b/rootdir/etc/fstab.emmc @@ -0,0 +1,51 @@ +# Copyright (c) 2019-2020 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted (subject to the limitations in the +# disclaimer below) provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE +# GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT +# HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Android fstab file. +# The filesystem that contains the filesystem checker binary (typically /system) cannot +# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK + +# +system /system ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,avb_keys=/avb/q-gsi.avbpubkey:/avb/r-gsi.avbpubkey:/avb/s-gsi.avbpubkey +system_ext /system_ext ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount +product /product ext4 ro,barrier=1,discard wait,slotselect,avb=vbmeta_system,logical,first_stage_mount +vendor /vendor ext4 ro,barrier=1,discard wait,slotselect,avb,logical,first_stage_mount +odm /odm ext4 ro,barrier=1,discard wait,slotselect,avb,logical,first_stage_mount +/dev/block/by-name/metadata /metadata ext4 noatime,nosuid,nodev,discard wait,check,formattable,first_stage_mount +/dev/block/bootdevice/by-name/persist /mnt/vendor/persist ext4 noatime,nosuid,nodev,barrier=1 wait,check +/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,inlinecrypt,reserve_root=32768,resgid=1065,fsync_mode=nobarrier latemount,wait,check,formattable,fileencryption=aes-256-xts:aes-256-cts:v2+emmc_optimized+wrappedkey_v0,metadata_encryption=aes-256-xts:wrappedkey_v0,keydirectory=/metadata/vold/metadata_encryption,quota,reservedsize=128M,checkpoint=fs +/dev/block/bootdevice/by-name/misc /misc emmc defaults defaults +/devices/platform/soc/4784000.sdhci/mmc_host* /storage/sdcard1 vfat nosuid,nodev wait,voldmanaged=sdcard1:auto,encryptable=footer +/devices/platform/soc/*.ssusb/*.dwc3/xhci-hcd.*.auto* /storage/usbotg vfat nosuid,nodev wait,voldmanaged=usbotg:auto +/dev/block/bootdevice/by-name/modem /vendor/firmware_mnt vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait,slotselect +/dev/block/bootdevice/by-name/dsp /vendor/dsp ext4 ro,nosuid,nodev,barrier=1 wait,slotselect +/dev/block/bootdevice/by-name/bluetooth /vendor/bt_firmware vfat ro,shortname=lower,uid=1002,gid=3002,dmask=227,fmask=337,context=u:object_r:bt_firmware_file:s0 wait,slotselect diff --git a/rootdir/etc/init.batterysecret.rc b/rootdir/etc/init.batterysecret.rc new file mode 100644 index 0000000..abfc11a --- /dev/null +++ b/rootdir/etc/init.batterysecret.rc @@ -0,0 +1,31 @@ +on property:sys.boot_completed=1 + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/usbpd_verifed + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/request_vdm_cmd + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/verify_process + chmod 0664 /sys/class/qcom-battery/odm_battery/pd_auth + chmod 0664 /sys/class/qcom-battery/odm_battery/verify_digest + chmod 0664 /sys/class/qcom-battery/odm_battery/real_type + chmod 0664 /sys/class/qcom-battery/odm_battery/authentic + chmod 0664 /sys/class/qcom-battery/odm_battery/input_suspend + +service batterysecret /vendor/bin/batterysecret + class last_start + user root + group system system wakelock + disabled + seclabel u:r:batterysecret:s0 + +on property:sys.boot_completed=1 + start batterysecret + +#run batterysecret in off-charge mode +on charger + start batterysecret + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/usbpd_verifed + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/request_vdm_cmd + chmod 0664 /sys/class/Charging_Adapter/pd_adapter/verify_process + chmod 0664 /sys/class/qcom-battery/odm_battery/pd_auth + chmod 0664 /sys/class/qcom-battery/odm_battery/verify_digest + chmod 0664 /sys/class/qcom-battery/odm_battery/real_type + chmod 0664 /sys/class/qcom-battery/odm_battery/authentic + chmod 0664 /sys/class/qcom-battery/odm_battery/input_suspend diff --git a/rootdir/etc/init.nfc.rc b/rootdir/etc/init.nfc.rc new file mode 100644 index 0000000..895fcee --- /dev/null +++ b/rootdir/etc/init.nfc.rc @@ -0,0 +1,15 @@ +# +# Copyright (C) 2021 The LineageOS Project +# +# SPDX-License-Identifier: Apache-2.0 +# + +service vendor.nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.2-service + override + class hal + user nfc + group nfc + disabled + +on boot && property:ro.boot.product.hardware.sku=nfc + enable vendor.nfc_hal_service diff --git a/rootdir/etc/init.qcom.rc b/rootdir/etc/init.qcom.rc new file mode 100644 index 0000000..19736f4 --- /dev/null +++ b/rootdir/etc/init.qcom.rc @@ -0,0 +1,1581 @@ +# Copyright (c) 2009-2012, 2014-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +import /vendor/etc/init/hw/init.nfc.rc +import /vendor/etc/init/hw/init.qti.ufs.rc +import /vendor/etc/init/hw/init.qcom.usb.rc +import /vendor/etc/init/hw/init.qcom.test.rc +import /vendor/etc/init/hw/init.target.rc +import /vendor/etc/init/hw/init.qcom.factory.rc + +on early-init + mount debugfs debugfs /sys/kernel/debug + chmod 0755 /sys/kernel/debug + mount tracefs tracefs /sys/kernel/tracing + chmod 0755 /sys/kernel/tracing + + # create symlink for vendor mount points + symlink /vendor/firmware_mnt /firmware + symlink /vendor/bt_firmware /bt_firmware + symlink /vendor/dsp /dsp + + # Change ownership of hw_recovery related nodes + chown system graphics /sys/kernel/debug/dri/0/debug/dump + chown system graphics /sys/kernel/debug/dri/0/debug/recovery_reg + chown system graphics /sys/kernel/debug/dri/0/debug/recovery_dbgbus + chown system graphics /sys/kernel/debug/dri/0/debug/recovery_vbif_dbgbus + chown system graphics /sys/kernel/debug/dri/0/debug/recovery_dsi_dbgbus + + # Change ownership of sysfs power control node + chown system graphics /sys/class/drm/card0/device/power/control + + # Change ownership of sw_sync node + chown system graphics /sys/kernel/debug/sync/sw_sync + chmod 0666 /sys/kernel/debug/sync/sw_sync + + #Disable UFS clock scaling + write /sys/bus/platform/devices/1d84000.ufshc/clkscale_enable 0 + + chown root system /dev/kmsg + chmod 0620 /dev/kmsg + # Load WIGIG platform driver + exec u:r:vendor_modprobe:s0 -- /vendor/bin/modprobe -a -d /vendor/lib/modules msm_11ad_proxy + +on init + + # Support legacy paths + symlink /sdcard /mnt/sdcard + symlink /sdcard /storage/sdcard0 + + # Create cgroup mount point for memory + mkdir /sys/fs/cgroup/memory/bg 0750 root system + write /sys/fs/cgroup/memory/bg/memory.swappiness 140 + write /sys/fs/cgroup/memory/bg/memory.move_charge_at_immigrate 1 + chown root system /sys/fs/cgroup/memory/bg/tasks + chmod 0660 /sys/fs/cgroup/memory/bg/tasks + + #ExtR HONGMI-90103,jiyanan.wt,ADD,20211130,enbale WLAN PD restart + write /sys/bus/msm_subsys/devices/subsys2/restart_level related + +on post-fs + chmod 0755 /sys/kernel/debug/tracing + +on early-boot + # set RLIMIT_MEMLOCK to 64MB + setrlimit 8 67108864 67108864 + # Allow subsystem (modem etc) debugging + write /sys/kernel/boot_adsp/boot 1 + write /sys/kernel/boot_cdsp/boot 1 + write /sys/devices/virtual/npu/msm_npu/boot 1 + write /sys/devices/virtual/cvp/cvp/boot 1 + exec u:r:vendor_qti_init_shell:s0 -- /vendor/bin/init.qcom.early_boot.sh + exec u:r:vendor_qti_init_shell:s0 -- /vendor/bin/init.qti.can.sh + setprop ro.sf.lcd_density ${vendor.display.lcd_density} + + chown system system /mnt/vendor/persist/data/pfm/licenses + chmod 0775 /mnt/vendor/persist/data/pfm/licenses + chown system system /mnt/vendor/persist/data/pfm/licenses/store_0 + chmod 0664 /mnt/vendor/persist/data/pfm/licenses/store_0 + chown system system /mnt/vendor/persist/data/pfm/licenses/store_1 + chmod 0664 /mnt/vendor/persist/data/pfm/licenses/store_1 + chown system system /mnt/vendor/persist/data/pfm/licenses/store_2 + chmod 0664 /mnt/vendor/persist/data/pfm/licenses/store_2 + chown system system /mnt/vendor/persist/data/pfm/licenses/store_3 + chmod 0664 /mnt/vendor/persist/data/pfm/licenses/store_3 + chown system system /mnt/vendor/persist/data/pfm/licenses/store_4 + chmod 0664 /mnt/vendor/persist/data/pfm/licenses/store_4 + +on boot + chown bluetooth bluetooth /sys/module/bluetooth_power/parameters/power + chown bluetooth net_bt /sys/class/rfkill/rfkill0/type + chown bluetooth net_bt /sys/class/rfkill/rfkill0/state + chown bluetooth bluetooth /proc/bluetooth/sleep/proto + chown bluetooth bluetooth /sys/module/hci_uart/parameters/ath_lpm + chown bluetooth bluetooth /sys/module/hci_uart/parameters/ath_btwrite + chown system system /sys/module/sco/parameters/disable_esco + chown bluetooth bluetooth /sys/module/hci_smd/parameters/hcismd_set + chown system system /sys/module/msm_core/parameters/polling_interval + chown system system /sys/module/msm_core/parameters/disabled + chown system system /sys/kernel/debug/msm_core/enable + chown system system /sys/kernel/debug/msm_core/ptable + chown system system /sys/kernel/boot_slpi/ssr + chown system system /sys/module/radio_iris_transport/parameters/fmsmd_set + chmod 0660 /sys/module/bluetooth_power/parameters/power + chmod 0660 /sys/module/hci_smd/parameters/hcismd_set + chmod 0660 /sys/module/radio_iris_transport/parameters/fmsmd_set + chmod 0660 /sys/class/rfkill/rfkill0/state + chmod 0660 /proc/bluetooth/sleep/proto + chown bluetooth net_bt /dev/ttyHS0 + chmod 0660 /sys/module/hci_uart/parameters/ath_lpm + chmod 0660 /sys/module/hci_uart/parameters/ath_btwrite + chmod 0660 /dev/ttyHS0 + chown bluetooth bluetooth /sys/devices/platform/msm_serial_hs.0/clock + chmod 0660 /sys/devices/platform/msm_serial_hs.0/clock + + chmod 0660 /dev/ttyHS2 + chown bluetooth bluetooth /dev/ttyHS2 + + chown bluetooth net_bt /sys/class/rfkill/rfkill0/device/extldo + chmod 0660 /sys/class/rfkill/rfkill0/device/extldo + + # This location is used by QCRIL to host UNIX domain + # socket files used for internal IPC within QCRIL + # modules + mkdir /dev/socket/qmux_radio 0770 radio radio + chmod 2770 /dev/socket/qmux_radio + + mkdir /persist/drm 0770 system system + mkdir /persist/bluetooth 0770 bluetooth bluetooth + mkdir /persist/misc 0770 system system + mkdir /persist/alarm 0770 system system + mkdir /mnt/vendor/persist/time 0770 system system + mkdir /mnt/vendor/persist/secnvm 0770 system system + mkdir /mnt/vendor/persist/iar_db 0770 system system + mkdir /mnt/vendor/spunvm 0770 system system + + #Create WIGIG socket area + mkdir /dev/socket/wigig 0770 wifi wifi + + setprop wifi.interface wlan0 + + setprop persist.bluetooth.a2dp_offload.disabled false + + setprop ro.telephony.call_ring.multiple false + + #Remove SUID bit for iproute2 ip tool + chmod 0755 /system/bin/ip + + + chmod 0444 /sys/devices/platform/msm_hsusb/gadget/usb_state + + setprop net.tcp.2g_init_rwnd 10 + + # To prevent out of order acknowledgements from making + # connection tracking to treat them as not belonging to + # the connection they belong to. + # Otherwise, a weird issue happens in which some long + # connections on high-throughput links get dropped when + # an ack packet comes out of order + write /proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal 1 + + # Set the console loglevel to < KERN_WARN + # Set the default message loglevel to KERN_INFO + write /proc/sys/kernel/printk "4 6 1 7" + + # Allow access for CCID command/response timeout configuration + chown system system /sys/module/ccid_bridge/parameters/bulk_msg_timeout + + # bond0 used by FST Manager + chown wifi wifi /sys/class/net/bond0/bonding/queue_id + + # Allow access to emmc rawdump block partition and dload sysfs node + chown root system /dev/block/bootdevice/by-name/rawdump + chmod 0660 /dev/block/bootdevice/by-name/rawdump + chown root system /sys/kernel/dload/emmc_dload + chmod 0660 /sys/kernel/dload/emmc_dload + chown root system /dev/block/bootdevice/by-name/ramdump + chmod 0660 /dev/block/bootdevice/by-name/ramdump + chown root system /sys/kernel/dload/dload_mode + chmod 0660 /sys/kernel/dload/dload_mode + + chown system system /sys/class/backlight/panel0-backlight/brightness + chown system system /sys/class/backlight/panel0-backlight/max_brightness + chown system system /sys/class/backlight/panel1-backlight/brightness + chown system system /sys/class/backlight/panel1-backlight/max_brightness + + # Allow access to sensors device attributes + chown system system /sys/class/sensors/MPU6050-accel/enable + chown system system /sys/class/sensors/MPU6050-accel/poll_delay + chown system system /sys/class/sensors/MPU6050-gyro/enable + chown system system /sys/class/sensors/MPU6050-gyro/poll_delay + chown system system /sys/class/sensors/apds9930-light/enable + chown system system /sys/class/sensors/apds9930-light/poll_delay + chown system system /sys/class/sensors/apds9930-proximity/enable + chown system system /sys/class/sensors/apds9930-proximity/poll_delay + + # Create directory used for display + # for backward compatibility + mkdir /persist/display 0770 system graphics + mkdir /mnt/vendor/persist/display 0770 system graphics + + # Create vpp directory + mkdir /mnt/vendor/persist/vpp 0770 media media + + + # Create hvdcp_opti directory + mkdir /mnt/vendor/persist/hvdcp_opti 0770 root system + + # limit discard size to 128MB in order to avoid long IO latency + write /sys/block/sda/queue/discard_max_bytes 134217728 + + chmod 0777 /sys/bus/coresight/devices/coresight-tmc-etr/block_size + chmod 0777 /dev/byte-cntr + + #enable coresight for diag_mdlog_system over qdss + write /sys/bus/coresight/devices/coresight-tmc-etr/buffer_size 0x2000000 + write /sys/bus/coresight/devices/coresight-tmc-etr/enable_sink 1 + write /sys/bus/coresight/devices/coresight-stm/enable_source 1 + write /sys/bus/coresight/devices/coresight-stm/hwevent_enable 0 + +# msm specific files that need to be created on /data +on post-fs-data + mkdir /data/vendor/misc 01771 system system + + # Create directory used for dump collection + mkdir /data/vendor/ssrdump 0770 root system + + # Create directory used by display clients + mkdir /data/vendor/display 0770 system graphics + + # Change lm related dirs + mkdir /data/vendor/lm 0700 root root + + # Create directory used by powermodule + mkdir /data/vendor/pwr 0700 root root + + # Create directory used by media clients + mkdir /data/vendor/media 0770 mediacodec media + + # Create /data/vendor/tzstorage directory for SFS listener + mkdir /data/vendor/tzstorage 0770 system system + + # Create directory for apps access via QTEEConnector + mkdir /data/vendor/qtee 0770 system system + + #Create folder of camera + mkdir /data/vendor/camera 0770 camera camera + + + #Create directory for tftp + mkdir /data/vendor/tombstones 0771 system system + mkdir /data/vendor/tombstones/rfs 0771 system system + + mkdir /data/vendor/ramdump 0771 root system + mkdir /data/vendor/bluetooth 0770 bluetooth bluetooth + mkdir /data/vendor/ramdump/bluetooth 0770 bluetooth bluetooth + + # Create the directories used by the Wireless subsystem + mkdir /data/vendor/wifi 0770 wifi wifi + mkdir /data/vendor/wifi/sockets 0770 wifi wifi + mkdir /data/vendor/wifi/hostapd 0770 wifi wifi + mkdir /data/vendor/wifi/hostapd/ctrl 0770 wifi wifi + mkdir /data/vendor/wifi/wpa_supplicant 0770 wifi wifi + mkdir /data/vendor/wifi/wigig_hostapd 0770 wifi wifi + mkdir /data/vendor/wifi/wpa 0770 wifi wifi + mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi + mkdir /data/vendor/wlan_logs_t 0770 system wifi + + #ExtR HONGMI-99227, jiyanan.wt, 20210903,ADD, generate bt/wlan addr file + mkdir /data/vendor/mac_addr 0775 root system + + # Create the directories used by WiGig Sensing + mkdir /data/vendor/sensing 0770 system wifi + + # Create the directories used by CnE subsystem + mkdir /data/vendor/connectivity 0771 radio radio + chown radio radio /data/vendor/connectivity + + # Create directory used by audio subsystem + mkdir /data/vendor/audio 0770 audio audio + + # Create directory for audio delta files + mkdir /data/vendor/audio/acdbdata 0770 media audio + mkdir /data/vendor/audio/acdbdata/delta 0770 media audio + + # Create directory for radio + mkdir /data/vendor/radio 0770 system radio + rm /data/vendor/radio/shmbus + + # Create directory for modem_config + mkdir /data/vendor/modem_config 0570 radio root + + # Mounting of persist is moved to 'on emmc-fs' and 'on fs' sections + # We chown/chmod /persist again so because mount is run as root + defaults + chown root system /persist + chmod 0771 /persist + chown system system /persist/WCNSS_qcom_wlan_nv.bin + chmod 0664 /sys/devices/platform/msm_sdcc.1/polling + chmod 0664 /sys/devices/platform/msm_sdcc.2/polling + chmod 0664 /sys/devices/platform/msm_sdcc.3/polling + chmod 0664 /sys/devices/platform/msm_sdcc.4/polling + + # Chown polling nodes as needed from UI running on system server + chown system system /sys/devices/platform/msm_sdcc.1/polling + chown system system /sys/devices/platform/msm_sdcc.2/polling + chown system system /sys/devices/platform/msm_sdcc.3/polling + chown system system /sys/devices/platform/msm_sdcc.4/polling + + #Create the symlink to qcn wpa_supplicant folder for ar6000 wpa_supplicant + #symlink /data/misc/wifi/wpa_supplicant /data/system/wpa_supplicant + + #Add for ir + chown system system /dev/ir_spi + chmod 0666 /dev/ir_spi + + #Create directories for Location services + mkdir /data/vendor/location 0770 gps gps + mkdir /data/vendor/location/mq 0770 gps gps + mkdir /data/vendor/location/xtwifi 0770 gps gps + mkdir /dev/socket/location 0770 gps gps + mkdir /dev/socket/location/mq 0770 gps gps + mkdir /dev/socket/location/xtra 0770 gps gps + mkdir /dev/socket/location/dgnss 0770 gps gps + + #Create directories for wifihal services + mkdir /dev/socket/wifihal 0770 wifi wifi + chmod 2770 /dev/socket/wifihal + + # Create /data/time folder for time-services + mkdir /data/vendor/time/ 0700 system system + + setprop vold.post_fs_data_done 1 + + #Create a folder for SRS to be able to create a usercfg file + #mkdir /data/data/media 0770 media media + + #Create FM dir for patchdownloader + mkdir /data/vendor/fm 0770 system system + chmod 0770 /data/vendor/fm + + #Create PERFD deamon related dirs + mkdir /data/vendor/perfd 0770 root system + chmod 2770 /data/vendor/perfd + rm /data/vendor/perfd/default_values + + mkdir /data/vendor/secure_element 0777 system system + + #Create IOP deamon related dirs + mkdir /data/vendor/iop 0700 root system + + # Mark the copy complete flag to not completed + write /data/vendor/radio/copy_complete 0 + chown radio radio /data/vendor/radio/copy_complete + chmod 0660 /data/vendor/radio/copy_complete + + # copy prebuilt qcril.db files always + copy /vendor/radio/qcril_database/qcril.db /data/vendor/radio/qcril_prebuilt.db + chown radio radio /data/vendor/radio/qcril_prebuilt.db + chmod 0660 /data/vendor/radio/qcril_prebuilt.db + copy /vendor/radio/qcril_database/qcrilNr.db /data/vendor/radio/qcrilNr_prebuilt.db + copy /vendor/etc/qcril_database/qcrilNr.db /data/vendor/radio/qcrilNr_prebuilt.db + chown radio radio /data/vendor/radio/qcrilNr_prebuilt.db + chmod 0660 /data/vendor/radio/qcrilNr_prebuilt.db + + # File flags for prebuilt ril db file + write /data/vendor/radio/prebuilt_db_support 1 + chown radio radio /data/vendor/radio/prebuilt_db_support + chmod 0400 /data/vendor/radio/prebuilt_db_support + write /data/vendor/radio/db_check_done 0 + chown radio radio /data/vendor/radio/db_check_done + chmod 0660 /data/vendor/radio/db_check_done + + # qti-logkit data + mkdir /data/vendor/qti-logkit/ 0771 system system + mkdir /data/vendor/qti-logkit/shared-privileged/ 2770 system system + mkdir /data/vendor/qti-logkit/shared-public/ 2770 system diag + mkdir /data/vendor/qti-logkit/socket-privileged/ 2770 system system + mkdir /data/vendor/qti-logkit/socket-public/ 2750 system diag + mkdir /data/vendor/qti-logkit/logdata/ 2750 system shell + + #Create SWAP related dirs + mkdir /data/vendor/swap 0770 root system + chmod 2770 /data/vendor/swap + + # set aggressive read ahead for dm-0 and dm-1 during boot up + write /sys/block/dm-0/queue/read_ahead_kb 2048 + write /sys/block/dm-1/queue/read_ahead_kb 2048 + write /sys/block/dm-2/queue/read_ahead_kb 2048 + + # Create vpp directory + mkdir /data/vendor/vpp 0770 media media + + #Create dir for TUI + mkdir /data/vendor/tui 0700 system drmrpc + + #Create dir for dolby + mkdir /data/vendor/dolby 0770 media media + +service nqnfcinfo /system/vendor/bin/nqnfcinfo + class late_start + group nfc + user system + oneshot + +service iop /system/vendor/bin/iop + class main + user root + group root + disabled + socket iop seqpacket 0666 root system + +service qcomsysd /system/vendor/bin/qcom-system-daemon + class main + user root + group root diag oem_2901 + disabled + +on property:persist.vendor.qcomsysd.enabled=1 + enable qcomsysd + +on property:persist.vendor.qcomsysd.enabled=0 + stop qcomsysd + +service vendor.ssr_setup /system/vendor/bin/ssr_setup + oneshot + disabled + +service vendor.ss_ramdump /system/bin/subsystem_ramdump_system 2 + class main +# user system + group system bluetooth sdcard_rw everybody + ioprio rt 4 + disabled + +on property:ro.vendor.iocgrp.config=1 + mkdir /dev/blkio + mount cgroup none /dev/blkio blkio + chown system system /dev/blkio + chown system system /dev/blkio/tasks + chmod 0664 /dev/blkio/tasks + mkdir /dev/blkio/bg 0755 system system + chown system system /dev/blkio/bg/tasks + chmod 0664 /dev/blkio/bg/tasks + write /dev/blkio/blkio.weight 1000 + write /dev/blkio/bg/blkio.weight 100 + +on property:persist.sys.ssr.enable_debug=* + write /sys/module/subsystem_restart/parameters/enable_debug ${persist.sys.ssr.enable_debug} + +on property:persist.sys.mba_boot_timeout=* + write /sys/module/pil_msa/parameters/pbl_mba_boot_timeout_ms ${persist.sys.mba_boot_timeout} + +on property:persist.sys.modem_auth_timeout=* + write /sys/module/pil_msa/parameters/modem_auth_timeout_ms ${persist.sys.modem_auth_timeout} + +on property:persist.sys.pil_proxy_timeout=* + write /sys/module/peripheral_loader/parameters/proxy_timeout_ms ${persist.sys.pil_proxy_timeout} + +on property:persist.vendor.ssr.restart_level=* + start vendor.ssr_setup + +on property:persist.vendor.ssr.enable_ramdumps=1 + write /sys/module/subsystem_restart/parameters/enable_ramdumps 1 + mkdir /data/vendor/ramdump_ssr 770 system system +# start vendor.ss_ramdump + +on property:persist.vendor.ssr.enable_ramdumps=0 + write /sys/module/subsystem_restart/parameters/enable_ramdumps 0 + +on property:persist.vendor.sys.rawdump_copy=1 + write /sys/kernel/dload/emmc_dload 1 + +on property:persist.vendor.sys.rawdump_copy=0 + write /sys/kernel/dload/emmc_dload 0 + +on property:sys.boot_completed=1 + write /dev/kmsg "Boot completed " + #Enable UFS clock scaling back + write /sys/bus/platform/devices/1d84000.ufshc/clkscale_enable 1 + #Reset read ahead for dm-0 and dm-1 to 512kb + write /sys/block/dm-0/queue/read_ahead_kb 512 + write /sys/block/dm-1/queue/read_ahead_kb 512 + #WDSP FW boot sysfs node used by STHAL + chown media audio /sys/kernel/wdsp0/boot + chown media audio /sys/kernel/wcd_cpe0/fw_name + #Reinit lmkd to reconfigure lmkd properties + setprop lmkd.reinit 1 + write /sys/kernel/dload/dload_mode "both" + write /sys/kernel/dload/emmc_dload 1 + +on property:persist.vendor.radio.atfwd.start=false + stop vendor.atfwd + +on property:vendor.radio.atfwd.start=false + stop vendor.atfwd + +# corefile limit +on property:persist.debug.trace=1 + mkdir /data/core 0777 root root + write /proc/sys/kernel/core_pattern "/data/core/core-%e-%p" + +on property:vendor.media.target.version=* + setprop vendor.sys.media.target.version ${vendor.media.target.version} + +on property:vendor.netflix.bsp_rev=* + setprop ro.netflix.bsp_rev ${vendor.netflix.bsp_rev} + +on property:vendor.media.target_variant=* + setprop ro.media.xml_variant.codecs ${vendor.media.target_variant} + setprop ro.media.xml_variant.codecs_performance ${vendor.media.target_variant} + +service qcom-c_core-sh /vendor/bin/init.qcom.class_core.sh + class core + user root + oneshot + +service qcom-c_main-sh /vendor/bin/init.class_main.sh + class main + user root + group root system + oneshot + +on property:vold.decrypt=trigger_restart_framework + start qcom-c_main-sh + start wcnss-service + +service vendor.qrtr-ns /vendor/bin/qrtr-ns -f + class core + user vendor_qrtr + group vendor_qrtr + capabilities NET_BIND_SERVICE + +service irsc_util /vendor/bin/irsc_util "/vendor/etc/sec_config" + class core + user root + oneshot + +service qmiproxy /system/bin/qmiproxy + class main + user radio + group radio diag + disabled + +service vendor.wigig_supplicant /vendor/bin/hw/wpa_supplicant \ + -iwigig0 -Dnl80211 -c/data/vendor/wifi/wigig_supplicant.conf \ + -m/data/vendor/wifi/wigig_p2p_supplicant.conf \ + -O/data/vendor/wifi/wigig_sockets -dd \ + -e/data/vendor/wifi/wigig_entropy.bin -g@android:wigig/wpa_wigig0 \ + -S wigigsvc + # we will start as root and wpa_supplicant will switch to user wifi + # after setting up the capabilities required for WEXT + # user wifi + # group wifi inet keystore + class main + socket wigig/wpa_wigig0 dgram 660 wifi wifi + disabled + oneshot + +# Data Migration +service vendor.move_wifi_data /system/bin/move_wifi_data.sh + class main + user wifi + group wifi + disabled + oneshot + +service wigignpt /vendor/bin/wigignpt + class hal + socket wigig/wigignpt stream 660 system wifi + user system + group wifi + capabilities NET_ADMIN + disabled + +on property:persist.vendor.wigig.npt.enable=1 + start wigignpt + +service vendor.sensingdaemon /vendor/bin/sensingdaemon + class hal + socket wigig/sensingdaemon stream 660 system wifi + user system + group wifi + disabled + +service dhcpcd_wlan0 /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service dhcpcd_bond0 /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service dhcpcd_p2p /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service dhcpcd_wigig0 /system/bin/dhcpcd -ABKLG + class late_start + disabled + oneshot + +service iprenew_wlan0 /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service iprenew_bond0 /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service iprenew_p2p /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service iprenew_wigig0 /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +#+ExtR HONGMI-89895 jiyanan 20210922 add for capture wifi full log start +service vendor.cnss_diag /vendor/bin/cnss_diag -q -f + class late_start + user system + group system wifi inet net_admin sdcard_rw media_rw diag + disabled + oneshot + +service vendor.tcpdump /vendor/bin/tcpdump -i any -W 2 -C 2 -s 134 -w /data/vendor/wlan_logs_t/tcpdump.pcap + class main + disabled + oneshot + +service sniffer /vendor/bin/tcpdump -i wlan0 -w /data/vendor/wlan_logs_t/sniffer.pcap + class main + disabled + oneshot + +on property:vendor.wififulllog.value=true + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap0 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap0 + start vendor.cnss_diag + start vendor.tcpdump + +on property:vendor.wififulllog.value=false + stop vendor.cnss_diag + stop vendor.tcpdump + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap0 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap0 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap1 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap1 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap2 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap2 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap3 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap3 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap4 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap4 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap5 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap5 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap6 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap6 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap7 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap7 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap8 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap8 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap9 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap9 + chmod 0664 /data/vendor/wlan_logs_t/tcpdump.pcap10 + chown system root /data/vendor/wlan_logs_t/tcpdump.pcap10 + +service startpktlog /system/bin/iwpriv wlan0 pktlog 2 + class main + user root + group root + disabled + oneshot + +service stoppktlog /system/bin/iwpriv wlan0 pktlog 0 + class main + user root + group root + disabled + oneshot + +on property:wifi.pktlog.debug.0.chen=false + start stoppktlog + +on property:wifi.pktlog.debug.0.chen=true + start startpktlog +#-ExtR HONGMI-89895 jiyanan 20210922 add for capture wifi full log start + +#+ExtB HONGMI-89820,liupeng.wt.Add,20211011 add wifi sar + +#india k6s +#2g head sar +on property:vendor.sysctl.tx=1 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli01 +service wpa_cli01 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 29 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6s +#2g body sar +on property:vendor.sysctl.tx=2 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli02 +service wpa_cli02 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6s +#2g restore +on property:vendor.sysctl.tx=3 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli03 +service wpa_cli03 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6s +#5g head sar +on property:vendor.sysctl.tx=4 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli04 +service wpa_cli04 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 23 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6s +#5g body sar +on property:vendor.sysctl.tx=5 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli05 +service wpa_cli05 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6s +#5g restore +on property:vendor.sysctl.tx=6 + stop wpa_cli01 + stop wpa_cli02 + stop wpa_cli03 + stop wpa_cli04 + stop wpa_cli05 + stop wpa_cli06 + start wpa_cli06 +service wpa_cli06 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#2g head sar +on property:vendor.sysctl.tx=11 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli11 +service wpa_cli11 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 29 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#2g body sar +on property:vendor.sysctl.tx=12 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli12 +service wpa_cli12 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#2g restore +on property:vendor.sysctl.tx=13 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli13 +service wpa_cli13 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#5g head sar +on property:vendor.sysctl.tx=14 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli14 +service wpa_cli14 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 20 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#5g body sar +on property:vendor.sysctl.tx=15 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli15 +service wpa_cli15 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 28 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#india k6p +#5g restore +on property:vendor.sysctl.tx=16 + stop wpa_cli11 + stop wpa_cli12 + stop wpa_cli13 + stop wpa_cli14 + stop wpa_cli15 + stop wpa_cli16 + start wpa_cli16 +service wpa_cli16 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 28 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#2g head sar +on property:vendor.sysctl.tx=21 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli21 +service wpa_cli21 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 33 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#2g body sar +on property:vendor.sysctl.tx=22 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli22 +service wpa_cli22 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 38 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#2g restore +on property:vendor.sysctl.tx=23 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli23 +service wpa_cli23 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 38 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#5g head sar +on property:vendor.sysctl.tx=24 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli24 +service wpa_cli24 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 27 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#5g body sar +on property:vendor.sysctl.tx=25 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli25 +service wpa_cli25 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 36 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#CN k6s +#5g restore +on property:vendor.sysctl.tx=26 + stop wpa_cli21 + stop wpa_cli22 + stop wpa_cli23 + stop wpa_cli24 + stop wpa_cli25 + stop wpa_cli26 + start wpa_cli26 +service wpa_cli26 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 36 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#2g head sar +on property:vendor.sysctl.tx=31 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli31 +service wpa_cli31 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 24 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#2g body sar +on property:vendor.sysctl.tx=32 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli32 +service wpa_cli32 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#2g restore +on property:vendor.sysctl.tx=33 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli33 +service wpa_cli33 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#5g head sar +on property:vendor.sysctl.tx=34 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli34 +service wpa_cli34 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 19 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#5g body sar +on property:vendor.sysctl.tx=35 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli35 +service wpa_cli35 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#JP k6s +#5g restore +on property:vendor.sysctl.tx=36 + stop wpa_cli31 + stop wpa_cli32 + stop wpa_cli33 + stop wpa_cli34 + stop wpa_cli35 + stop wpa_cli36 + start wpa_cli36 +service wpa_cli36 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#2g head sar +on property:vendor.sysctl.tx=41 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli41 +service wpa_cli41 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 24 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#2g body sar +on property:vendor.sysctl.tx=42 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli42 +service wpa_cli42 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#2g restore +on property:vendor.sysctl.tx=43 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli43 +service wpa_cli43 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 37 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#5g head sar +on property:vendor.sysctl.tx=44 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli44 +service wpa_cli44 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 19 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#5g body sar +on property:vendor.sysctl.tx=45 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli45 +service wpa_cli45 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#GL k6s +#5g restore +on property:vendor.sysctl.tx=46 + stop wpa_cli41 + stop wpa_cli42 + stop wpa_cli43 + stop wpa_cli44 + stop wpa_cli45 + stop wpa_cli46 + start wpa_cli46 +service wpa_cli46 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 32 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + +#KR k6s no sar power +#2g head sar +on property:vendor.sysctl.tx=51 + start wpa_cli51 +service wpa_cli51 /vendor/bin/wpa_cli driver SET_TX_POWER_CALLING 8 + class main + user root + group root + disabled + oneshot + seclabel u:r:sar:s0 + + +#-ExtB HONGMI-89820,liupeng.wt.Add,20211011 add wifi sar + +service ptt_socket_app /system/vendor/bin/ptt_socket_app -d + class main + user wifi + group wifi system inet net_admin + capabilities NET_ADMIN + oneshot + +service ptt_ffbm /system/vendor/bin/ptt_socket_app -f -d + user root + group root + disabled + oneshot + +service wifi_ftmd /system/vendor/bin/wifi_ftmd + user system + group system inet net_admin + socket wififtmd_server dgram 0660 system system + disabled + oneshot + +on property:vendor.wifi.ftmd.load=true + insmod /system/lib/modules/pronto/pronto_wlan.ko con_mode=5 + +service cnss-daemon /system/vendor/bin/cnss-daemon -n -l + class late_start + user system + group system inet net_admin wifi + capabilities NET_ADMIN + +on property:sys.shutdown.requested=* + write /sys/kernel/shutdown_wlan/shutdown 1 + stop cnss-daemon + +service dhcpcd_bt-pan /system/bin/dhcpcd -BKLG + class late_start + disabled + oneshot + +service iprenew_bt-pan /system/bin/dhcpcd -n + class late_start + disabled + oneshot + +service ssgqmigd /vendor/bin/ssgqmigd + class late_start + user radio + group radio gps system + socket ssgqmig seqpacket 0660 radio inet + +service mlid /vendor/bin/mlid + class late_start + user gps + group gps + socket mlid stream 0666 gps gps + +service loc_launcher /system/vendor/bin/loc_launcher + class late_start + user gps + group gps + +service qcom-sh /vendor/bin/init.qcom.sh + class late_start + user root + group root system radio + oneshot +# Remove since is deprecated but throws AVC denial. +# service crashdata-sh /vendor/bin/init.qcom.crashdata.sh +# class late_start +# user root +# oneshot + +service qcom-post-boot /vendor/bin/init.qcom.post_boot.sh + class late_start + user root + group root system wakelock graphics + disabled + oneshot + +service qti-testscripts /system/bin/sh /product/etc/init.qcom.testscripts.sh + class late_start + user root + disabled + oneshot + seclabel u:r:qti-testscripts:s0 + +service wifi-sdio-on /vendor/bin/init.qcom.sdio.sh + class late_start + group wifi inet + disabled + oneshot + +service wifi-crda /vendor/bin/init.crda.sh + class late_start + user root + disabled + oneshot + +on property:sys.boot_completed=1 + start qcom-post-boot + start qti-testscripts + +on property:ro.vendor.ril.mbn_copy_completed=1 + write /data/vendor/radio/copy_complete 1 + +service qvop-daemon /vendor/bin/qvop-daemon + class late_start + user system + group system drmrpc + +service vendor.atfwd /vendor/bin/ATFWD-daemon + class late_start + user system + group system radio + +service hostapd_fst /vendor/bin/hw/hostapd -dd -g /data/vendor/wifi/hostapd/global + class main + capabilities NET_ADMIN NET_RAW + user wifi + group wifi + disabled + oneshot + +service battery_monitor /system/bin/battery_monitor + user system + group system + disabled + +service vendor.ril-daemon2 /vendor/bin/hw/rild -c 2 + class main + user radio + disabled + group radio cache inet misc audio sdcard_r sdcard_rw diag oem_2901 log + capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW + +service vendor.ril-daemon3 /vendor/bin/hw/rild -c 3 + class main + user radio + disabled + group radio cache inet misc audio sdcard_r sdcard_rw diag oem_2901 log + capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW + +service profiler_daemon /system/bin/profiler_daemon + class late_start + user root + group root + disabled + +service charger /system/bin/charger + class charger + user system + group system graphics input + capabilities SYS_BOOT + seclabel u:r:charger:s0 + +service vendor.ssr_diag /system/vendor/bin/ssr_diag + class late_start + user system + group system + disabled + +#HONGMI-102656, wuwenting.wt, modify, 20211012, change diag command +service diag_mdlog_start /system/vendor/bin/diag_mdlog -q 2 -u + class late_start + user shell + group system oem_2901 sdcard_rw sdcard_r media_rw + disabled + oneshot + +service diag_mdlog_stop /system/vendor/bin/diag_mdlog -k + class late_start + user shell + group system oem_2901 sdcard_rw sdcard_r media_rw + disabled + oneshot + +service qlogd /system/xbin/qlogd + socket qlogd stream 0662 system system + class main + disabled +on property:persist.sys.qlogd=1 + start qlogd +on property:persist.sys.qlogd=0 + stop qlogd + +service vm_bms /vendor/bin/vm_bms + user root + group root + disabled + +service vendor.msm_irqbalance /vendor/bin/msm_irqbalance -f /system/vendor/etc/msm_irqbalance.conf + class core + user root + group root + disabled + +service vendor.msm_irqbal_lb /vendor/bin/msm_irqbalance -f /system/vendor/etc/msm_irqbalance_little_big.conf + class core + user root + group root + disabled + +service vendor.msm_irqbl_sdm630 /vendor/bin/msm_irqbalance -f /system/vendor/etc/msm_irqbalance_sdm630.conf + class core + user root + group root + disabled + +# service for USERDEBUG +service vendor.LKCore-dbg /vendor/bin/LKCore + class late_start + oneshot + disabled + user root + group root system log diag net_raw + +# service for USER +service vendor.LKCore-rel /vendor/bin/LKCore + class late_start + oneshot + disabled + user system + group system log diag + +service qseeproxydaemon /system/vendor/bin/qseeproxydaemon + class late_start + user system + group system + +service esepmdaemon /system/vendor/bin/esepmdaemon + class core + user system + group nfc + +on charger + setprop persist.sys.usb.config mass_storage + start qcom-post-boot + +#add poweroffhandler +service poweroffhandler /system/vendor/bin/poweroffhandler + class core + user media + group graphics audio + disabled + oneshot + +service time_daemon /vendor/bin/time_daemon + class main + user system + group system + capabilities SYS_TIME + +# Set vendor-ril lib path based on Meta version +on property:vendor.rild.libpath=* + setprop rild.libpath ${vendor.rild.libpath} + +on property:ro.vendor.radio.noril=* + setprop ro.radio.noril ${ro.vendor.radio.noril} + +service vendor.power_off_alarm /vendor/bin/power_off_alarm + class core + group system + disabled + oneshot + +service vendor.hbtp /vendor/bin/hbtp_daemon + class main + user system + group system + capabilities SYS_NICE + disabled + +service chre /vendor/bin/chre + class late_start + user system + group system + socket chre seqpacket 0660 root system + shutdown critical + +on property:vendor.chre.enabled=0 + stop chre + +service bugreport /system/bin/dumpstate -d -p -B -z -o /data/user_de/0/com.android.shell/files/bugreports/bugreport + class main + disabled + oneshot + keycodes 114 115 116 + +#Set GPU Opengles version +on property:vendor.opengles.version=* + setprop ro.opengles.version ${vendor.opengles.version} + +#Set gpu available frequencies property +on property:vendor.gpu.available_frequencies=* + setprop ro.vendor.gpu.available_frequencies ${vendor.gpu.available_frequencies} + +service vendor.audio-hal /vendor/bin/hw/android.hardware.audio.service + override + class hal + user audioserver + # media gid needed for /dev/fm (radio) and for /data/misc/media (tee) + group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct oem_2901 wakelock + capabilities BLOCK_SUSPEND + ioprio rt 4 + writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks + socket audio_hw_socket seqpacket 0666 system system + onrestart restart audioserver diff --git a/rootdir/etc/init.qti.kernel.rc b/rootdir/etc/init.qti.kernel.rc new file mode 100644 index 0000000..a1f8c62 --- /dev/null +++ b/rootdir/etc/init.qti.kernel.rc @@ -0,0 +1,175 @@ +#============================================================================= +# Copyright (c) 2019-2021 Qualcomm Technologies, Inc. +# All Rights Reserved. +# Confidential and Proprietary - Qualcomm Technologies, Inc. +# +# Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= +import /vendor/etc/init/hw/init.qti.kernel.test.rc + +on early-init + mount debugfs debugfs /sys/kernel/debug + chmod 0755 /sys/kernel/debug + + # Mount tracefs in /sys/kernel/tracing as CONFIG_DEBUG_FS might be + # disabled and /sys/kernel/debug/tracing might not be available + mount tracefs tracefs /sys/kernel/tracing + chmod 0755 /sys/kernel/tracing + + chown root system /dev/kmsg + chmod 0620 /dev/kmsg + + write /proc/sys/kernel/sched_boost 1 + + write /proc/sys/kernel/firmware_config/force_sysfs_fallback 1 + +on init + # Create cgroup mount point for memory + mkdir /sys/fs/cgroup/memory/bg 0750 root system + write /sys/fs/cgroup/memory/bg/memory.swappiness 140 + write /sys/fs/cgroup/memory/bg/memory.move_charge_at_immigrate 1 + chown root system /sys/fs/cgroup/memory/bg/tasks + chmod 0660 /sys/fs/cgroup/memory/bg/tasks + + # update scheduler tunables + write /dev/cpuctl/foreground/cpu.uclamp.sched_boost_no_override 1 + write /dev/cpuctl/top-app/cpu.uclamp.sched_boost_no_override 1 + write /dev/cpuctl/background/cpu.uclamp.colocate 0 + write /dev/cpuctl/foreground/cpu.uclamp.colocate 0 + write /dev/cpuctl/top-app/cpu.uclamp.colocate 1 + +on post-fs + chmod 0755 /sys/kernel/debug/tracing + + # set aggressive read ahead for dm-0 and dm-1 during boot up + write /sys/block/dm-0/queue/read_ahead_kb 2048 + write /sys/block/dm-1/queue/read_ahead_kb 2048 + write /sys/block/dm-2/queue/read_ahead_kb 2048 + +on early-boot + # Allow subsystem (modem etc) debugging + write /sys/kernel/boot_adsp/boot 1 + write /sys/kernel/boot_cdsp/boot 1 + write /sys/kernel/boot_slpi/boot 1 + write /sys/devices/virtual/cvp/cvp/boot 1 + +on boot + # Set the console loglevel to < KERN_WARN + # Set the default message loglevel to KERN_INFO + write /proc/sys/kernel/printk "4 6 1 7" + + # Allow access to emmc rawdump block partition and dload sysfs node + chown root system /dev/block/bootdevice/by-name/rawdump + chmod 0660 /dev/block/bootdevice/by-name/rawdump + chown root system /sys/kernel/dload/emmc_dload + chmod 0660 /sys/kernel/dload/emmc_dload + chown root system /dev/block/bootdevice/by-name/ramdump + chmod 0660 /dev/block/bootdevice/by-name/ramdump + chown root system /sys/kernel/dload/dload_mode + chmod 0660 /sys/kernel/dload/dload_mode + + # set the io-scheduler to bfq on all mq support devices + write /sys/block/sda/queue/scheduler bfq + write /sys/block/sdb/queue/scheduler bfq + write /sys/block/sdc/queue/scheduler bfq + write /sys/block/sdd/queue/scheduler bfq + write /sys/block/sde/queue/scheduler bfq + write /sys/block/sdf/queue/scheduler bfq + write /sys/block/sdg/queue/scheduler bfq + write /sys/block/sdh/queue/scheduler bfq + write /sys/class/block/mmcblk0/queue/scheduler bfq + write /sys/class/block/mmcblk1/queue/scheduler bfq + + # update io-scheduler tunables + write /sys/block/sda/queue/iosched/slice_idle 0 + write /sys/block/sdb/queue/iosched/slice_idle 0 + write /sys/block/sdc/queue/iosched/slice_idle 0 + write /sys/block/sdd/queue/iosched/slice_idle 0 + write /sys/block/sde/queue/iosched/slice_idle 0 + write /sys/block/sdf/queue/iosched/slice_idle 0 + write /sys/block/sdg/queue/iosched/slice_idle 0 + write /sys/block/sdh/queue/iosched/slice_idle 0 + write /sys/class/block/mmcblk0/queue/iosched/slice_idle 0 + write /sys/class/block/mmcblk1/queue/iosched/slice_idle 0 + +on post-fs-data + # Create directory used for dump collection + mkdir /data/vendor/ssrdump 0770 root system + +on property:persist.sys.ssr.enable_debug=* + write /sys/module/subsys_pil_tz/parameters/enable_debug ${persist.sys.ssr.enable_debug} + +on property:persist.sys.mba_boot_timeout=* + write /sys/module/pil_msa/parameters/pbl_mba_boot_timeout_ms ${persist.sys.mba_boot_timeout} + +on property:persist.sys.modem_auth_timeout=* + write /sys/module/pil_msa/parameters/modem_auth_timeout_ms ${persist.sys.modem_auth_timeout} + +on property:persist.sys.pil_proxy_timeout=* + write /sys/module/peripheral_loader/parameters/proxy_timeout_ms ${persist.sys.pil_proxy_timeout} + +on property:persist.vendor.ssr.enable_ramdumps=1 + write /sys/module/subsystem_restart/parameters/enable_ramdumps 1 + +on property:persist.vendor.ssr.enable_ramdumps=0 + write /sys/module/subsystem_restart/parameters/enable_ramdumps 0 + +on property:persist.vendor.sys.rawdump_copy=1 + write /sys/kernel/dload/emmc_dload 1 + +on property:persist.vendor.sys.rawdump_copy=0 + write /sys/kernel/dload/emmc_dload 0 + +service kernel-boot /vendor/bin/sh /vendor/bin/init.qti.kernel.sh + class core + user root + group root + disabled + oneshot + +service kernel-post-boot /vendor/bin/sh /vendor/bin/init.kernel.post_boot.sh + class core + user root + group root system wakelock graphics + disabled + oneshot + +on property:sys.boot_completed=1 + write /dev/kmsg "Boot completed " + #Reset read ahead for dm-0, dm-1 and dm-2 to 512kb + write /sys/block/dm-0/queue/read_ahead_kb 512 + write /sys/block/dm-1/queue/read_ahead_kb 512 + write /sys/block/dm-2/queue/read_ahead_kb 512 + write /proc/sys/vm/page-cluster 0 + start kernel-boot + start kernel-post-boot + +service vendor.msm_irqbalance /vendor/bin/msm_irqbalance -f /system/vendor/etc/msm_irqbalance.conf + class core + user root + group root + disabled diff --git a/rootdir/etc/init.qti.ufs.rc b/rootdir/etc/init.qti.ufs.rc new file mode 100644 index 0000000..a37e55e --- /dev/null +++ b/rootdir/etc/init.qti.ufs.rc @@ -0,0 +1,30 @@ +# Copyright (c) 2011-2016, 2018-2020 The Linux Foundation. All rights reserved. +# # +# # Redistribution and use in source and binary forms, with or without +# # modification, are permitted provided that the following conditions are +# # met: +# # * Redistributions of source code must retain the above copyright +# # notice, this list of conditions and the following disclaimer. +# # * Redistributions in binary form must reproduce the above +# # copyright notice, this list of conditions and the following +# # disclaimer in the documentation and/or other materials provided +# # with the distribution. +# # * Neither the name of The Linux Foundation nor the names of its +# # contributors may be used to endorse or promote products derived +# # from this software without specific prior written permission. +# # +# # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +on init + exec u:r:vendor-qti-testscripts:s0 -- /vendor/bin/sh /vendor/bin/init.qti.ufs.debug.sh diff --git a/rootdir/etc/init.recovery.qcom.rc b/rootdir/etc/init.recovery.qcom.rc new file mode 100644 index 0000000..edb5bd3 --- /dev/null +++ b/rootdir/etc/init.recovery.qcom.rc @@ -0,0 +1,38 @@ +# Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +on init + write /sys/class/backlight/panel0-backlight/brightness 200 + setprop sys.usb.configfs 1 + +on property:ro.boot.usbcontroller=* + setprop sys.usb.controller ${ro.boot.usbcontroller} + write /sys/class/udc/${ro.boot.usbcontroller}/device/../mode peripheral + +on fs + wait /dev/block/platform/soc/${ro.boot.bootdevice} + symlink /dev/block/platform/soc/${ro.boot.bootdevice} /dev/block/bootdevice \ No newline at end of file diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc new file mode 100644 index 0000000..38c9a9f --- /dev/null +++ b/rootdir/etc/init.target.rc @@ -0,0 +1,286 @@ + +# Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of The Linux Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +import /vendor/etc/init/init.mishow.ctl.rc +import /vendor/etc/init/init.charge_logger.rc +import /vendor/etc/init/hw/init.qti.kernel.rc + +on early-init + exec u:r:vendor_modprobe:s0 -- /vendor/bin/vendor_modprobe.sh + exec u:r:vendor_modprobe:s0 -- /vendor/bin/modprobe -a -d /vendor/lib/modules q6_pdr_dlkm q6_notifier_dlkm snd_event_dlkm apr_dlkm adsp_loader_dlkm q6_dlkm native_dlkm pinctrl_lpi_dlkm swr_dlkm platform_dlkm stub_dlkm wcd_core_dlkm wsa881x_analog_dlkm bolero_cdc_dlkm va_macro_dlkm rx_macro_dlkm tx_macro_dlkm bt_fm_slim wcd938x_dlkm wcd938x_slave_dlkm wcd937x_dlkm wcd937x_slave_dlkm aw882xx_dlkm fs19xx_dlkm machine_dlkm radio-i2c-rtc6226-qca cdsprm + wait /sys/devices/soc0/soc_id + +on init + # Scheduler uclamp + mkdir /dev/cpuctl/foreground + mkdir /dev/cpuctl/background + mkdir /dev/cpuctl/top-app + mkdir /dev/cpuctl/rt + chown system system /dev/cpuctl + chown system system /dev/cpuctl/foreground + chown system system /dev/cpuctl/background + chown system system /dev/cpuctl/top-app + chown system system /dev/cpuctl/rt + chown system system /dev/cpuctl/tasks + chown system system /dev/cpuctl/foreground/tasks + chown system system /dev/cpuctl/background/tasks + chown system system /dev/cpuctl/top-app/tasks + chown system system /dev/cpuctl/rt/tasks + chmod 0664 /dev/cpuctl/tasks + chmod 0664 /dev/cpuctl/foreground/tasks + chmod 0664 /dev/cpuctl/background/tasks + chmod 0664 /dev/cpuctl/top-app/tasks + chmod 0664 /dev/cpuctl/rt/tasks + write /dev/cpuctl/foreground/cpu.rt_runtime_us 950000 + write /dev/cpuctl/background/cpu.rt_runtime_us 950000 + write /dev/cpuctl/top-app/cpu.rt_runtime_us 950000 + write /dev/cpuctl/rt/cpu.rt_runtime_us 950000 + + wait /dev/block/platform/soc/${ro.boot.bootdevice} + symlink /dev/block/platform/soc/${ro.boot.bootdevice} /dev/block/bootdevice + start logd + + #+chk99786, tanghongnian.wt, add, 20211029, for battery charging off if CALL_STATE_OFFHOOK + chown system system /sys/class/qcom-battery/charging_call_state + chmod 0660 /sys/class/qcom-battery/charging_call_state + #-chk99786, tanghongnian.wt, add, 20211029, for battery charging off if CALL_STATE_OFFHOOK + +on early-fs + start vold + +on fs + start hwservicemanager + mount_all --early + chown root system /mnt/vendor/persist + chmod 0771 /mnt/vendor/persist + restorecon_recursive /mnt/vendor/persist + mkdir /mnt/vendor/persist/data 0700 system system + mount ext4 /dev/block/bootdevice/by-name/rescue /mnt/rescue noatime + restorecon_recursive /mnt/rescue + +on post-fs + # set RLIMIT_MEMLOCK to 64MB + setrlimit 8 67108864 67108864 + +on property:ro.factory_mode=1 && property:sys.boot_completed=1 + chown system system /data/local/tmp + chmod 0777 /data/local/tmp + chmod 0666 /dev/block/sda9 + +on late-fs + wait_for_prop hwservicemanager.ready true + #exec_start wait_for_keymaster + start console + mount_all --late + +on post-fs-data + mkdir /vendor/data/tombstones 0771 system system +#ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal + mkdir /data/vendor/thermal 0771 root system + mkdir /data/vendor/thermal/config 0771 root system + chmod 0644 /dev/elliptic0 + chmod 0644 /dev/elliptic1 + chmod 0660 /dev/ir_spi + chown system system /dev/ir_spi + mkdir /data/vendor/wlan_logs 0777 root shell + +on early-boot + start vendor.sensors + +on boot + # DT2W + chown system system /proc/tp_gesture + chmod 0644 /proc/tp_gesture + + write /dev/cpuset/audio-app/cpus 1-2 + # Add a cpuset for the camera daemon + # We want all cores for camera + mkdir /dev/cpuset/camera-daemon + write /dev/cpuset/camera-daemon/cpus 0-7 + write /dev/cpuset/camera-daemon/mems 0 + chown cameraserver cameraserver /dev/cpuset/camera-daemon + chown cameraserver cameraserver /dev/cpuset/camera-daemon/tasks + chmod 0660 /dev/cpuset/camera-daemon/tasks + #USB controller configuration + setprop vendor.usb.rndis.func.name "gsi" + setprop vendor.usb.rmnet.func.name "gsi" + setprop vendor.usb.rmnet.inst.name "rmnet" + setprop vendor.usb.dpl.inst.name "dpl" + setprop vendor.usb.qdss.inst.name "qdss_mdm" + setprop vendor.usb.controller 4e00000.dwc3 +#bug 676383, zhangsen1@wingtech.com, 20210807, modify audio bringup smartpa + mkdir /mnt/vendor/persist/audio 0777 system system + mkdir /vendor/firmware/awinic/ + mkdir /mnt/vendor/persist/audio 0777 system system + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0034/cali + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0034/cali_f0 + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0034/cali_re + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0034/dsp_re + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0035/cali + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0035/cali_f0 + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0035/cali_re + chmod 0666 /sys/bus/i2c/drivers/aw882xx_smartpa/3-0035/dsp_re + +#bug 676383, zhangsen1@wingtech.com, 20210828, modify audio bringup smartpa + mkdir /vendor/firmware/fsm1962/ + + chmod 0666 /sys/bus/i2c/drivers/fs19xx/3-0036/cali_f0 + chmod 0666 /sys/bus/i2c/drivers/fs19xx/3-0036/cali_re + + chmod 0666 /sys/bus/i2c/drivers/fs19xx/3-0037/cali_f0 + chmod 0666 /sys/bus/i2c/drivers/fs19xx/3-0037/cali_re + + chmod 0644 /mnt/vendor/persist/audio/aw_cali.bin + chmod 0644 /mnt/vendor/persist/audio/fsm_calib.bin + + #ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal + chown system system /sys/class/thermal/thermal_message/sconfig + +# add dual + mkdir /mnt/vendor/persist/camera 0777 system system + chmod 0666 /mnt/vendor/persist/camera/rear_dc_cal_wu.bin + chmod 0666 /data/vendor/camera/com.xiaomi.dcal.wu.data + +#xiechongchong01 test + chmod 0777 /proc/tp_palm + chown system system /proc/tp_palm + +#add perm for calib + chmod 0777 /data/vendor/camera + +on property:vendor.display.lcd_density=560 + setprop dalvik.vm.heapgrowthlimit 256m + +on property:vendor.display.lcd_density=640 + setprop dalvik.vm.heapgrowthlimit 512m + +on boot && property:persist.vendor.usb.controller.default=* + setprop vendor.usb.controller ${persist.vendor.usb.controller.default} + +on charger + mount_all /vendor/etc/charger_fstab.qti --early + write /sys/kernel/boot_adsp/boot 1 + #restart charger after ADSP is out of reset + #restart charger + start vendor.power_off_alarm + setprop sys.usb.controller 4e00000.dwc3 + setprop sys.usb.configfs 1 + #+ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal + start mi_thermald + #-ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal + +#+ExtR HONGMI-90162,zhangb02@wingtech.com,add,20211003,add misound +service audioshell_service /vendor/bin/audioshell_service + oneshot + disabled + +on property:ro.vendor.miui.region=* + start audioshell_service +#-ExtR HONGMI-90162,zhangbo2@wingtech.com,add,20211003,add misound + +#pd-mapper +service vendor.pd_mapper /vendor/bin/pd-mapper + class core + user system + group system + +#Peripheral manager +service vendor.per_mgr /vendor/bin/pm-service + class core + user system + group system + ioprio rt 4 + +service vendor.per_proxy /vendor/bin/pm-proxy + class core + user system + group system + disabled + +#service vendor.mdm_helper /vendor/bin/mdm_helper +# class core +# group system wakelock +# disabled + +service vendor.mdm_launcher /vendor/bin/sh /vendor/bin/init.mdm.sh + class core + oneshot + +on property:init.svc.vendor.per_mgr=running + start vendor.per_proxy + +on property:sys.shutdown.requested=* + stop vendor.per_proxy + +on property:vold.decrypt=trigger_restart_framework + start vendor.cnss_diag + +service vendor.cnss_diag /system/vendor/bin/cnss_diag -q -f -t HELIUM + class main + user system + group system wifi inet sdcard_rw media_rw diag + oneshot + +#ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal +service mi_thermald /system/vendor/bin/mi_thermald + class main + user root + group system + seclabel u:r:mi_thermald:s0 +#-ExtR HONGMI-90116,wufa@wingtech.com,add,20210908,add mi_thermal + +service svi_on /vendor/bin/ppd "svi:on" + class main + group root system + oneshot + disabled + +on property:init.svc.vendor.nv_mac=stopped + start vendor.btmac-sh + +service vendor.btmac-sh /vendor/bin/init.mi.btmac.sh + class late_start + user system + group system bluetooth wifi + oneshot + disabled + +on property:ro.vendor.display.svi=1 && property:sys.boot_completed=1 + start svi_on + +service checknv /system/bin/checknv + class main + user root + group root system + oneshot + seclabel u:r:checknv:s0 + +# Sync attribute value between system and vendor +on property:persist.sys.mcc.mnc=* + setprop persist.vendor.mcc.mnc ${persist.sys.mcc.mnc} diff --git a/rootdir/etc/ueventd.qcom.rc b/rootdir/etc/ueventd.qcom.rc new file mode 100644 index 0000000..04e5708 --- /dev/null +++ b/rootdir/etc/ueventd.qcom.rc @@ -0,0 +1,507 @@ +# Copyright (c) 2012-2015, 2017-2020, The Linux Foundation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of The Linux Foundation nor +# the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# Firmware directory Path +# Below macro will be read by uevent and path will +# be added to search path for firmware loading +firmware_directories /vendor/firmware_mnt/image/ + +# the DIAG device node is not world writable/readable. +/dev/diag 0660 system oem_2901 +/dev/mhi_*_pipe_4 0660 system system + +/dev/genlock 0666 system system +/dev/wlan 0660 wifi wifi +/dev/kgsl 0666 system system +/dev/kgsl-3d0 0666 system system +/dev/kgsl-2d0 0666 root root +/dev/kgsl-2d1 0666 root root +/dev/ion 0664 system system +/dev/membuf 0664 system system +/dev/rtc0 0660 system system +/dev/smd0 0660 system system +/dev/smd4 0660 system system +/dev/smd_cxm_qmi 0640 radio radio +/dev/smd5 0660 system system +/dev/smd6 0660 system system +/dev/smd7 0660 bluetooth bluetooth +/dev/ccid_bridge 0660 system system +/dev/ipa 0660 radio radio +/dev/wwan_ioctl 0660 radio radio +/dev/ipaNatTable 0660 radio radio +/dev/rmnet_ctrl 0660 usb usb +/dev/dpl_ctrl 0660 usb usb +/dev/ipa_odl_ctl 0660 radio radio +/dev/ipa_adpl 0660 system oem_2905 +/dev/synx_device 0660 root camera +/dev/hab 0666 system system +/dev/hgsl 0666 system system +/dev/iio:device* 0664 system system + +#permissions for UFS RPMB BSG device node +/dev/0:0:0:49476 0600 system system + +#permissions for CSVT +/dev/smd11 0660 radio radio + +#permsissions for BT/FM +/dev/smd2 0660 bluetooth bluetooth +/dev/smd3 0660 bluetooth bluetooth +/dev/btpower 0660 bluetooth system + +#permissions for pta +/dev/pta 0660 system system + +/dev/radio0 0640 system system +/dev/rfcomm0 0660 bluetooth bluetooth +/dev/ttyUSB0 0660 bluetooth bluetooth +/dev/smdcntl0 0640 radio radio +/dev/smdcntl1 0640 radio radio +/dev/smdcntl2 0640 radio radio +/dev/smdcntl3 0640 radio radio +/dev/smdcntl4 0640 radio radio +/dev/smdcntl5 0640 radio radio +/dev/smdcntl6 0640 radio radio +/dev/smdcntl7 0640 radio radio +/dev/smdcntl8 0640 radio radio +/dev/smdcnt_rev0 0640 radio radio +/dev/smdcnt_rev1 0640 radio radio +/dev/smdcnt_rev2 0640 radio radio +/dev/smdcnt_rev3 0640 radio radio +/dev/smdcnt_rev4 0640 radio radio +/dev/smdcnt_rev5 0640 radio radio +/dev/smdcnt_rev6 0640 radio radio +/dev/smdcnt_rev7 0640 radio radio +/dev/smdcnt_rev8 0640 radio radio +/dev/smuxctl32 0640 radio radio +/dev/sdioctl0 0640 radio radio +/dev/sdioctl1 0640 radio radio +/dev/sdioctl2 0640 radio radio +/dev/sdioctl3 0640 radio radio +/dev/sdioctl4 0640 radio radio +/dev/sdioctl5 0640 radio radio +/dev/sdioctl6 0640 radio radio +/dev/sdioctl7 0640 radio radio +/dev/sdioctl8 0640 radio radio +/dev/rmnet_mux_ctrl 0640 radio radio +/dev/hsicctl0 0640 radio radio +/dev/hsicctl1 0640 radio radio +/dev/hsicctl2 0640 radio radio +/dev/hsicctl3 0640 radio radio +/dev/hsicctl4 0640 radio radio +/dev/hsicctl5 0640 radio radio +/dev/hsicctl6 0640 radio radio +/dev/hsicctl7 0640 radio radio +/dev/hsicctl8 0640 radio radio +/dev/hsicctl9 0640 radio radio +/dev/hsicctl10 0640 radio radio +/dev/hsicctl11 0640 radio radio +/dev/hsicctl12 0640 radio radio +/dev/hsicctl13 0640 radio radio +/dev/hsicctl14 0640 radio radio +/dev/hsicctl15 0640 radio radio +/dev/hsicctl16 0640 radio radio +/dev/mhi_*_pipe_14 0640 radio radio +/dev/mhi_*_pipe_16 0640 radio radio +/dev/mhi_*_pipe_32 0640 radio radio +/dev/at_usb0 0640 radio radio +/dev/at_mdm0 0640 radio radio +/dev/video* 0660 system camera +/dev/cvp* 0660 system camera +/dev/media* 0660 system camera +/dev/v4l-subdev* 0660 system camera +/dev/qseecom 0660 system drmrpc +/dev/qce 0660 system drmrpc +/dev/smcinvoke 0660 system drmrpc +/dev/qsee_ipc_irq_spss 0660 system drmrpc +/dev/seemplog 0660 system system +/dev/pft 0660 system drmrpc +/dev/spcom 0660 system system +/dev/spss_utils 0660 system system +/dev/sp_kernel 0660 system system +/dev/sp_nvm 0660 system system +/dev/sp_ssr 0660 system system +/dev/sp_keymaster 0660 system system +/dev/sp_keymaster_ssr 0660 system system +/dev/sec_nvm_* 0660 system system +/dev/cryptoapp 0660 system system +/dev/spdaemon_ssr 0660 system system +/dev/spu_hal_ssr 0660 system system +/dev/iuicc* 0660 system system +/dev/gemini0 0660 system camera +/dev/jpeg0 0660 system camera +/dev/jpeg1 0660 system camera +/dev/jpeg2 0660 system camera +/dev/jpeg3 0660 system camera +/dev/adsprpc-smd 0664 system system +/dev/adsprpc-smd-secure 0644 system system +/dev/system_health_monitor 0644 radio system +/dev/mdss_rotator 0664 system system + +#QDSS +/dev/byte-cntr 0660 system oem_2902 +/dev/mhi_qdss 0660 system oem_2902 +/sys/class/qdss_bridge/mhi_qdss mode 0660 system oem_2902 + +#qg +/dev/qg 0660 system system +/dev/qg_battery 0660 system system + +#qvr +/dev/qvr_external_sensor_ioctl 0660 system system +/sys/kernel/qvr_external_sensor/fd 0660 system system +/dev/bus/usb/001/002 0660 system system +/dev/bus/usb/001/003 0660 system system +/dev/bus/usb/001/004 0660 system system +/dev/bus/usb/001/005 0660 system system +/dev/bus/usb/002/002 0660 system system +/dev/bus/usb/002/003 0660 system system +/dev/bus/usb/002/004 0660 system system +/dev/bus/usb/002/005 0660 system system +/dev/bus/usb/003/002 0660 system system +/dev/bus/usb/003/003 0660 system system +/dev/bus/usb/003/004 0660 system system +/dev/bus/usb/003/005 0660 system system +/dev/hidraw0 0660 system system +/dev/hidraw1 0660 system system +/dev/hidraw2 0660 system system +/dev/hidraw3 0660 system system +/dev/hidraw4 0660 system system +/dev/hidraw5 0660 system system +/dev/hidraw6 0660 system system +/dev/hidraw7 0660 system system +/dev/hidraw8 0660 system system +/dev/hidraw9 0660 system system + +#goodix fingerprint +/dev/goodix_fp 0660 system system + +# wlan +/dev/wcnss_wlan 0660 system system +/dev/wcnss_ctrl 0660 system system +/sys/devices/soc/a000000.qcom,wcnss-wlan/net/wlan0/queues/rx-* rps_cpus 0660 system system +/sys/devices/soc/a000000.qcom,wcnss-wlan/net/p2p0/queues/rx-* rps_cpus 0660 system system +/sys/devices/platform/soc/*.qcom,icnss/net/wlan*/queues/rx-* rps_cpus 0660 system system +/sys/devices/platform/soc/1c00000.qcom,pcie/pci0000:00/0000:00:00.0/0000:01:00.0/net/wlan*/queues/rx-* rps_cpus 0660 system system +/sys/devices/platform/soc/17a10040.qcom,wcn6750/net/wlan*/queues/rx-* rps_cpus 0660 system system +/dev/spidev0.0 0660 system audio +/dev/i2c-7 0660 system audio +/dev/msm_camera/* 0660 system camera +/dev/gemini/ 0660 system camera +/dev/mercury0 0660 system camera +/dev/msm_vidc_reg 0660 system audio +/dev/msm_vidc_dec 0660 system audio +/dev/msm_vidc_dec_sec 0660 system audio +/dev/msm_vidc_enc 0660 system audio +/dev/msm_rotator 0660 system system +/dev/hw_random 0600 root root +/dev/sdsprpc-smd 0660 system system + +#permissions for audio +/dev/wcd_dsp0_control 0660 system audio +/dev/wcd-dsp-glink 0660 system audio +/dev/audio_slimslave 0660 system audio +/dev/msm_qcelp 0660 system audio +/dev/msm_evrc 0660 system audio +/dev/msm_wma 0660 system audio +/dev/msm_wmapro 0660 system audio +/dev/msm_alac 0660 system audio +/dev/msm_ape 0660 system audio +/dev/msm_amrnb 0660 system audio +/dev/msm_amrwb 0660 system audio +/dev/msm_amrwbplus 0660 system audio +/dev/msm_aac 0660 system audio +/dev/msm_multi_aac 0660 system audio +/dev/msm_aac_in 0660 system audio +/dev/msm_qcelp_in 0660 system audio +/dev/msm_evrc_in 0660 system audio +/dev/msm_amrnb_in 0660 system audio +/dev/msm_amrwb_in 0660 system audio +/dev/msm_a2dp_in 0660 system audio +/dev/msm_ac3 0660 system audio +/dev/msm_audio_cal 0660 system audio +/dev/msm_hweffects 0660 system audio +/dev/msm_cad 0660 system audio +/dev/msm_fm 0660 system audio +/dev/msm_mvs 0660 system audio +/dev/msm_pcm_lp_dec 0660 system audio +/dev/msm_preproc_ctl 0660 system audio +/dev/msm_rtac 0660 system audio +/dev/msm_voicememo 0660 system audio +/dev/ttyHSL1 0660 system system +/dev/ttyHS1 0660 system system +/dev/mdm 0660 system radio +/sys/devices/virtual/smdpkt/smdcntl* open_timeout 0664 radio radio +/dev/sdio_tty_ciq_00 0660 system system +/dev/tty_sdio_00 0660 system system +/dev/ttyGS0 0660 system system +/dev/i2c-5 0660 media media +/dev/avtimer 0660 system audio +/dev/spidev2.0 0660 system audio +/dev/spidev22.0 0660 system audio +/dev/spidev10.0 0660 system audio + +# DVB devices +/dev/dvb/adapter0/demux* 0440 media media +/dev/dvb/adapter0/dvr* 0660 media media +/dev/dvb/adapter0/video* 0660 media media + +# Broadcast devices +/dev/tsc_mux0 0660 media media +/dev/tsc_ci0 0660 media media + +# sensors +/dev/sensors 0660 system system +/sys/devices/i2c-12/12-* pollrate_ms 0664 system system +/sys/devices/f9925000.i2c/i2c-0/0-* enable 0660 input system +/sys/devices/f9925000.i2c/i2c-0/0-* poll_delay 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* enable 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* poll_delay 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* enable_wakeup 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* max_latency 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* flush 0660 input system +/sys/devices/soc.0/78b6000.i2c/i2c-0/0-* calibrate 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* enable 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* poll_delay 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* enable_wakeup 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* max_latency 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* flush 0660 input system +/sys/devices/soc.0/78b5000.i2c/i2c-1/1-* calibrate 0660 input system +/sys/devices/virtual/optical_sensors/proximity ps_adc 0660 input system +/sys/devices/virtual/optical_sensors/proximity ps_poll_delay 0660 input system +/sys/devices/virtual/optical_sensors/lightsensor ls_auto 0660 input system +/sys/devices/virtual/optical_sensors/lightsensor ls_poll_delay 0660 input system +/sys/devices/virtual/input/input* poll 0660 input system +/sys/devices/virtual/input/input* pollrate_ms 0660 input system +/sys/devices/soc/78b7000.i2c/i2c-3/3-0020/input/input* secure_touch 0440 system drmrpc +/sys/devices/soc/78b7000.i2c/i2c-3/3-0020/input/input* secure_touch_enable 0660 system drmrpc +/sys/devices/soc/78b7000.i2c/i2c-3/3-0038/input/input* secure_touch 0440 system drmrpc +/sys/devices/soc/78b7000.i2c/i2c-3/3-0038/input/input* secure_touch_enable 0660 system drmrpc +/sys/devices/soc/78b7000.i2c/i2c-3/3-004b/input/input* secure_touch 0440 system drmrpc +/sys/devices/soc/78b7000.i2c/i2c-3/3-004b/input/input* secure_touch_enable 0660 system drmrpc +/sys/devices/soc/c179000.i2c/i2c-5/5-0020/input/input* secure_touch 0440 system drmrpc +/sys/devices/soc/c179000.i2c/i2c-5/5-0020/input/input* secure_touch_enable 0660 system drmrpc +/sys/devices/platform/soc/a98000.i2c/i2c-2/2-0020/input/input* secure_touch 0440 system drmrpc +/sys/devices/platform/soc/a98000.i2c/i2c-2/2-0020/input/input* secure_touch_enable 0660 system drmrpc +/sys/devices/platform/soc/a84000.i2c/i2c-2/2-0020/input/input* secure_touch 0440 system drmrpc +/sys/devices/platform/soc/a84000.i2c/i2c-2/2-0020/input/input* secure_touch_enable 0660 system drmrpc + +# GNSS Device premissions +/dev/gnss_sirf 0660 gps gps + +# laser sensor access +/sys/devices/virtual/input/input* enable_ps_sensor 0660 system input +/sys/devices/virtual/input/input* set_delay_ms 0660 system input +/sys/devices/virtual/input/input* do_flush 0660 system input + +# vm_bms +/dev/vm_bms 0660 system system +/dev/battery_data 0660 system system + +# wlan +/dev/wcnss_wlan 0660 system system +/dev/wcnss_ctrl 0660 system system +/sys/devices/soc/600000.qcom,pcie/pci0000:00/0000:00:00.0/0000:01:00.0/net/wlan0/queues/rx-* rps_cpus 0660 system system +/sys/devices/soc/600000.qcom,pcie/pci0000:00/0000:00:00.0/0000:01:00.0/net/p2p0/queues/rx-* rps_cpus 0660 system system + +# wigig +/sys/bus/pci/drivers/wil6210* 0000:01:00.0/wil6210/fst_link_loss 0660 wifi wifi +/sys/bus/pci/drivers/wil6210* 0000:01:00.0/wil6210/thermal_throttling 0660 system system +/sys/bus/pci/drivers/wil6210* 0000:01:00.0/wil6210/snr_thresh 0660 wifi wifi +/sys/bus/pci/drivers/wil6210* 0000:01:00.0/net/wigig0/queues/rx-0/rps_cpus 0660 system system +/sys/bus/pci/drivers/wil6210* 0000:01:00.0/net/wigig0/gro_flush_timeout 0660 system system +/sys/devices/virtual/net/bond0 queues/rx-0/rps_cpus 0660 system system + +#nfc permissions +/dev/nfc-nci 0660 nfc nfc +/dev/nq-nci 0660 nfc nfc +/dev/assd 0660 nfc nfc + +# UIO devices +/dev/uio0 0660 system system +/dev/uio1 0660 system system +/dev/uio2 0660 system system + +# SSR devices +/dev/subsys_* 0640 system system + +# Ultrasound device +/dev/usf1 0660 system system + +# Ramdump devices +/dev/ramdump* 0640 system system + +# Fingerprint device +/dev/qbt* 0660 system system +/sys/class/fts/touch_aoi aoi_set 0660 root system +/sys/class/fts/touch_aoi power_set 0660 root system + +#ImproveTouch device +/dev/hbtp_input 0660 system system +/dev/hbtp_vm 0660 system system + +# Add device block for FRP +/dev/block/platform/soc/7824900.sdhci/by-name/config 0600 system system +/dev/block/platform/soc/7464900.sdhci/by-name/frp 0600 system system +/dev/block/platform/soc/624000.ufshc/by-name/frp 0600 system system +/dev/block/platform/soc/1da4000.ufshc/by-name/frp 0600 system system +/dev/block/platform/soc/c0c4000.sdhci/by-name/frp 0600 system system +/dev/block/platform/soc/1d84000.ufshc/by-name/frp 0600 system system +/dev/block/platform/soc/7c4000.sdhci/by-name/frp 0600 system system +/dev/block/platform/soc/4744000.sdhci/by-name/frp 0600 system system +/dev/block/platform/soc/4804000.ufshc/by-name/frp 0600 system system + +# This is temporary while using SD card for initial bring-up +/dev/block/platform/soc/8804000.sdhci/by-name/frp 0600 system system + +# Kmsg device +/dev/kmsg 0620 root system + +#bug636798, xuxinyu@wt, 20210724,add hardware info +#hardwareinfo +/dev/hardwareinfo 0660 root system + +# LED class devices +/sys/class/leds/red delay_on 0640 system system +/sys/class/leds/red delay_off 0640 system system +/sys/class/leds/red breath 0640 system system +/sys/class/leds/red trigger 0640 system system +/sys/class/leds/green delay_on 0640 system system +/sys/class/leds/green delay_off 0640 system system +/sys/class/leds/green breath 0640 system system +/sys/class/leds/green trigger 0640 system system +/sys/class/leds/blue delay_on 0640 system system +/sys/class/leds/blue delay_off 0640 system system +/sys/class/leds/blue breath 0640 system system +/sys/class/leds/blue trigger 0640 system system + +# NPU device +/dev/msm_npu 0644 system system + +# USB role switch +/sys/class/dual_role_usb/* data_role 0660 system system +/sys/class/dual_role_usb/* power_role 0660 system system +/sys/class/dual_role_usb/* mode 0660 system system + +#Memory Offline +/sys/devices/system/memory/memory* state 0660 system system + +/sys/devices/virtual/hdcp/msm_hdcp min_level_change 0664 system graphics + +# sys-fs display +/sys/class/graphics/fb* hpd 0664 system graphics +/sys/class/graphics/fb* res_info 0664 system graphics +/sys/class/graphics/fb* vendor_name 0664 system graphics +/sys/class/graphics/fb* product_description 0664 system graphics +/sys/class/graphics/fb* video_mode 0664 system graphics +/sys/class/graphics/fb* format_3d 0664 system graphics +/sys/class/graphics/fb* s3d_mode 0664 system graphics +/sys/class/graphics/fb* dynamic_fps 0664 system graphics +/sys/class/graphics/fb* msm_fb_dfps_mode 0664 system graphics +/sys/class/graphics/fb* hdr_stream 0664 system graphics +/sys/class/graphics/fb* cec/enable 0664 system graphics +/sys/class/graphics/fb* cec/logical_addr 0664 system graphics +/sys/class/graphics/fb* cec/rd_msg 0664 system graphics +/sys/class/graphics/fb* pa 0664 system graphics +/sys/class/graphics/fb* cec/wr_msg 0600 system graphics +/sys/class/graphics/fb* hdcp/tp 0664 system graphics +/sys/class/graphics/fb* hdcp2p2/min_level_change 0660 system graphics +/sys/class/graphics/fb* hdmi_audio_cb 0600 audioserver audio + +/sys/class/graphics/fb* lineptr_value 0664 system graphics +/sys/class/graphics/fb* msm_fb_persist_mode 0664 system graphics + +/sys/class/graphics/fb0 idle_time 0664 system graphics +/sys/class/graphics/fb0 dynamic_fps 0664 system graphics +/sys/class/graphics/fb0 dyn_pu 0664 system graphics +/sys/class/graphics/fb0 modes 0664 system graphics +/sys/class/graphics/fb0 mode 0664 system graphics +/sys/class/graphics/fb0 msm_cmd_autorefresh_en 0664 system graphics +*/ + +/sys/devices/platform/soc/ae00000.qcom,mdss_mdp power/control 0664 system graphics + +#asm330 sensor +#common sensors files +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* buffer/enable 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* buffer/length 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* buffer/watermark 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* discharded_samples 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* current_timestamp_clock 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* hwfifo_flush 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* hwfifo_watermark 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* hwfifo_watermark_max 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* mount_matrix 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* name 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* sampling_frequency 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* sampling_frequency_available 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_timestamp_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_timestamp_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_timestamp_type 0664 system system + +# standard iio accel attributes +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_scale_available 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_x_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_x_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_y_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_y_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_z_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_accel_z_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_x_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_x_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_x_type 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_y_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_y_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_y_type 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_z_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_z_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_accel_z_type 0664 system system + +# standard iio gyro attributes +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_scale_available 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_x_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_x_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_y_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_y_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_z_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_anglvel_z_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_x_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_x_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_x_type 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_y_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_y_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_y_type 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_z_en 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_z_index 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* scan_elements/in_anglvel_z_type 0664 system system + + +# standard iio temp attributes +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_temp_offset 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_temp_raw 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_temp_scale 0664 system system +/sys/devices/platform/soc/*.i2c/i2c-*/*-*/iio:device* in_temp_scale_available 0664 system system diff --git a/sensors/Android.bp b/sensors/Android.bp new file mode 100644 index 0000000..20e6427 --- /dev/null +++ b/sensors/Android.bp @@ -0,0 +1,49 @@ +// +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_binary { + name: "android.hardware.sensors@2.1-service.xiaomi_holi-multihal", + defaults: [ + "hidl_defaults", + ], + vendor: true, + relative_install_path: "hw", + srcs: [ + "service.cpp", + "HalProxy.cpp", + "HalProxyCallback.cpp", + ], + init_rc: ["android.hardware.sensors@2.1-service.xiaomi_holi-multihal.rc"], + vintf_fragments: ["android.hardware.sensors@2.1.xiaomi_holi-multihal.xml"], + header_libs: [ + "android.hardware.sensors@2.X-shared-utils", + ], + shared_libs: [ + "android.hardware.sensors@2.0", + "android.hardware.sensors@2.0-ScopedWakelock", + "android.hardware.sensors@2.1", + "libbase", + "libcutils", + "libfmq", + "libhidlbase", + "liblog", + "libpower", + "libutils", + ], + static_libs: [ + "android.hardware.sensors@1.0-convert", + "android.hardware.sensors@2.X-multihal", + ], +} diff --git a/sensors/HalProxy.cpp b/sensors/HalProxy.cpp new file mode 100644 index 0000000..1a73265 --- /dev/null +++ b/sensors/HalProxy.cpp @@ -0,0 +1,778 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "HalProxy.h" + +#include + +#include +#include "hardware_legacy/power.h" + +#include + +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace sensors { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::sensors::V1_0::Result; +using ::android::hardware::sensors::V2_0::EventQueueFlagBits; +using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits; +using ::android::hardware::sensors::V2_0::implementation::getTimeNow; +using ::android::hardware::sensors::V2_0::implementation::kWakelockTimeoutNs; + +typedef V2_0::implementation::ISensorsSubHal*(SensorsHalGetSubHalFunc)(uint32_t*); +typedef V2_1::implementation::ISensorsSubHal*(SensorsHalGetSubHalV2_1Func)(uint32_t*); + +static constexpr int32_t kBitsAfterSubHalIndex = 24; + +/** + * Set the subhal index as first byte of sensor handle and return this modified version. + * + * @param sensorHandle The sensor handle to modify. + * @param subHalIndex The index in the hal proxy of the sub hal this sensor belongs to. + * + * @return The modified sensor handle. + */ +int32_t setSubHalIndex(int32_t sensorHandle, size_t subHalIndex) { + return sensorHandle | (static_cast(subHalIndex) << kBitsAfterSubHalIndex); +} + +/** + * Extract the subHalIndex from sensorHandle. + * + * @param sensorHandle The sensorHandle to extract from. + * + * @return The subhal index. + */ +size_t extractSubHalIndex(int32_t sensorHandle) { + return static_cast(sensorHandle >> kBitsAfterSubHalIndex); +} + +/** + * Convert nanoseconds to milliseconds. + * + * @param nanos The nanoseconds input. + * + * @return The milliseconds count. + */ +int64_t msFromNs(int64_t nanos) { + constexpr int64_t nanosecondsInAMillsecond = 1000000; + return nanos / nanosecondsInAMillsecond; +} + +bool patchXiaomiPickupSensor(V2_1::SensorInfo& sensor) { + if (sensor.typeAsString != "xiaomi.sensor.pickup") { + return true; + } + + /* + * Implement only the wake-up version of this sensor. + */ + if (!(sensor.flags & V1_0::SensorFlagBits::WAKE_UP)) { + return false; + } + + sensor.type = V2_1::SensorType::PICK_UP_GESTURE; + sensor.typeAsString = SENSOR_STRING_TYPE_PICK_UP_GESTURE; + sensor.maxRange = 1; + + return true; +} + +HalProxy::HalProxy() { + const char* kMultiHalConfigFile = "/vendor/etc/sensors/hals.conf"; + initializeSubHalListFromConfigFile(kMultiHalConfigFile); + init(); +} + +HalProxy::HalProxy(std::vector& subHalList) { + for (ISensorsSubHalV2_0* subHal : subHalList) { + mSubHalList.push_back(std::make_unique(subHal)); + } + + init(); +} + +HalProxy::HalProxy(std::vector& subHalList, + std::vector& subHalListV2_1) { + for (ISensorsSubHalV2_0* subHal : subHalList) { + mSubHalList.push_back(std::make_unique(subHal)); + } + + for (ISensorsSubHalV2_1* subHal : subHalListV2_1) { + mSubHalList.push_back(std::make_unique(subHal)); + } + + init(); +} + +HalProxy::~HalProxy() { + stopThreads(); +} + +Return HalProxy::getSensorsList_2_1(ISensorsV2_1::getSensorsList_2_1_cb _hidl_cb) { + std::vector sensors; + for (const auto& iter : mSensors) { + sensors.push_back(iter.second); + } + _hidl_cb(sensors); + return Void(); +} + +Return HalProxy::getSensorsList(ISensorsV2_0::getSensorsList_cb _hidl_cb) { + std::vector sensors; + for (const auto& iter : mSensors) { + sensors.push_back(convertToOldSensorInfo(iter.second)); + } + _hidl_cb(sensors); + return Void(); +} + +Return HalProxy::setOperationMode(OperationMode mode) { + Result result = Result::OK; + size_t subHalIndex; + for (subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) { + result = mSubHalList[subHalIndex]->setOperationMode(mode); + if (result != Result::OK) { + ALOGE("setOperationMode failed for SubHal: %s", + mSubHalList[subHalIndex]->getName().c_str()); + break; + } + } + + if (result != Result::OK) { + // Reset the subhal operation modes that have been flipped + for (size_t i = 0; i < subHalIndex; i++) { + mSubHalList[i]->setOperationMode(mCurrentOperationMode); + } + } else { + mCurrentOperationMode = mode; + } + return result; +} + +Return HalProxy::activate(int32_t sensorHandle, bool enabled) { + if (!isSubHalIndexValid(sensorHandle)) { + return Result::BAD_VALUE; + } + return getSubHalForSensorHandle(sensorHandle) + ->activate(clearSubHalIndex(sensorHandle), enabled); +} + +Return HalProxy::initialize_2_1( + const ::android::hardware::MQDescriptorSync& eventQueueDescriptor, + const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, + const sp& sensorsCallback) { + sp dynamicCallback = + new ISensorsCallbackWrapperV2_1(sensorsCallback); + + // Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions. + auto eventQueue = + std::make_unique(eventQueueDescriptor, true /* resetPointers */); + std::unique_ptr queue = + std::make_unique(eventQueue); + + return initializeCommon(queue, wakeLockDescriptor, dynamicCallback); +} + +Return HalProxy::initialize( + const ::android::hardware::MQDescriptorSync& eventQueueDescriptor, + const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, + const sp& sensorsCallback) { + sp dynamicCallback = + new ISensorsCallbackWrapperV2_0(sensorsCallback); + + // Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions. + auto eventQueue = + std::make_unique(eventQueueDescriptor, true /* resetPointers */); + std::unique_ptr queue = + std::make_unique(eventQueue); + + return initializeCommon(queue, wakeLockDescriptor, dynamicCallback); +} + +Return HalProxy::initializeCommon( + std::unique_ptr& eventQueue, + const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, + const sp& sensorsCallback) { + Result result = Result::OK; + + stopThreads(); + resetSharedWakelock(); + + // So that the pending write events queue can be cleared safely and when we start threads + // again we do not get new events until after initialize resets the subhals. + disableAllSensors(); + + // Clears the queue if any events were pending write before. + mPendingWriteEventsQueue = std::queue, size_t>>(); + mSizePendingWriteEventsQueue = 0; + + // Clears previously connected dynamic sensors + mDynamicSensors.clear(); + + mDynamicSensorsCallback = sensorsCallback; + + // Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions. + mEventQueue = std::move(eventQueue); + + // Create the Wake Lock FMQ that is used by the framework to communicate whenever WAKE_UP + // events have been successfully read and handled by the framework. + mWakeLockQueue = + std::make_unique(wakeLockDescriptor, true /* resetPointers */); + + if (mEventQueueFlag != nullptr) { + EventFlag::deleteEventFlag(&mEventQueueFlag); + } + if (mWakelockQueueFlag != nullptr) { + EventFlag::deleteEventFlag(&mWakelockQueueFlag); + } + if (EventFlag::createEventFlag(mEventQueue->getEventFlagWord(), &mEventQueueFlag) != OK) { + result = Result::BAD_VALUE; + } + if (EventFlag::createEventFlag(mWakeLockQueue->getEventFlagWord(), &mWakelockQueueFlag) != OK) { + result = Result::BAD_VALUE; + } + if (!mDynamicSensorsCallback || !mEventQueue || !mWakeLockQueue || mEventQueueFlag == nullptr) { + result = Result::BAD_VALUE; + } + + mThreadsRun.store(true); + + mPendingWritesThread = std::thread(startPendingWritesThread, this); + mWakelockThread = std::thread(startWakelockThread, this); + + for (size_t i = 0; i < mSubHalList.size(); i++) { + Result currRes = mSubHalList[i]->initialize(this, this, i); + if (currRes != Result::OK) { + result = currRes; + ALOGE("Subhal '%s' failed to initialize.", mSubHalList[i]->getName().c_str()); + break; + } + } + + mCurrentOperationMode = OperationMode::NORMAL; + + return result; +} + +Return HalProxy::batch(int32_t sensorHandle, int64_t samplingPeriodNs, + int64_t maxReportLatencyNs) { + if (!isSubHalIndexValid(sensorHandle)) { + return Result::BAD_VALUE; + } + return getSubHalForSensorHandle(sensorHandle) + ->batch(clearSubHalIndex(sensorHandle), samplingPeriodNs, maxReportLatencyNs); +} + +Return HalProxy::flush(int32_t sensorHandle) { + if (!isSubHalIndexValid(sensorHandle)) { + return Result::BAD_VALUE; + } + return getSubHalForSensorHandle(sensorHandle)->flush(clearSubHalIndex(sensorHandle)); +} + +Return HalProxy::injectSensorData_2_1(const V2_1::Event& event) { + return injectSensorData(convertToOldEvent(event)); +} + +Return HalProxy::injectSensorData(const V1_0::Event& event) { + Result result = Result::OK; + if (mCurrentOperationMode == OperationMode::NORMAL && + event.sensorType != V1_0::SensorType::ADDITIONAL_INFO) { + ALOGE("An event with type != ADDITIONAL_INFO passed to injectSensorData while operation" + " mode was NORMAL."); + result = Result::BAD_VALUE; + } + if (result == Result::OK) { + V1_0::Event subHalEvent = event; + if (!isSubHalIndexValid(event.sensorHandle)) { + return Result::BAD_VALUE; + } + subHalEvent.sensorHandle = clearSubHalIndex(event.sensorHandle); + result = getSubHalForSensorHandle(event.sensorHandle) + ->injectSensorData(convertToNewEvent(subHalEvent)); + } + return result; +} + +Return HalProxy::registerDirectChannel(const SharedMemInfo& mem, + ISensorsV2_0::registerDirectChannel_cb _hidl_cb) { + if (mDirectChannelSubHal == nullptr) { + _hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */); + } else { + mDirectChannelSubHal->registerDirectChannel(mem, _hidl_cb); + } + return Return(); +} + +Return HalProxy::unregisterDirectChannel(int32_t channelHandle) { + Result result; + if (mDirectChannelSubHal == nullptr) { + result = Result::INVALID_OPERATION; + } else { + result = mDirectChannelSubHal->unregisterDirectChannel(channelHandle); + } + return result; +} + +Return HalProxy::configDirectReport(int32_t sensorHandle, int32_t channelHandle, + RateLevel rate, + ISensorsV2_0::configDirectReport_cb _hidl_cb) { + if (mDirectChannelSubHal == nullptr) { + _hidl_cb(Result::INVALID_OPERATION, -1 /* reportToken */); + } else if (sensorHandle == -1 && rate != RateLevel::STOP) { + _hidl_cb(Result::BAD_VALUE, -1 /* reportToken */); + } else { + // -1 denotes all sensors should be disabled + if (sensorHandle != -1) { + sensorHandle = clearSubHalIndex(sensorHandle); + } + mDirectChannelSubHal->configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb); + } + return Return(); +} + +Return HalProxy::debug(const hidl_handle& fd, const hidl_vec& /*args*/) { + if (fd.getNativeHandle() == nullptr || fd->numFds < 1) { + ALOGE("%s: missing fd for writing", __FUNCTION__); + return Void(); + } + + android::base::borrowed_fd writeFd = dup(fd->data[0]); + + std::ostringstream stream; + stream << "===HalProxy===" << std::endl; + stream << "Internal values:" << std::endl; + stream << " Threads are running: " << (mThreadsRun.load() ? "true" : "false") << std::endl; + int64_t now = getTimeNow(); + stream << " Wakelock timeout start time: " << msFromNs(now - mWakelockTimeoutStartTime) + << " ms ago" << std::endl; + stream << " Wakelock timeout reset time: " << msFromNs(now - mWakelockTimeoutResetTime) + << " ms ago" << std::endl; + // TODO(b/142969448): Add logging for history of wakelock acquisition per subhal. + stream << " Wakelock ref count: " << mWakelockRefCount << std::endl; + stream << " # of events on pending write writes queue: " << mSizePendingWriteEventsQueue + << std::endl; + stream << " Most events seen on pending write events queue: " + << mMostEventsObservedPendingWriteEventsQueue << std::endl; + if (!mPendingWriteEventsQueue.empty()) { + stream << " Size of events list on front of pending writes queue: " + << mPendingWriteEventsQueue.front().first.size() << std::endl; + } + stream << " # of non-dynamic sensors across all subhals: " << mSensors.size() << std::endl; + stream << " # of dynamic sensors across all subhals: " << mDynamicSensors.size() << std::endl; + stream << "SubHals (" << mSubHalList.size() << "):" << std::endl; + for (auto& subHal : mSubHalList) { + stream << " Name: " << subHal->getName() << std::endl; + stream << " Debug dump: " << std::endl; + android::base::WriteStringToFd(stream.str(), writeFd); + subHal->debug(fd, {}); + stream.str(""); + stream << std::endl; + } + android::base::WriteStringToFd(stream.str(), writeFd); + return Return(); +} + +Return HalProxy::onDynamicSensorsConnected(const hidl_vec& dynamicSensorsAdded, + int32_t subHalIndex) { + std::vector sensors; + { + std::lock_guard lock(mDynamicSensorsMutex); + for (SensorInfo sensor : dynamicSensorsAdded) { + if (!subHalIndexIsClear(sensor.sensorHandle)) { + ALOGE("Dynamic sensor added %s had sensorHandle with first byte not 0.", + sensor.name.c_str()); + } else { + sensor.sensorHandle = setSubHalIndex(sensor.sensorHandle, subHalIndex); + mDynamicSensors[sensor.sensorHandle] = sensor; + sensors.push_back(sensor); + } + } + } + mDynamicSensorsCallback->onDynamicSensorsConnected(sensors); + return Return(); +} + +Return HalProxy::onDynamicSensorsDisconnected( + const hidl_vec& dynamicSensorHandlesRemoved, int32_t subHalIndex) { + // TODO(b/143302327): Block this call until all pending events are flushed from queue + std::vector sensorHandles; + { + std::lock_guard lock(mDynamicSensorsMutex); + for (int32_t sensorHandle : dynamicSensorHandlesRemoved) { + if (!subHalIndexIsClear(sensorHandle)) { + ALOGE("Dynamic sensorHandle removed had first byte not 0."); + } else { + sensorHandle = setSubHalIndex(sensorHandle, subHalIndex); + if (mDynamicSensors.find(sensorHandle) != mDynamicSensors.end()) { + mDynamicSensors.erase(sensorHandle); + sensorHandles.push_back(sensorHandle); + } + } + } + } + mDynamicSensorsCallback->onDynamicSensorsDisconnected(sensorHandles); + return Return(); +} + +void HalProxy::initializeSubHalListFromConfigFile(const char* configFileName) { + std::ifstream subHalConfigStream(configFileName); + if (!subHalConfigStream) { + ALOGE("Failed to load subHal config file: %s", configFileName); + } else { + std::string subHalLibraryFile; + while (subHalConfigStream >> subHalLibraryFile) { + void* handle = getHandleForSubHalSharedObject(subHalLibraryFile); + if (handle == nullptr) { + ALOGE("dlopen failed for library: %s", subHalLibraryFile.c_str()); + } else { + SensorsHalGetSubHalFunc* sensorsHalGetSubHalPtr = + (SensorsHalGetSubHalFunc*)dlsym(handle, "sensorsHalGetSubHal"); + if (sensorsHalGetSubHalPtr != nullptr) { + std::function sensorsHalGetSubHal = + *sensorsHalGetSubHalPtr; + uint32_t version; + ISensorsSubHalV2_0* subHal = sensorsHalGetSubHal(&version); + if (version != SUB_HAL_2_0_VERSION) { + ALOGE("SubHal version was not 2.0 for library: %s", + subHalLibraryFile.c_str()); + } else { + ALOGV("Loaded SubHal from library: %s", subHalLibraryFile.c_str()); + mSubHalList.push_back(std::make_unique(subHal)); + } + } else { + SensorsHalGetSubHalV2_1Func* getSubHalV2_1Ptr = + (SensorsHalGetSubHalV2_1Func*)dlsym(handle, "sensorsHalGetSubHal_2_1"); + + if (getSubHalV2_1Ptr == nullptr) { + ALOGE("Failed to locate sensorsHalGetSubHal function for library: %s", + subHalLibraryFile.c_str()); + } else { + std::function sensorsHalGetSubHal_2_1 = + *getSubHalV2_1Ptr; + uint32_t version; + ISensorsSubHalV2_1* subHal = sensorsHalGetSubHal_2_1(&version); + if (version != SUB_HAL_2_1_VERSION) { + ALOGE("SubHal version was not 2.1 for library: %s", + subHalLibraryFile.c_str()); + } else { + ALOGV("Loaded SubHal from library: %s", subHalLibraryFile.c_str()); + mSubHalList.push_back(std::make_unique(subHal)); + } + } + } + } + } + } +} + +void HalProxy::initializeSensorList() { + for (size_t subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) { + auto result = mSubHalList[subHalIndex]->getSensorsList([&](const auto& list) { + for (SensorInfo sensor : list) { + if (!subHalIndexIsClear(sensor.sensorHandle)) { + ALOGE("SubHal sensorHandle's first byte was not 0"); + } else { + ALOGV("Loaded sensor: %s", sensor.name.c_str()); + sensor.sensorHandle = setSubHalIndex(sensor.sensorHandle, subHalIndex); + setDirectChannelFlags(&sensor, mSubHalList[subHalIndex]); + bool keep = patchXiaomiPickupSensor(sensor); + if (!keep) { + continue; + } + + mSensors[sensor.sensorHandle] = sensor; + } + } + }); + if (!result.isOk()) { + ALOGE("getSensorsList call failed for SubHal: %s", + mSubHalList[subHalIndex]->getName().c_str()); + } + } +} + +void* HalProxy::getHandleForSubHalSharedObject(const std::string& filename) { + static const std::string kSubHalShareObjectLocations[] = { + "", // Default locations will be searched +#ifdef __LP64__ + "/vendor/lib64/hw/", "/odm/lib64/hw/" +#else + "/vendor/lib/hw/", "/odm/lib/hw/" +#endif + }; + + for (const std::string& dir : kSubHalShareObjectLocations) { + void* handle = dlopen((dir + filename).c_str(), RTLD_NOW); + if (handle != nullptr) { + return handle; + } + } + return nullptr; +} + +void HalProxy::init() { + initializeSensorList(); +} + +void HalProxy::stopThreads() { + mThreadsRun.store(false); + if (mEventQueueFlag != nullptr && mEventQueue != nullptr) { + size_t numToRead = mEventQueue->availableToRead(); + std::vector events(numToRead); + mEventQueue->read(events.data(), numToRead); + mEventQueueFlag->wake(static_cast(EventQueueFlagBits::EVENTS_READ)); + } + if (mWakelockQueueFlag != nullptr && mWakeLockQueue != nullptr) { + uint32_t kZero = 0; + mWakeLockQueue->write(&kZero); + mWakelockQueueFlag->wake(static_cast(WakeLockQueueFlagBits::DATA_WRITTEN)); + } + mWakelockCV.notify_one(); + mEventQueueWriteCV.notify_one(); + if (mPendingWritesThread.joinable()) { + mPendingWritesThread.join(); + } + if (mWakelockThread.joinable()) { + mWakelockThread.join(); + } +} + +void HalProxy::disableAllSensors() { + for (const auto& sensorEntry : mSensors) { + int32_t sensorHandle = sensorEntry.first; + activate(sensorHandle, false /* enabled */); + } + std::lock_guard dynamicSensorsLock(mDynamicSensorsMutex); + for (const auto& sensorEntry : mDynamicSensors) { + int32_t sensorHandle = sensorEntry.first; + activate(sensorHandle, false /* enabled */); + } +} + +void HalProxy::startPendingWritesThread(HalProxy* halProxy) { + halProxy->handlePendingWrites(); +} + +void HalProxy::handlePendingWrites() { + // TODO(b/143302327): Find a way to optimize locking strategy maybe using two mutexes instead of + // one. + std::unique_lock lock(mEventQueueWriteMutex); + while (mThreadsRun.load()) { + mEventQueueWriteCV.wait( + lock, [&] { return !mPendingWriteEventsQueue.empty() || !mThreadsRun.load(); }); + if (mThreadsRun.load()) { + std::vector& pendingWriteEvents = mPendingWriteEventsQueue.front().first; + size_t numWakeupEvents = mPendingWriteEventsQueue.front().second; + size_t eventQueueSize = mEventQueue->getQuantumCount(); + size_t numToWrite = std::min(pendingWriteEvents.size(), eventQueueSize); + lock.unlock(); + if (!mEventQueue->writeBlocking( + pendingWriteEvents.data(), numToWrite, + static_cast(EventQueueFlagBits::EVENTS_READ), + static_cast(EventQueueFlagBits::READ_AND_PROCESS), + kPendingWriteTimeoutNs, mEventQueueFlag)) { + ALOGE("Dropping %zu events after blockingWrite failed.", numToWrite); + if (numWakeupEvents > 0) { + if (pendingWriteEvents.size() > eventQueueSize) { + decrementRefCountAndMaybeReleaseWakelock( + countNumWakeupEvents(pendingWriteEvents, eventQueueSize)); + } else { + decrementRefCountAndMaybeReleaseWakelock(numWakeupEvents); + } + } + } + lock.lock(); + mSizePendingWriteEventsQueue -= numToWrite; + if (pendingWriteEvents.size() > eventQueueSize) { + // TODO(b/143302327): Check if this erase operation is too inefficient. It will copy + // all the events ahead of it down to fill gap off array at front after the erase. + pendingWriteEvents.erase(pendingWriteEvents.begin(), + pendingWriteEvents.begin() + eventQueueSize); + } else { + mPendingWriteEventsQueue.pop(); + } + } + } +} + +void HalProxy::startWakelockThread(HalProxy* halProxy) { + halProxy->handleWakelocks(); +} + +void HalProxy::handleWakelocks() { + std::unique_lock lock(mWakelockMutex); + while (mThreadsRun.load()) { + mWakelockCV.wait(lock, [&] { return mWakelockRefCount > 0 || !mThreadsRun.load(); }); + if (mThreadsRun.load()) { + int64_t timeLeft; + if (sharedWakelockDidTimeout(&timeLeft)) { + resetSharedWakelock(); + } else { + uint32_t numWakeLocksProcessed; + lock.unlock(); + bool success = mWakeLockQueue->readBlocking( + &numWakeLocksProcessed, 1, 0, + static_cast(WakeLockQueueFlagBits::DATA_WRITTEN), timeLeft); + lock.lock(); + if (success) { + decrementRefCountAndMaybeReleaseWakelock( + static_cast(numWakeLocksProcessed)); + } + } + } + } + resetSharedWakelock(); +} + +bool HalProxy::sharedWakelockDidTimeout(int64_t* timeLeft) { + bool didTimeout; + int64_t duration = getTimeNow() - mWakelockTimeoutStartTime; + if (duration > kWakelockTimeoutNs) { + didTimeout = true; + } else { + didTimeout = false; + *timeLeft = kWakelockTimeoutNs - duration; + } + return didTimeout; +} + +void HalProxy::resetSharedWakelock() { + std::lock_guard lockGuard(mWakelockMutex); + decrementRefCountAndMaybeReleaseWakelock(mWakelockRefCount); + mWakelockTimeoutResetTime = getTimeNow(); +} + +void HalProxy::postEventsToMessageQueue(const std::vector& events, size_t numWakeupEvents, + V2_0::implementation::ScopedWakelock wakelock) { + size_t numToWrite = 0; + std::lock_guard lock(mEventQueueWriteMutex); + if (wakelock.isLocked()) { + incrementRefCountAndMaybeAcquireWakelock(numWakeupEvents); + } + if (mPendingWriteEventsQueue.empty()) { + numToWrite = std::min(events.size(), mEventQueue->availableToWrite()); + if (numToWrite > 0) { + if (mEventQueue->write(events.data(), numToWrite)) { + // TODO(b/143302327): While loop if mEventQueue->avaiableToWrite > 0 to possibly fit + // in more writes immediately + mEventQueueFlag->wake(static_cast(EventQueueFlagBits::READ_AND_PROCESS)); + } else { + numToWrite = 0; + } + } + } + size_t numLeft = events.size() - numToWrite; + if (numToWrite < events.size() && + mSizePendingWriteEventsQueue + numLeft <= kMaxSizePendingWriteEventsQueue) { + std::vector eventsLeft(events.begin() + numToWrite, events.end()); + mPendingWriteEventsQueue.push({eventsLeft, numWakeupEvents}); + mSizePendingWriteEventsQueue += numLeft; + mMostEventsObservedPendingWriteEventsQueue = + std::max(mMostEventsObservedPendingWriteEventsQueue, mSizePendingWriteEventsQueue); + mEventQueueWriteCV.notify_one(); + } +} + +bool HalProxy::incrementRefCountAndMaybeAcquireWakelock(size_t delta, + int64_t* timeoutStart /* = nullptr */) { + if (!mThreadsRun.load()) return false; + std::lock_guard lockGuard(mWakelockMutex); + if (mWakelockRefCount == 0) { + acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakelockName); + mWakelockCV.notify_one(); + } + mWakelockTimeoutStartTime = getTimeNow(); + mWakelockRefCount += delta; + if (timeoutStart != nullptr) { + *timeoutStart = mWakelockTimeoutStartTime; + } + return true; +} + +void HalProxy::decrementRefCountAndMaybeReleaseWakelock(size_t delta, + int64_t timeoutStart /* = -1 */) { + if (!mThreadsRun.load()) return; + std::lock_guard lockGuard(mWakelockMutex); + if (delta > mWakelockRefCount) { + ALOGE("Decrementing wakelock ref count by %zu when count is %zu", + delta, mWakelockRefCount); + } + if (timeoutStart == -1) timeoutStart = mWakelockTimeoutResetTime; + if (mWakelockRefCount == 0 || timeoutStart < mWakelockTimeoutResetTime) return; + mWakelockRefCount -= std::min(mWakelockRefCount, delta); + if (mWakelockRefCount == 0) { + release_wake_lock(kWakelockName); + } +} + +void HalProxy::setDirectChannelFlags(SensorInfo* sensorInfo, + std::shared_ptr subHal) { + bool sensorSupportsDirectChannel = + (sensorInfo->flags & (V1_0::SensorFlagBits::MASK_DIRECT_REPORT | + V1_0::SensorFlagBits::MASK_DIRECT_CHANNEL)) != 0; + if (mDirectChannelSubHal == nullptr && sensorSupportsDirectChannel) { + mDirectChannelSubHal = subHal; + } else if (mDirectChannelSubHal != nullptr && subHal != mDirectChannelSubHal) { + // disable direct channel capability for sensors in subHals that are not + // the only one we will enable + sensorInfo->flags &= ~(V1_0::SensorFlagBits::MASK_DIRECT_REPORT | + V1_0::SensorFlagBits::MASK_DIRECT_CHANNEL); + } +} + +std::shared_ptr HalProxy::getSubHalForSensorHandle(int32_t sensorHandle) { + return mSubHalList[extractSubHalIndex(sensorHandle)]; +} + +bool HalProxy::isSubHalIndexValid(int32_t sensorHandle) { + return extractSubHalIndex(sensorHandle) < mSubHalList.size(); +} + +size_t HalProxy::countNumWakeupEvents(const std::vector& events, size_t n) { + size_t numWakeupEvents = 0; + for (size_t i = 0; i < n; i++) { + int32_t sensorHandle = events[i].sensorHandle; + if (mSensors[sensorHandle].flags & static_cast(V1_0::SensorFlagBits::WAKE_UP)) { + numWakeupEvents++; + } + } + return numWakeupEvents; +} + +int32_t HalProxy::clearSubHalIndex(int32_t sensorHandle) { + return sensorHandle & (~kSensorHandleSubHalIndexMask); +} + +bool HalProxy::subHalIndexIsClear(int32_t sensorHandle) { + return (sensorHandle & kSensorHandleSubHalIndexMask) == 0; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace sensors +} // namespace hardware +} // namespace android diff --git a/sensors/HalProxyCallback.cpp b/sensors/HalProxyCallback.cpp new file mode 100644 index 0000000..122c382 --- /dev/null +++ b/sensors/HalProxyCallback.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "HalProxyCallback.h" + +#include + +namespace android { +namespace hardware { +namespace sensors { +namespace V2_0 { +namespace implementation { + +static constexpr int32_t kBitsAfterSubHalIndex = 24; + +/** + * Set the subhal index as first byte of sensor handle and return this modified version. + * + * @param sensorHandle The sensor handle to modify. + * @param subHalIndex The index in the hal proxy of the sub hal this sensor belongs to. + * + * @return The modified sensor handle. + */ +int32_t setSubHalIndex(int32_t sensorHandle, size_t subHalIndex) { + return sensorHandle | (static_cast(subHalIndex) << kBitsAfterSubHalIndex); +} + +void HalProxyCallbackBase::postEvents(const std::vector& events, + ScopedWakelock wakelock) { + if (events.empty() || !mCallback->areThreadsRunning()) return; + size_t numWakeupEvents; + std::vector processedEvents = processEvents(events, &numWakeupEvents); + if (numWakeupEvents > 0) { + ALOG_ASSERT(wakelock.isLocked(), + "Wakeup events posted while wakelock unlocked for subhal" + " w/ index %" PRId32 ".", + mSubHalIndex); + } else { + ALOG_ASSERT(!wakelock.isLocked(), + "No Wakeup events posted but wakelock locked for subhal" + " w/ index %" PRId32 ".", + mSubHalIndex); + } + mCallback->postEventsToMessageQueue(processedEvents, numWakeupEvents, std::move(wakelock)); +} + +ScopedWakelock HalProxyCallbackBase::createScopedWakelock(bool lock) { + ScopedWakelock wakelock(mRefCounter, lock); + return wakelock; +} + +std::vector HalProxyCallbackBase::processEvents(const std::vector& events, + size_t* numWakeupEvents) const { + *numWakeupEvents = 0; + std::vector eventsOut; + for (V2_1::Event event : events) { + event.sensorHandle = setSubHalIndex(event.sensorHandle, mSubHalIndex); + const V2_1::SensorInfo& sensor = mCallback->getSensorInfo(event.sensorHandle); + + if (sensor.type == V2_1::SensorType::PICK_UP_GESTURE + && event.u.scalar != 1) { + continue; + } + + if ((sensor.flags & V1_0::SensorFlagBits::WAKE_UP) != 0) { + (*numWakeupEvents)++; + } + eventsOut.push_back(event); + } + return eventsOut; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace sensors +} // namespace hardware +} // namespace android diff --git a/sensors/android.hardware.sensors@2.1-service.xiaomi_holi-multihal.rc b/sensors/android.hardware.sensors@2.1-service.xiaomi_holi-multihal.rc new file mode 100644 index 0000000..c5a14bb --- /dev/null +++ b/sensors/android.hardware.sensors@2.1-service.xiaomi_holi-multihal.rc @@ -0,0 +1,7 @@ +service vendor.sensors-hal-2-1-multihal /vendor/bin/hw/android.hardware.sensors@2.1-service.xiaomi_holi-multihal + class hal + user system + group system wakelock context_hub + writepid /dev/cpuset/system-background/tasks + capabilities BLOCK_SUSPEND + rlimit rtprio 10 10 diff --git a/sensors/android.hardware.sensors@2.1.xiaomi_holi-multihal.xml b/sensors/android.hardware.sensors@2.1.xiaomi_holi-multihal.xml new file mode 100644 index 0000000..18bd3ae --- /dev/null +++ b/sensors/android.hardware.sensors@2.1.xiaomi_holi-multihal.xml @@ -0,0 +1,11 @@ + + + android.hardware.sensors + hwbinder + 2.1 + + ISensors + default + + + diff --git a/sensors/service.cpp b/sensors/service.cpp new file mode 100644 index 0000000..d68d9a3 --- /dev/null +++ b/sensors/service.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "HalProxy.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::hardware::sensors::V2_1::ISensors; +using android::hardware::sensors::V2_1::implementation::HalProxyV2_1; + +int main(int /* argc */, char** /* argv */) { + configureRpcThreadpool(1, true); + + android::sp halProxy = new HalProxyV2_1(); + if (halProxy->registerAsService() != ::android::OK) { + ALOGE("Failed to register Sensors HAL instance"); + return -1; + } + + joinRpcThreadpool(); + return 1; // joinRpcThreadpool shouldn't exit +} diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts new file mode 100644 index 0000000..3ffbc81 --- /dev/null +++ b/sepolicy/private/file_contexts @@ -0,0 +1,2 @@ +# Dev nodes +/dev/stune(/.*)? u:object_r:cgroup:s0 diff --git a/sepolicy/public/attributes b/sepolicy/public/attributes new file mode 100644 index 0000000..c5a79e7 --- /dev/null +++ b/sepolicy/public/attributes @@ -0,0 +1,3 @@ +attribute hal_mlipay; +attribute hal_mlipay_client; +attribute hal_mlipay_server; diff --git a/sepolicy/public/property.te b/sepolicy/public/property.te new file mode 100644 index 0000000..72d3996 --- /dev/null +++ b/sepolicy/public/property.te @@ -0,0 +1,5 @@ +# Fingerprint +vendor_public_prop(vendor_fp_prop) + +# Mlipay +vendor_public_prop(vendor_mlipay_prop) diff --git a/sepolicy/public/property_contexts b/sepolicy/public/property_contexts new file mode 100644 index 0000000..3d3b2d6 --- /dev/null +++ b/sepolicy/public/property_contexts @@ -0,0 +1,6 @@ +# Camera +camera. u:object_r:vendor_camera_prop:s0 + +# Fingerprint +sys.fp.vendor u:object_r:vendor_fp_prop:s0 + diff --git a/sepolicy/vendor/adsprpcd.te b/sepolicy/vendor/adsprpcd.te new file mode 100644 index 0000000..58fe3e7 --- /dev/null +++ b/sepolicy/vendor/adsprpcd.te @@ -0,0 +1 @@ +r_dir_file(vendor_adsprpcd, vendor_sysfs_graphics) diff --git a/sepolicy/vendor/app.te b/sepolicy/vendor/app.te new file mode 100644 index 0000000..60325ab --- /dev/null +++ b/sepolicy/vendor/app.te @@ -0,0 +1 @@ +get_prop({ appdomain -isolated_app }, vendor_mlipay_prop) diff --git a/sepolicy/vendor/batterysecret.te b/sepolicy/vendor/batterysecret.te new file mode 100644 index 0000000..b55fc19 --- /dev/null +++ b/sepolicy/vendor/batterysecret.te @@ -0,0 +1,49 @@ +type batterysecret, domain; +type batterysecret_exec, exec_type, vendor_file_type, file_type; +init_daemon_domain(batterysecret) + +r_dir_file(batterysecret, cgroup) +r_dir_file(batterysecret, mnt_vendor_file) +r_dir_file(batterysecret, vendor_sysfs_battery_supply) +r_dir_file(batterysecret, sysfs_batteryinfo) +r_dir_file(batterysecret, sysfs_type) +r_dir_file(batterysecret, vendor_sysfs_usb_supply) +r_dir_file(batterysecret, vendor_sysfs_usbpd_device) + +allow batterysecret { + mnt_vendor_file + persist_subsys_file + rootfs +}:dir rw_dir_perms; + +allow batterysecret { + persist_subsys_file + sysfs + vendor_sysfs_battery_supply + sysfs_usb + vendor_sysfs_usb_supply + vendor_sysfs_usbpd_device +}:file w_file_perms; + +allow batterysecret kmsg_device:chr_file rw_file_perms; + +allow batterysecret self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl; + +allow batterysecret self:global_capability_class_set { + sys_tty_config + sys_boot +}; + +allow batterysecret self:capability { + chown + fsetid +}; + +allow batterysecret { + system_suspend_hwservice + hidl_manager_hwservice +}:hwservice_manager find; + +binder_call(batterysecret, system_suspend_server) + +wakelock_use(batterysecret) \ No newline at end of file diff --git a/sepolicy/vendor/device.te b/sepolicy/vendor/device.te new file mode 100644 index 0000000..99f0186 --- /dev/null +++ b/sepolicy/vendor/device.te @@ -0,0 +1,8 @@ +# Audio device +type sound_device, dev_type; + +# Fingerprint device +type vendor_fingerprint_device, dev_type; + +# IR device +type ir_spi_device, dev_type; diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te new file mode 100644 index 0000000..8faaa33 --- /dev/null +++ b/sepolicy/vendor/file.te @@ -0,0 +1,17 @@ +# Audio +type audio_socket, file_type; + +# Battery +type persist_subsys_file, vendor_persist_type, file_type; + +# Camera +type camera_persist_file, vendor_persist_type, file_type; + +# Fingerprint +type vendor_fingerprint_data_file, data_file_type, file_type; + +# Thermal +type thermal_data_file, data_file_type, file_type; + +# Touchpanel +type proc_touchpanel, fs_type, proc_type; diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts new file mode 100644 index 0000000..7afaa3a --- /dev/null +++ b/sepolicy/vendor/file_contexts @@ -0,0 +1,56 @@ + # Audio +/dev/socket/audio_hw_socket u:object_r:audio_socket:s0 +/dev/elliptic(.*)? u:object_r:sound_device:s0 +/mnt/vendor/persist/audio/cali_test.bin u:object_r:vendor_persist_audio_file:s0 +/mnt/vendor/persist/audio/fsm_calib.bin u:object_r:vendor_persist_audio_file:s0 +/mnt/vendor/persist/audio/aw_cali.bin u:object_r:vendor_persist_audio_file:s0 + +# Battery +/vendor/bin/batterysecret u:object_r:batterysecret_exec:s0 +/mnt/vendor/persist/subsys(/.*)? u:object_r:persist_subsys_file:s0 + +# Bluetooth +/vendor/bin/init\.mi\.btmac\.sh u:object_r:vendor_qti_init_shell_exec:s0 + +# Camera +/mnt/vendor/persist/camera(/.*)? u:object_r:camera_persist_file:s0 + +# Fingerprint +/dev/goodix_fp u:object_r:vendor_fingerprint_device:s0 +/dev/silead_fp u:object_r:vendor_fingerprint_device:s0 +/dev/silead_s.* u:object_r:vendor_fingerprint_device:s0 +/dev/silead_stub u:object_r:vendor_fingerprint_device:s0 +/dev/spidev.* u:object_r:vendor_fingerprint_device:s0 +/mnt/vendor/persist/silead(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/mnt/vendor/persist/goodix(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/data/vendor/fpc(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/data/vendor/fpdump(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/data/vendor/goodix(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/data/vendor/goodix/gf_data(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/data/vendor/silead(/.*)? u:object_r:vendor_fingerprint_data_file:s0 +/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2.1-service\.xiaomi_holi u:object_r:hal_fingerprint_default_exec:s0 +/vendor/bin/hw/vendor\.silead\.hardware\.fingerprintext@1\.0-service u:object_r:hal_fingerprint_default_exec:s0 + +# IR +/dev/ir_spi u:object_r:ir_spi_device:s0 + +# Mlipay +/vendor/bin/mlipayd@1.1 u:object_r:hal_mlipay_default_exec:s0 + +# NFC +/dev/pn553 u:object_r:nfc_device:s0 +/dev/pn54x u:object_r:nfc_device:s0 + +# Sensors +/vendor/bin/hw/android\.hardware\.sensors@2.1-service\.xiaomi_holi-multihal u:object_r:hal_sensors_default_exec:s0 + +# Thermal +/data/vendor/thermal(/.*)? u:object_r:thermal_data_file:s0 +/vendor/bin/mi_thermald u:object_r:mi_thermald_exec:s0 + +# Vibrator +/vendor/bin/hw/vendor\.qti\.hardware\.vibrator\.service\.xiaomi_holi u:object_r:hal_vibrator_default_exec:s0 + +# Xiaomi MAC +/data/vendor/mac_addr(/.*)? u:object_r:vendor_wifi_vendor_data_file:s0 +/data/vendor/wlan_logs(/.*)? u:object_r:vendor_wifi_vendor_data_file:s0 diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts new file mode 100644 index 0000000..80aa773 --- /dev/null +++ b/sepolicy/vendor/genfs_contexts @@ -0,0 +1,58 @@ +# Battery +genfscon sysfs /devices/platform/soc/soc:qcom_wt_chg/power_supply u:object_r:vendor_sysfs_battery_supply:s0 +genfscon sysfs /devices/platform/soc/soc:qcom_wt_chg/power_supply/battery u:object_r:vendor_sysfs_battery_supply:s0 + +# Fingerprint +genfscon sysfs /devices/platform/soc/soc:fpc1020 u:object_r:vendor_sysfs_fingerprint:s0 +genfscon sysfs /devices/platform/soc/soc:goodix_fp u:object_r:vendor_sysfs_fingerprint:s0 +genfscon sysfs /devices/platform/soc/soc:silead_fp u:object_r:vendor_sysfs_fingerprint:s0 + +# SSR +genfscon sysfs /devices/platform/soc/a400000.qcom,lpass/subsys[0-9]+/name u:object_r:vendor_sysfs_ssr:s0 +genfscon sysfs /devices/platform/soc/a400000.qcom,lpass/subsys[0-9]+/restart_level u:object_r:vendor_sysfs_ssr_toggle:s0 +genfscon sysfs /devices/platform/soc/b000000.qcom,turing/subsys[0-9]+/name u:object_r:vendor_sysfs_ssr:s0 +genfscon sysfs /devices/platform/soc/b000000.qcom,turing/subsys[0-9]+/restart_level u:object_r:vendor_sysfs_ssr_toggle:s0 +genfscon sysfs /devices/platform/soc/6000000.qcom,mss/subsys[0-9]+/name u:object_r:vendor_sysfs_ssr:s0 +genfscon sysfs /devices/platform/soc/6000000.qcom,mss/subsys[0-9]+/restart_level u:object_r:vendor_sysfs_ssr_toggle:s0 +genfscon sysfs /devices/platform/soc/5ab0000.qcom,venus/subsys[0-9]+/name u:object_r:vendor_sysfs_ssr:s0 +genfscon sysfs /devices/platform/soc/5ab0000.qcom,venus/subsys[0-9]+/restart_level u:object_r:vendor_sysfs_ssr_toggle:s0 + +# Touchpanel +genfscon proc /tp_gesture u:object_r:proc_touchpanel:s0 + +# Wakeup nodes +genfscon sysfs /devices/platform/soc/soc:goodix_fp/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:silead_fp/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,smp2p-adsp/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,smp2p-modem/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4a80000.i2c/i2c-4/4-0066/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4a80000.i2c/i2c-4/4-0055/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4a80000.i2c/i2c-4/4-005a/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4c90000.i2c/i2c-3/3-0066/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4c90000.i2c/i2c-3/3-0028/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4c90000.i2c/i2c-3/3-004e/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4c90000.i2c/i2c-3/3-006a/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,smp2p-cdsp/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,ipa_fws/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,ipa_fws/subsys3/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,msm-audio-apr/soc:qcom,msm-audio-apr:qcom,q6core-audio/soc:qcom,msm-audio-apr:qcom,q6core-audio:bolero-cdc/va-macro/va_swr_ctrl/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/6000000.qcom,mss/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/6000000.qcom,mss/subsys2/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/b000000.qcom,turing/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/b000000.qcom,turing/subsys1/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4a84000.qcom,qup_uart/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:gpio_keys/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/a400000.qcom,lpass/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/a400000.qcom,lpass/subsys0/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,kgsl-hyp/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,kgsl-hyp/subsys4/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom_wt_chg/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/1628000.qcom,msm-eud/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/5ab0000.qcom,venus/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/5ab0000.qcom,venus/subsys5/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/5800000.qcom,ipa/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/c800000.qcom,icnss/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,smp2p_sleepstate/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/4e00000.ssusb/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/1c40000.qcom,spmi/spmi-0/spmi0-00/1c40000.qcom,spmi:qcom,pm6125@0:qcom,power-on@800/wakeup u:object_r:sysfs_wakeup:s0 +genfscon sysfs /devices/platform/soc/1c40000.qcom,spmi/spmi-0/spmi0-06/1c40000.qcom,spmi:qcom,pmk8350@0:rtc@6100/wakeup u:object_r:sysfs_wakeup:s0 diff --git a/sepolicy/vendor/hal_audio_default.te b/sepolicy/vendor/hal_audio_default.te new file mode 100644 index 0000000..7e6e5a4 --- /dev/null +++ b/sepolicy/vendor/hal_audio_default.te @@ -0,0 +1,13 @@ +# Allow hal_audio_default to read vendor_persist_audio_file +r_dir_file(hal_audio_default, vendor_persist_audio_file) + +r_dir_file(hal_audio_default, sysfs) + +binder_call(hal_audio_default, system_suspend_server) + +allow hal_audio_default system_suspend_hwservice:hwservice_manager find; + +set_prop(hal_audio_default, vendor_audio_prop) + +allow hal_audio_default audio_socket:sock_file rw_file_perms; +allow hal_audio_default sound_device:chr_file rw_file_perms; diff --git a/sepolicy/vendor/hal_bluetooth_default.te b/sepolicy/vendor/hal_bluetooth_default.te new file mode 100644 index 0000000..82c6ef2 --- /dev/null +++ b/sepolicy/vendor/hal_bluetooth_default.te @@ -0,0 +1,6 @@ +# Allow hal_bluetooth_default to read files in vendor_wifi_vendor_data_file +r_dir_file(hal_bluetooth_default, vendor_wifi_vendor_data_file) +allow hal_bluetooth_default vendor_wifi_vendor_data_file:dir rw_dir_perms; +allow hal_bluetooth_default vendor_wifi_vendor_data_file:file create_file_perms; + +get_prop(hal_bluetooth_default, vendor_wifi_prop) diff --git a/sepolicy/vendor/hal_bootctl_default.te b/sepolicy/vendor/hal_bootctl_default.te new file mode 100644 index 0000000..e5c73b6 --- /dev/null +++ b/sepolicy/vendor/hal_bootctl_default.te @@ -0,0 +1 @@ +allow hal_bootctl_default vendor_uefi_block_device:blk_file getattr; diff --git a/sepolicy/vendor/hal_camera_default.te b/sepolicy/vendor/hal_camera_default.te new file mode 100644 index 0000000..d97b6ee --- /dev/null +++ b/sepolicy/vendor/hal_camera_default.te @@ -0,0 +1,2 @@ +r_dir_file(hal_camera_default, camera_persist_file) +set_prop(hal_camera_default, vendor_camera_sensor_prop) diff --git a/sepolicy/vendor/hal_fingerprint_default.te b/sepolicy/vendor/hal_fingerprint_default.te new file mode 100644 index 0000000..55c920f --- /dev/null +++ b/sepolicy/vendor/hal_fingerprint_default.te @@ -0,0 +1,37 @@ +# Binder +allow hal_fingerprint_default vendor_hal_perf_default:binder call; +allow hal_fingerprint_default vendor_hal_perf_hwservice:hwservice_manager find; + +# Props +set_prop(hal_fingerprint_default, vendor_fp_prop) +get_prop(system_server, vendor_fp_prop); + +# Sysfs +allow hal_fingerprint_default { + sysfs_rtc + vendor_sysfs_fingerprint + vendor_sysfs_spss +}: file rw_file_perms; + +allow hal_fingerprint_default { + input_device + sysfs_rtc + vendor_sysfs_fingerprint + vendor_sysfs_spss +}: dir r_dir_perms; + +# Dev nodes +allow hal_fingerprint_default { + input_device + tee_device + uhid_device + vendor_fingerprint_device +}: chr_file rw_file_perms; + +# Data +allow hal_fingerprint_default vendor_fingerprint_data_file:dir rw_dir_perms; +allow hal_fingerprint_default vendor_fingerprint_data_file:file create_file_perms; + +allow hal_fingerprint_default self:netlink_socket create_socket_perms_no_ioctl; + +r_dir_file(hal_fingerprint_default, firmware_file) diff --git a/sepolicy/vendor/hal_health_default.te b/sepolicy/vendor/hal_health_default.te new file mode 100644 index 0000000..6cecf70 --- /dev/null +++ b/sepolicy/vendor/hal_health_default.te @@ -0,0 +1,2 @@ +allow hal_health_default sysfs_wakeup:dir r_dir_perms; +allow hal_health_default sysfs_wakeup:file r_file_perms; diff --git a/sepolicy/vendor/hal_ir_default.te b/sepolicy/vendor/hal_ir_default.te new file mode 100644 index 0000000..46663b7 --- /dev/null +++ b/sepolicy/vendor/hal_ir_default.te @@ -0,0 +1 @@ +allow hal_ir_default ir_spi_device:chr_file rw_file_perms; diff --git a/sepolicy/vendor/hal_mlipay.te b/sepolicy/vendor/hal_mlipay.te new file mode 100644 index 0000000..5f4787f --- /dev/null +++ b/sepolicy/vendor/hal_mlipay.te @@ -0,0 +1,22 @@ +type hal_mlipay_hwservice, hwservice_manager_type; + +type hal_mlipay_default, domain; +hal_server_domain(hal_mlipay_default, hal_mlipay) + +type hal_mlipay_default_exec, exec_type, vendor_file_type, file_type; +init_daemon_domain(hal_mlipay_default) + +# Allow hwbinder call from hal client to server +binder_call(hal_mlipay_client, hal_mlipay_server) + +# Add hwservice related rules +add_hwservice(hal_mlipay_server, hal_mlipay_hwservice) +allow hal_mlipay_client hal_mlipay_hwservice:hwservice_manager find; + +allow hal_mlipay_default tee_device:chr_file rw_file_perms; +allow hal_mlipay_default ion_device:chr_file r_file_perms; + +r_dir_file(hal_mlipay_default, firmware_file) +set_prop(hal_mlipay_default, vendor_mlipay_prop); + +get_prop(hal_mlipay_default, vendor_fp_prop) diff --git a/sepolicy/vendor/hal_nfc_default.te b/sepolicy/vendor/hal_nfc_default.te new file mode 100644 index 0000000..9486137 --- /dev/null +++ b/sepolicy/vendor/hal_nfc_default.te @@ -0,0 +1,2 @@ +allow hal_nfc_default vendor_nfc_vendor_data_file:dir create_dir_perms; +allow hal_nfc_default vendor_nfc_vendor_data_file:file create_file_perms; diff --git a/sepolicy/vendor/hal_perf_default.te b/sepolicy/vendor/hal_perf_default.te new file mode 100644 index 0000000..5d19e84 --- /dev/null +++ b/sepolicy/vendor/hal_perf_default.te @@ -0,0 +1,5 @@ +allow vendor_hal_perf_default hal_audio_default:dir r_dir_perms; +allow vendor_hal_perf_default hal_audio_default:file r_file_perms; +allow vendor_hal_perf_default hal_fingerprint_default:dir r_dir_perms; +allow vendor_hal_perf_default hal_fingerprint_default:file r_file_perms; +allow vendor_hal_perf_default hal_camera_default:dir r_dir_perms; diff --git a/sepolicy/vendor/hal_power_default.te b/sepolicy/vendor/hal_power_default.te new file mode 100644 index 0000000..d9ef52d --- /dev/null +++ b/sepolicy/vendor/hal_power_default.te @@ -0,0 +1,3 @@ +# Allow hal_power_default to write to dt2w node +allow hal_power_default proc_touchpanel:dir search; +allow hal_power_default proc_touchpanel:file rw_file_perms; diff --git a/sepolicy/vendor/hal_sensors_default.te b/sepolicy/vendor/hal_sensors_default.te new file mode 100644 index 0000000..1d3339e --- /dev/null +++ b/sepolicy/vendor/hal_sensors_default.te @@ -0,0 +1,10 @@ +binder_call(hal_sensors_default, hal_audio_default) + +hal_client_domain(hal_sensors_default, hal_audio) + +allow hal_sensors_default audio_socket:sock_file rw_file_perms; +allow hal_sensors_default socket_device:sock_file rw_file_perms; +allow hal_sensors_default sound_device:chr_file rw_file_perms; +allow hal_sensors_default iio_device:chr_file rw_file_perms; + +get_prop(hal_sensors_default, vendor_adsprpc_prop) diff --git a/sepolicy/vendor/hal_wifi_default.te b/sepolicy/vendor/hal_wifi_default.te new file mode 100644 index 0000000..c6580df --- /dev/null +++ b/sepolicy/vendor/hal_wifi_default.te @@ -0,0 +1 @@ +allow hal_wifi_default self:capability sys_module; diff --git a/sepolicy/vendor/hwservice_contexts b/sepolicy/vendor/hwservice_contexts new file mode 100644 index 0000000..7af07e3 --- /dev/null +++ b/sepolicy/vendor/hwservice_contexts @@ -0,0 +1,15 @@ +# Fingerprint +com.fingerprints.extension::IFingerprintSensorTest u:object_r:hal_fingerprint_hwservice:s0 +com.fingerprints.extension::IFingerprintNavigation u:object_r:hal_fingerprint_hwservice:s0 +com.fingerprints.extension::IFingerprintEngineering u:object_r:hal_fingerprint_hwservice:s0 +vendor.goodix.hardware.biometrics.fingerprint::IGoodixFingerprintDaemon u:object_r:hal_fingerprint_hwservice:s0 +vendor.goodix.hardware.biometrics.fingerprint::IGoodixFingerprintDaemonExt u:object_r:hal_fingerprint_hwservice:s0 +vendor.silead.hardware.fingerprintext::ISileadFingerprint u:object_r:hal_fingerprint_hwservice:s0 +vendor.xiaomi.hardware.fingerprintextension::IXiaomiFingerprint u:object_r:hal_fingerprint_hwservice:s0 + +# Mlipay +vendor.xiaomi.hardware.mlipay::IMlipayService u:object_r:hal_mlipay_hwservice:s0 + +# NFC +vendor.nxp.nxpnfc::INxpNfc u:object_r:hal_nfc_hwservice:s0 +vendor.nxp.nxpnfclegacy::INxpNfcLegacy u:object_r:hal_nfc_hwservice:s0 diff --git a/sepolicy/vendor/mi_thermald.te b/sepolicy/vendor/mi_thermald.te new file mode 100644 index 0000000..4209b38 --- /dev/null +++ b/sepolicy/vendor/mi_thermald.te @@ -0,0 +1,35 @@ +type mi_thermald, domain; +type mi_thermald_exec, exec_type, vendor_file_type, file_type; + +init_daemon_domain(mi_thermald) + +set_prop(mi_thermald, vendor_thermal_normal_prop) + +allow mi_thermald thermal_data_file:dir rw_dir_perms; +allow mi_thermald thermal_data_file:file create_file_perms; + +allow mi_thermald self:capability { fsetid sys_boot }; +allow mi_thermald mi_thermald:capability { chown fowner }; +allow mi_thermald mi_thermald:capability2 { wake_alarm block_suspend }; + +allow mi_thermald sysfs_devices_system_cpu:file rw_file_perms; + +r_dir_file(mi_thermald, sysfs_thermal) +allow mi_thermald sysfs_thermal:file w_file_perms; + +r_dir_file(mi_thermald, sysfs) +allow mi_thermald sysfs:file w_file_perms; + +r_dir_file(mi_thermald, sysfs_leds) + +allow mi_thermald vendor_sysfs_kgsl:dir r_dir_perms; +allow mi_thermald vendor_sysfs_kgsl:file rw_file_perms; +allow mi_thermald vendor_sysfs_kgsl:lnk_file r_file_perms; + +allow mi_thermald vendor_sysfs_battery_supply:dir r_dir_perms; +allow mi_thermald vendor_sysfs_battery_supply:file rw_file_perms; +allow mi_thermald vendor_sysfs_battery_supply:lnk_file r_file_perms; + +allow mi_thermald vendor_sysfs_graphics:dir r_dir_perms; +allow mi_thermald vendor_sysfs_graphics:file rw_file_perms; +allow mi_thermald vendor_sysfs_graphics:lnk_file r_file_perms; \ No newline at end of file diff --git a/sepolicy/vendor/property.te b/sepolicy/vendor/property.te new file mode 100644 index 0000000..d647ff7 --- /dev/null +++ b/sepolicy/vendor/property.te @@ -0,0 +1,5 @@ +# Camera +vendor_internal_prop(vendor_camera_sensor_prop); + +# Thermal +vendor_internal_prop(vendor_thermal_normal_prop); diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts new file mode 100644 index 0000000..00a5068 --- /dev/null +++ b/sepolicy/vendor/property_contexts @@ -0,0 +1,26 @@ +# Camera +persist.camera. u:object_r:vendor_camera_prop:s0 +ro.boot.camera.config u:object_r:vendor_camera_sensor_prop:s0 +vendor.camera.config. u:object_r:vendor_camera_sensor_prop:s0 + +# Fingerprint +persist.vendor.sys.fp. u:object_r:vendor_fp_prop:s0 +ro.hardware.fp. u:object_r:vendor_fp_prop:s0 +vendor.fps_hal. u:object_r:vendor_fp_prop:s0 +vendor.silead.fp.ext. u:object_r:vendor_fp_prop:s0 + +# Mlipay +persist.vendor.sys.pay. u:object_r:vendor_mlipay_prop:s0 +persist.vendor.sys.provision.status u:object_r:vendor_mlipay_prop:s0 + +# RIL +odm.ril.radio.status. u:object_r:vendor_radio_prop:s0 +odm.ril.radio.status.sim1 u:object_r:vendor_radio_prop:s0 +odm.ril.radio.status.sim2 u:object_r:vendor_radio_prop:s0 + +# Thermal +vendor.sys.thermal. u:object_r:vendor_thermal_normal_prop:s0 + +# Wi-Fi +ro.vendor.ril.oem.btmac u:object_r:vendor_wifi_prop:s0 +ro.vendor.ril.oem.wifimac u:object_r:vendor_wifi_prop:s0 diff --git a/sepolicy/vendor/qti_init_shell.te b/sepolicy/vendor/qti_init_shell.te new file mode 100644 index 0000000..0d6641f --- /dev/null +++ b/sepolicy/vendor/qti_init_shell.te @@ -0,0 +1 @@ +allow vendor_qti_init_shell proc_page_cluster:file rw_file_perms; diff --git a/sepolicy/vendor/recovery.te b/sepolicy/vendor/recovery.te new file mode 100644 index 0000000..afc4845 --- /dev/null +++ b/sepolicy/vendor/recovery.te @@ -0,0 +1 @@ +allow recovery pstorefs:dir r_dir_perms; diff --git a/sepolicy/vendor/sensors.te b/sepolicy/vendor/sensors.te new file mode 100644 index 0000000..0b0d84d --- /dev/null +++ b/sepolicy/vendor/sensors.te @@ -0,0 +1 @@ +r_dir_file(vendor_sensors, vendor_sysfs_graphics) diff --git a/sepolicy/vendor/system_app.te b/sepolicy/vendor/system_app.te new file mode 100644 index 0000000..e33161e --- /dev/null +++ b/sepolicy/vendor/system_app.te @@ -0,0 +1,2 @@ +# Xiaomi Parts +allow system_app sysfs_thermal:file rw_file_perms; \ No newline at end of file diff --git a/sepolicy/vendor/tee.te b/sepolicy/vendor/tee.te new file mode 100644 index 0000000..d2556fb --- /dev/null +++ b/sepolicy/vendor/tee.te @@ -0,0 +1,2 @@ +allow tee vendor_fingerprint_data_file:dir create_dir_perms; +allow tee vendor_fingerprint_data_file:file create_file_perms; diff --git a/sepolicy/vendor/thermal-engine.te b/sepolicy/vendor/thermal-engine.te new file mode 100644 index 0000000..6e59f5b --- /dev/null +++ b/sepolicy/vendor/thermal-engine.te @@ -0,0 +1,11 @@ +allow vendor_thermal-engine { + vendor_sysfs_devfreq + thermal_data_file +}:dir r_dir_perms; + +allow vendor_thermal-engine vendor_sysfs_devfreq:file rw_file_perms; + +# Rule for vendor_thermal-engine to access init process +unix_socket_connect(vendor_thermal-engine, property, init); + +set_prop(vendor_thermal-engine, vendor_thermal_normal_prop) \ No newline at end of file diff --git a/sepolicy/vendor/vendor_modprobe.te b/sepolicy/vendor/vendor_modprobe.te new file mode 100644 index 0000000..4a6f93e --- /dev/null +++ b/sepolicy/vendor/vendor_modprobe.te @@ -0,0 +1,4 @@ +allow vendor_modprobe self:capability sys_module; +allow vendor_modprobe self:cap_userns sys_module; +allow vendor_modprobe vendor_file:system module_load; +r_dir_file(vendor_modprobe, vendor_file) diff --git a/sepolicy/vendor/vendor_qti_init_shell.te b/sepolicy/vendor/vendor_qti_init_shell.te new file mode 100644 index 0000000..1b25678 --- /dev/null +++ b/sepolicy/vendor/vendor_qti_init_shell.te @@ -0,0 +1,4 @@ +# allow init.mi.btmac.sh to read hex-encoded mac address and set it +allow vendor_qti_init_shell vendor_bluetooth_prop:property_service set; +allow vendor_qti_init_shell vendor_wifi_vendor_data_file:dir search; +allow vendor_qti_init_shell vendor_wifi_vendor_data_file:file r_file_perms; diff --git a/setup-makefiles.sh b/setup-makefiles.sh index 488689c..ba8a6ec 100755 --- a/setup-makefiles.sh +++ b/setup-makefiles.sh @@ -1,15 +1,35 @@ #!/bin/bash # -# Copyright (C) 2016 The CyanogenMod Project -# Copyright (C) 2017-2020 The LineageOS Project +# Copyright (C) 2022 The LineageOS Project # # SPDX-License-Identifier: Apache-2.0 # set -e -export DEVICE=veux -export DEVICE_COMMON=sm6375-common -export VENDOR=xiaomi +DEVICE=veux +VENDOR=xiaomi -"./../../${VENDOR}/${DEVICE_COMMON}/setup-makefiles.sh" "$@" +# Load extract_utils and do some sanity checks +MY_DIR="${BASH_SOURCE%/*}" +if [[ ! -d "${MY_DIR}" ]]; then MY_DIR="${PWD}"; fi + +ANDROID_ROOT="${MY_DIR}/../../.." + +HELPER="${ANDROID_ROOT}/tools/extract-utils/extract_utils.sh" +if [ ! -f "${HELPER}" ]; then + echo "Unable to find helper script at ${HELPER}" + exit 1 +fi +source "${HELPER}" + +# Initialize the helper +setup_vendor "${DEVICE}" "${VENDOR}" "${ANDROID_ROOT}" + +# Warning headers and guards +write_headers + +write_makefiles "${MY_DIR}/proprietary-files.txt" true + +# Finish +write_footers \ No newline at end of file diff --git a/system.prop b/system.prop new file mode 100644 index 0000000..12369c5 --- /dev/null +++ b/system.prop @@ -0,0 +1,42 @@ +# Charger +ro.charger.enable_suspend=true + +# CNE +persist.vendor.cne.feature=1 + +# Graphics +debug.sf.disable_backpressure=1 +debug.sf.enable_hwc_vds=1 + +# IMS +persist.dbg.volte_avail_ovr=1 +persist.dbg.vt_avail_ovr=1 +persist.dbg.wfc_avail_ovr=1 + +# Media +media.aac_51_output_enabled=true +media.stagefright.enable-aac=true +media.stagefright.enable-fma2dp=true +media.stagefright.enable-http=true +media.stagefright.enable-player=true +media.stagefright.enable-qcp=true +media.stagefright.enable-scan=true +persist.mm.enable.prefetch=true +ro.media.recorder-max-base-layer-fps=60 +vendor.mm.enable.qcom_parser=16777215 + +# NFC +ro.nfc.port=I2C + +# QC framework value-adds +ro.vendor.qti.va_aosp.support=1 + +# Qcom +ro.vendor.qti.sys.fw.bservice_enable=true + +# Radio +DEVICE_PROVISIONED=1 +ril.subscription.types=NV,RUIM + +# Sensors +persist.vendor.sensors.enable.mag_filter=true diff --git a/system_ext.prop b/system_ext.prop new file mode 100644 index 0000000..c00c9be --- /dev/null +++ b/system_ext.prop @@ -0,0 +1,5 @@ +# DPM +persist.vendor.dpm.feature=11 + +# Media +vendor.media.target_variant=_holi diff --git a/vendor.prop b/vendor.prop new file mode 100644 index 0000000..3c2d310 --- /dev/null +++ b/vendor.prop @@ -0,0 +1,272 @@ +# Audio +vendor.audio_hal.period_size=192 +persist.vendor.audio.ambisonic.capture=false +persist.vendor.audio.ambisonic.auto.profile=false +persist.vendor.audio.apptype.multirec.enabled=false +ro.vendor.audio.sdk.fluencetype=fluence +persist.vendor.audio.fluence.voicecall=true +persist.vendor.audio.fluence.voicerec=true +persist.vendor.audio.fluence.speaker=true +persist.vendor.audio.fluence.tmic.enabled=false +ro.qc.sdk.audio.ssr=false +ro.qc.sdk.audio.fluencetype=fluence +persist.audio.fluence.voicecall=true +persist.audio.fluence.voicerec=true +persist.audio.fluence.speaker=true +persist.vendor.audio.spv3.enable=true +persist.vendor.audio.avs.afe_api_version=2 +vendor.audio.tunnel.encode=false +persist.vendor.audio.ras.enabled=false +vendor.audio.offload.buffer.size.kb=32 +vendor.audio.offload.track.enable=true +vendor.voice.path.for.pcm.voip=true +ro.vendor.audio.sos=true +ro.vendor.audio.game.mode=true +vendor.audio.offload.multiaac.enable=true +vendor.audio.dolby.ds2.enabled=false +vendor.audio.dolby.ds2.hardbypass=false +vendor.audio.offload.multiple.enabled=false +vendor.audio.offload.passthrough=false +ro.vendor.audio.sdk.ssr=false +vendor.audio.offload.gapless.enabled=true +vendor.audio.safx.pbe.enabled=false +ro.vendor.audio.voice.volume.boost=manual +vendor.audio.parser.ip.buffer.size=262144 +vendor.audio.flac.sw.decoder.24bit=true +vendor.audio.hal.boot.timeout.ms=20000 +vendor.audio.use.sw.alac.decoder=true +vendor.audio.use.sw.ape.decoder=true +vendor.audio.use.sw.mpegh.decoder=true +vendor.audio.hw.aac.encoder=true +vendor.audio_hal.in_period_size=144 +vendor.audio_hal.period_multiplier=3 +vendor.audio.adm.buffering.ms=2 +vendor.audio.volume.headset.gain.depcal=true +persist.audio.fluence.voicecomm=true +debug.stagefright.omx_default_rank=0 +ro.vendor.audio.ring.filter=true +persist.vendor.audio.ring.filter.mask=0 +vendor.audio.hal.output.suspend.supported=true +aaudio.mmap_policy=2 +aaudio.mmap_exclusive_policy=2 +aaudio.hw_burst_min_usec=2000 +vendor.audio.enable.mirrorlink=false +ro.vendor.audio.afe.record=true +ro.vendor.audio.us.proximity=true +persist.vendor.audio.voicecall.speaker.stereo=true +persist.vendor.audio.ha_proxy.enabled=true +vendor.audio.feature.a2dp_offload.enable=true +vendor.audio.feature.afe_proxy.enable=true +vendor.audio.feature.anc_headset.enable=false +vendor.audio.feature.battery_listener.enable=true +vendor.audio.feature.compr_cap.enable=false +vendor.audio.feature.compress_in.enable=true +vendor.audio.feature.compress_meta_data.enable=true +vendor.audio.feature.compr_voip.enable=false +vendor.audio.feature.concurrent_capture.enable=true +vendor.audio.feature.custom_stereo.enable=true +vendor.audio.feature.display_port.enable=true +vendor.audio.feature.dsm_feedback.enable=false +vendor.audio.feature.dynamic_ecns.enable=true +vendor.audio.feature.ext_hw_plugin.enable=false +vendor.audio.feature.external_dsp.enable=false +vendor.audio.feature.external_speaker.enable=false +vendor.audio.feature.external_speaker_tfa.enable=false +vendor.audio.feature.fluence.enable=true +vendor.audio.feature.fm.enable=true +vendor.audio.feature.hdmi_edid.enable=true +vendor.audio.feature.hdmi_passthrough.enable=true +vendor.audio.feature.hfp.enable=true +vendor.audio.feature.hifi_audio.enable=false +vendor.audio.feature.hwdep_cal.enable=false +vendor.audio.feature.incall_music.enable=true +vendor.audio.feature.multi_voice_session.enable=true +vendor.audio.feature.keep_alive.enable=true +vendor.audio.feature.kpi_optimize.enable=true +vendor.audio.feature.maxx_audio.enable=false +vendor.audio.feature.ras.enable=true +vendor.audio.feature.record_play_concurency.enable=false +vendor.audio.feature.src_trkn.enable=true +vendor.audio.feature.spkr_prot.enable=true +vendor.audio.feature.ssrec.enable=true +vendor.audio.feature.usb_offload.enable=true +vendor.audio.feature.usb_offload_burst_mode.enable=true +vendor.audio.feature.usb_offload_sidetone_volume.enable=false +vendor.audio.feature.deepbuffer_as_primary.enable=false +vendor.audio.feature.vbat.enable=true +vendor.audio.feature.wsa.enable=false +vendor.audio.feature.audiozoom.enable=false +vendor.audio.feature.snd_mon.enable=true +vendor.audio.chk.cal.spk=2 +vendor.audio.chk.cal.us=2 +ro.vendor.audio.voice.change.support=true +ro.vendor.audio.soundfx.type=mi +ro.vendor.audio.vocal.support=true +ro.vendor.audio.surround.support=true +ro.vendor.audio.scenario.support=true +ro.vendor.audio.sfx.scenario=true +ro.vendor.audio.spk.stereo=true +ro.vendor.audio.sfx.earadj=true +ro.vendor.audio.soundfx.usb=true +ro.vendor.audio.miui.karaoke.show=false +ro.vendor.audio.miui.karaoke.tencent.show=false +ro.vendor.audio.soundtrigger.xiaomievent=1 +ro.vendor.audio.soundtrigger.pangaea=1 +ro.vendor.audio.soundtrigger.sva-5.0=1 +ro.vendor.audio.soundtrigger=sva +ro.vendor.audio.soundtrigger.lowpower=true +ro.vendor.audio.soundtrigger.training.level=50 +ro.vendor.audio.soundtrigger.xanzn.gmm.level=40 +ro.vendor.audio.soundtrigger.xanzn.gmm.user.level=30 +ro.vendor.audio.soundtrigger.xanzn.cnn.level=70 +ro.vendor.audio.soundtrigger.xanzn.vop.level=10 +ro.vendor.audio.soundtrigger.xatx.gmm.level=30 +ro.vendor.audio.soundtrigger.xatx.gmm.user.level=40 +ro.vendor.audio.soundtrigger.xatx.cnn.level=45 +ro.vendor.audio.soundtrigger.xatx.vop.level=0 +ro.vendor.audio.soundtrigger.appdefine.gmm.level=55 +ro.vendor.audio.soundtrigger.appdefine.gmm.user.level=65 +ro.vendor.audio.soundtrigger.appdefine.cnn.level=45 +ro.vendor.audio.soundtrigger.appdefine.vop.level=10 +ro.vendor.audio.soundtrigger.snr=16 +ro.vendor.audio.voice.change.youme.support=true +ro.audio.monitorRotation=true +persist.vendor.audio.misound.disable=true +persist.vendor.audio.delta.refresh=true + +# Bluetooth +persist.bluetooth.a2dp_offload.cap=sbc-aac-aptx-aptxhd-ldac-lhdc +persist.bluetooth.a2dp_offload.disabled=false +persist.vendor.bt.aac_frm_ctl.enabled=true +persist.vendor.bt.aac_vbr_frm_ctl.enabled=true +persist.vendor.qcom.bluetooth.a2dp_mcast_test.enabled=false +persist.vendor.qcom.bluetooth.a2dp_offload_cap=sbc-aptx-aptxtws-aptxhd-aac-ldac-aptxadaptiver2 +persist.vendor.qcom.bluetooth.aac_frm_ctl.enabled=true +persist.vendor.qcom.bluetooth.aac_vbr_ctl.enabled=true +persist.vendor.qcom.bluetooth.aptxadaptiver2_1_support=true +persist.vendor.qcom.bluetooth.scram.enabled=false +persist.vendor.qcom.bluetooth.twsp_state.enabled=false +ro.bluetooth.a2dp_offload.supported=true + +# Camera +camera.disable_zsl_mode=true + +# Chipset +ro.soc.manufacturer=Qualcomm +ro.soc.model=SM6375 + +# Crypto +ro.crypto.dm_default_key.options_format.version=2 +ro.crypto.volume.metadata.method=dm-default-key + +# DPM +persist.vendor.dpm.feature=1 +persist.vendor.dpm.idletimer.mode=default +persist.vendor.dpm.nsrm.bkg.evt=3955 +persist.vendor.dpmhalservice.enable=1 + +# FRP +ro.frp.pst=/dev/block/bootdevice/by-name/frp + +# Gatekeeper +vendor.gatekeeper.disable_spu=true + +# Graphics +debug.egl.hw=0 +debug.mdpcomp.logs=0 +debug.sf.disable_client_composition_cache=1 +debug.sf.enable_advanced_sf_phase_offset=1 +debug.sf.enable_gl_backpressure=1 +debug.sf.high_fps_early_gl_phase_offset_ns=-4000000 +debug.sf.high_fps_early_phase_offset_ns=-4000000 +debug.sf.high_fps_late_app_phase_offset_ns=1000000 +debug.sf.high_fps_late_sf_phase_offset_ns=-4000000 +debug.sf.hw=0 +persist.sys.sf.color_mode=0 +persist.sys.sf.color_saturation=1.0 +ro.hardware.egl=adreno +ro.hardware.vulkan=adreno +ro.opengles.version=196610 +ro.surface_flinger.force_hwc_copy_for_virtual_displays=true +ro.surface_flinger.has_HDR_display=true +ro.surface_flinger.has_wide_color_display=true +ro.surface_flinger.max_frame_buffer_acquired_buffers=3 +ro.surface_flinger.max_virtual_display_dimension=4096 +ro.surface_flinger.protected_contents=true +ro.surface_flinger.use_color_management=true +ro.vendor.colorpick_adjust=true +ro.vendor.all_modes.colorpick_adjust=true +ro.vendor.sf.enable_fb_scaling=1 +ro.vendor.display.type=oled +vendor.display.comp_mask=0 +vendor.display.disable_excl_rect=0 +vendor.display.disable_excl_rect_partial_fb=1 +vendor.display.disable_hw_recovery_dump=1 +vendor.display.disable_offline_rotator=1 +vendor.display.disable_scaler=0 +vendor.display.enable_async_powermode=0 +vendor.display.enable_early_wakeup=1 +vendor.display.enable_optimize_refresh=1 +vendor.display.enable_rounded_corner=0 +vendor.display.enable_perf_hint_large_comp_cycle=1 +vendor.display.enable_posted_start_dyn=2 +vendor.display.qdcm.mode_combine=2 +vendor.display.use_layer_ext=0 +vendor.display.use_smooth_motion=0 +vendor.gralloc.disable_ubwc=0 + +# NFC +ro.vendor.se.type=HCE,UICC + +# Radio +keyguard.no_require_sim=true +persist.radio.multisim.config=dsds +persist.vendor.data.iwlan.enable=true +persist.vendor.data.mode=concurrent +persist.vendor.radio.apm_sim_not_pwdn=1 +persist.vendor.radio.atfwd.start=true +persist.vendor.radio.custom_ecc=1 +persist.vendor.radio.data_ltd_sys_ind=1 +persist.vendor.radio.dynamic_load_mbn=3 +persist.vendor.radio.dynamic_sar=1 +persist.vendor.radio.enable_temp_dds=true +persist.vendor.radio.enableadvancedscan=true +persist.vendor.radio.force_ltd_sys_ind=1 +persist.vendor.radio.force_on_dc=true +persist.vendor.radio.hidl_dev_service=true +persist.vendor.radio.manual_nw_rej_ct=1 +persist.vendor.radio.mbn_trace=true +persist.vendor.radio.procedure_bytes=SKIP +persist.vendor.radio.rat_on=combine +persist.vendor.radio.redir_party_num=1 +persist.vendor.radio.sib16_support=1 +ro.telephony.call_ring.multiple=false +ro.telephony.default_cdma_sub=0 +ro.telephony.default_network=33,33 +ro.vendor.radio.5g=3 +ro.vendor.use_data_netmgrd=true +telephony.lteOnCdmaDevice=1 + +# Perf +ro.vendor.extension_library=libqti-perfd-client.so +ro.vendor.perf.scroll_opt=1 + +# Sensors +persist.vendor.sensors.debug.ssc_qmi_debug=true +persist.vendor.sensors.hal_trigger_ssr=false +persist.vendor.sensors.enable.rt_task=false +persist.vendor.sensors.support_direct_channel=false +persist.vendor.sensors.enable.bypass_worker=true +persist.vendor.sensors.sync_request=true + +# Storage +ro.incremental.enable=yes + +# Thermal +vendor.sys.thermal.data.path=/data/vendor/thermal/ + +# USB +vendor.usb.use_ffs_mtp=1 + +# Wifi +wifi.aware.interface=wifi-aware0 diff --git a/vibrator/Android.bp b/vibrator/Android.bp new file mode 100644 index 0000000..e9d6056 --- /dev/null +++ b/vibrator/Android.bp @@ -0,0 +1,42 @@ +Common_CFlags = ["-Wall"] +Common_CFlags += ["-Werror"] + +cc_library_shared { + name: "vendor.qti.hardware.vibrator.impl.xiaomi_holi", + vendor: true, + cflags: Common_CFlags, + srcs: [ + "Vibrator.cpp", + ], + shared_libs: [ + "libcutils", + "libutils", + "liblog", + "libqtivibratoreffect", + "libbinder_ndk", + "android.hardware.vibrator-V1-ndk_platform", + ], + export_include_dirs: ["include"] +} + +cc_binary { + name: "vendor.qti.hardware.vibrator.service.xiaomi_holi", + vendor: true, + relative_install_path: "hw", + init_rc: ["vendor.qti.hardware.vibrator.service.xiaomi_holi.rc"], + vintf_fragments: [ + "vendor.qti.hardware.vibrator.service.xiaomi_holi.xml", + ], + cflags: Common_CFlags, + srcs: [ + "service.cpp", + ], + shared_libs: [ + "libcutils", + "libutils", + "libbase", + "libbinder_ndk", + "android.hardware.vibrator-V1-ndk_platform", + "vendor.qti.hardware.vibrator.impl.xiaomi_holi", + ], +} diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp new file mode 100644 index 0000000..629eb18 --- /dev/null +++ b/vibrator/Vibrator.cpp @@ -0,0 +1,587 @@ +/* + * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "vendor.qti.vibrator.xiaomi_holi" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/Vibrator.h" +#ifdef USE_EFFECT_STREAM +#include "effect.h" +#endif + +namespace aidl { +namespace android { +namespace hardware { +namespace vibrator { + +#define STRONG_MAGNITUDE 0x7fff +#define MEDIUM_MAGNITUDE 0x5fff +#define LIGHT_MAGNITUDE 0x3fff +#define INVALID_VALUE -1 +#define CUSTOM_DATA_LEN 3 +#define NAME_BUF_SIZE 32 + +#define MSM_CPU_LAHAINA 415 +#define APQ_CPU_LAHAINA 439 +#define MSM_CPU_SHIMA 450 +#define MSM_CPU_SM8325 501 +#define APQ_CPU_SM8325P 502 +#define MSM_CPU_YUPIK 475 + +#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) + +static const char LED_DEVICE[] = "/sys/class/leds/vibrator"; + +InputFFDevice::InputFFDevice() +{ + DIR *dp; + FILE *fp = NULL; + struct dirent *dir; + uint8_t ffBitmask[FF_CNT / 8]; + char devicename[PATH_MAX]; + const char *INPUT_DIR = "/dev/input/"; + char name[NAME_BUF_SIZE]; + int fd, ret; + int soc = property_get_int32("ro.vendor.qti.soc_id", -1); + + mVibraFd = INVALID_VALUE; + mSupportGain = false; + mSupportEffects = false; + mSupportExternalControl = false; + mCurrAppId = INVALID_VALUE; + mCurrMagnitude = 0x7fff; + mInExternalControl = false; + + dp = opendir(INPUT_DIR); + if (!dp) { + ALOGE("open %s failed, errno = %d", INPUT_DIR, errno); + return; + } + + memset(ffBitmask, 0, sizeof(ffBitmask)); + while ((dir = readdir(dp)) != NULL){ + if (dir->d_name[0] == '.' && + (dir->d_name[1] == '\0' || + (dir->d_name[1] == '.' && dir->d_name[2] == '\0'))) + continue; + + snprintf(devicename, PATH_MAX, "%s%s", INPUT_DIR, dir->d_name); + fd = TEMP_FAILURE_RETRY(open(devicename, O_RDWR)); + if (fd < 0) { + ALOGE("open %s failed, errno = %d", devicename, errno); + continue; + } + + ret = TEMP_FAILURE_RETRY(ioctl(fd, EVIOCGNAME(sizeof(name)), name)); + if (ret == -1) { + ALOGE("get input device name %s failed, errno = %d\n", devicename, errno); + close(fd); + continue; + } + + if (strcmp(name, "qcom-hv-haptics") && strcmp(name, "qti-haptics") && + strcmp(name, "aw8624_haptic")) { + ALOGD("not a qcom/qti haptics device\n"); + close(fd); + continue; + } + + ALOGI("%s is detected at %s\n", name, devicename); + ret = TEMP_FAILURE_RETRY(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ffBitmask)), ffBitmask)); + if (ret == -1) { + ALOGE("ioctl failed, errno = %d", errno); + close(fd); + continue; + } + + if (test_bit(FF_CONSTANT, ffBitmask) || + test_bit(FF_PERIODIC, ffBitmask)) { + mVibraFd = fd; + if (test_bit(FF_CUSTOM, ffBitmask)) + mSupportEffects = true; + if (test_bit(FF_GAIN, ffBitmask)) + mSupportGain = true; + + if (soc <= 0 && (fp = fopen("/sys/devices/soc0/soc_id", "r")) != NULL) { + fscanf(fp, "%u", &soc); + fclose(fp); + } + switch (soc) { + case MSM_CPU_LAHAINA: + case APQ_CPU_LAHAINA: + case MSM_CPU_SHIMA: + case MSM_CPU_SM8325: + case APQ_CPU_SM8325P: + case MSM_CPU_YUPIK: + mSupportExternalControl = true; + break; + default: + mSupportExternalControl = false; + break; + } + break; + } + + close(fd); + } + + closedir(dp); +} + +/** Play vibration + * + * @param effectId: ID of the predefined effect will be played. If effectId is valid + * (non-negative value), the timeoutMs value will be ignored, and the + * real playing length will be set in param@playLengtMs and returned + * to VibratorService. If effectId is invalid, value in param@timeoutMs + * will be used as the play length for playing a constant effect. + * @param timeoutMs: playing length, non-zero means playing, zero means stop playing. + * @param playLengthMs: the playing length in ms unit which will be returned to + * VibratorService if the request is playing a predefined effect. + * The custom_data in periodic is reused for returning the playLengthMs + * from kernel space to userspace if the pattern is defined in kernel + * driver. It's been defined with following format: + * . + * The effect-ID is used for passing down the predefined effect to + * kernel driver, and the rest two parameters are used for returning + * back the real playing length from kernel driver. + */ +int InputFFDevice::play(int effectId, uint32_t timeoutMs, long *playLengthMs) { + struct ff_effect effect; + struct input_event play; + int16_t data[CUSTOM_DATA_LEN] = {0, 0, 0}; + int ret; +#ifdef USE_EFFECT_STREAM + const struct effect_stream *stream; +#endif + + /* For QMAA compliance, return OK even if vibrator device doesn't exist */ + if (mVibraFd == INVALID_VALUE) { + if (playLengthMs != NULL) + *playLengthMs = 0; + return 0; + } + + if (timeoutMs != 0) { + if (mCurrAppId != INVALID_VALUE) { + ret = TEMP_FAILURE_RETRY(ioctl(mVibraFd, EVIOCRMFF, mCurrAppId)); + if (ret == -1) { + ALOGE("ioctl EVIOCRMFF failed, errno = %d", -errno); + goto errout; + } + mCurrAppId = INVALID_VALUE; + } + + memset(&effect, 0, sizeof(effect)); + if (effectId != INVALID_VALUE) { + data[0] = effectId; + effect.type = FF_PERIODIC; + effect.u.periodic.waveform = FF_CUSTOM; + effect.u.periodic.magnitude = mCurrMagnitude; + effect.u.periodic.custom_data = data; + effect.u.periodic.custom_len = sizeof(int16_t) * CUSTOM_DATA_LEN; +#ifdef USE_EFFECT_STREAM + stream = get_effect_stream(effectId); + if (stream != NULL) { + effect.u.periodic.custom_data = (int16_t *)stream; + effect.u.periodic.custom_len = sizeof(*stream); + } +#endif + } else { + effect.type = FF_CONSTANT; + effect.u.constant.level = mCurrMagnitude; + effect.replay.length = timeoutMs; + } + + effect.id = mCurrAppId; + effect.replay.delay = 0; + + ret = TEMP_FAILURE_RETRY(ioctl(mVibraFd, EVIOCSFF, &effect)); + if (ret == -1) { + ALOGE("ioctl EVIOCSFF failed, errno = %d", -errno); + goto errout; + } + + mCurrAppId = effect.id; + if (effectId != INVALID_VALUE && playLengthMs != NULL) { + *playLengthMs = data[1] * 1000 + data[2]; +#ifdef USE_EFFECT_STREAM + if (stream != NULL && stream->play_rate_hz != 0) + *playLengthMs = ((stream->length * 1000) / stream->play_rate_hz) + 1; +#endif + } + + play.value = 1; + play.type = EV_FF; + play.code = mCurrAppId; + play.time.tv_sec = 0; + play.time.tv_usec = 0; + ret = TEMP_FAILURE_RETRY(write(mVibraFd, (const void*)&play, sizeof(play))); + if (ret == -1) { + ALOGE("write failed, errno = %d\n", -errno); + ret = TEMP_FAILURE_RETRY(ioctl(mVibraFd, EVIOCRMFF, mCurrAppId)); + if (ret == -1) + ALOGE("ioctl EVIOCRMFF failed, errno = %d", -errno); + goto errout; + } + } else if (mCurrAppId != INVALID_VALUE) { + ret = TEMP_FAILURE_RETRY(ioctl(mVibraFd, EVIOCRMFF, mCurrAppId)); + if (ret == -1) { + ALOGE("ioctl EVIOCRMFF failed, errno = %d", -errno); + goto errout; + } + mCurrAppId = INVALID_VALUE; + } + return 0; + +errout: + mCurrAppId = INVALID_VALUE; + return ret; +} + +int InputFFDevice::on(int32_t timeoutMs) { + return play(INVALID_VALUE, timeoutMs, NULL); +} + +int InputFFDevice::off() { + return play(INVALID_VALUE, 0, NULL); +} + +int InputFFDevice::setAmplitude(uint8_t amplitude) { + int tmp, ret; + struct input_event ie; + + /* For QMAA compliance, return OK even if vibrator device doesn't exist */ + if (mVibraFd == INVALID_VALUE) + return 0; + + tmp = amplitude * (STRONG_MAGNITUDE - LIGHT_MAGNITUDE) / 255; + tmp += LIGHT_MAGNITUDE; + ie.type = EV_FF; + ie.code = FF_GAIN; + ie.value = tmp; + + ret = TEMP_FAILURE_RETRY(write(mVibraFd, &ie, sizeof(ie))); + if (ret == -1) { + ALOGE("write FF_GAIN failed, errno = %d", -errno); + return ret; + } + + mCurrMagnitude = tmp; + return 0; +} + +int InputFFDevice::playEffect(int effectId, EffectStrength es, long *playLengthMs) { + switch (es) { + case EffectStrength::LIGHT: + mCurrMagnitude = LIGHT_MAGNITUDE; + break; + case EffectStrength::MEDIUM: + mCurrMagnitude = MEDIUM_MAGNITUDE; + break; + case EffectStrength::STRONG: + mCurrMagnitude = STRONG_MAGNITUDE; + break; + default: + return -1; + } + + return play(effectId, INVALID_VALUE, playLengthMs); +} + +LedVibratorDevice::LedVibratorDevice() { + char devicename[PATH_MAX]; + int fd; + + mDetected = false; + + snprintf(devicename, sizeof(devicename), "%s/%s", LED_DEVICE, "activate"); + fd = TEMP_FAILURE_RETRY(open(devicename, O_RDWR)); + if (fd < 0) { + ALOGE("open %s failed, errno = %d", devicename, errno); + return; + } + + mDetected = true; +} + +int LedVibratorDevice::write_value(const char *file, const char *value) { + int fd; + int ret; + + fd = TEMP_FAILURE_RETRY(open(file, O_WRONLY)); + if (fd < 0) { + ALOGE("open %s failed, errno = %d", file, errno); + return -errno; + } + + ret = TEMP_FAILURE_RETRY(write(fd, value, strlen(value) + 1)); + if (ret == -1) { + ret = -errno; + } else if (ret != strlen(value) + 1) { + /* even though EAGAIN is an errno value that could be set + by write() in some cases, none of them apply here. So, this return + value can be clearly identified when debugging and suggests the + caller that it may try to call vibrator_on() again */ + ret = -EAGAIN; + } else { + ret = 0; + } + + errno = 0; + close(fd); + + return ret; +} + +int LedVibratorDevice::on(int32_t timeoutMs) { + char file[PATH_MAX]; + char value[32]; + int ret; + + snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "state"); + ret = write_value(file, "1"); + if (ret < 0) + goto error; + + snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "duration"); + snprintf(value, sizeof(value), "%u\n", timeoutMs); + ret = write_value(file, value); + if (ret < 0) + goto error; + + snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "activate"); + ret = write_value(file, "1"); + if (ret < 0) + goto error; + + return 0; + +error: + ALOGE("Failed to turn on vibrator ret: %d\n", ret); + return ret; +} + +int LedVibratorDevice::off() +{ + char file[PATH_MAX]; + int ret; + + snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "activate"); + ret = write_value(file, "0"); + return ret; +} + +ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { + *_aidl_return = IVibrator::CAP_ON_CALLBACK; + + if (ledVib.mDetected) { + *_aidl_return |= IVibrator::CAP_PERFORM_CALLBACK; + ALOGD("QTI Vibrator reporting capabilities: %d", *_aidl_return); + return ndk::ScopedAStatus::ok(); + } + + if (ff.mSupportGain) + *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL; + if (ff.mSupportEffects) + *_aidl_return |= IVibrator::CAP_PERFORM_CALLBACK; + if (ff.mSupportExternalControl) + *_aidl_return |= IVibrator::CAP_EXTERNAL_CONTROL; + + ALOGD("QTI Vibrator reporting capabilities: %d", *_aidl_return); + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::off() { + int ret; + + ALOGD("QTI Vibrator off"); + if (ledVib.mDetected) + ret = ledVib.off(); + else + ret = ff.off(); + if (ret != 0) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, + const std::shared_ptr& callback) { + int ret; + + ALOGD("Vibrator on for timeoutMs: %d", timeoutMs); + if (ledVib.mDetected) + ret = ledVib.on(timeoutMs); + else + ret = ff.on(timeoutMs); + + if (ret != 0) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); + + if (callback != nullptr) { + std::thread([=] { + ALOGD("Starting on on another thread"); + usleep(timeoutMs * 1000); + ALOGD("Notifying on complete"); + if (!callback->onComplete().isOk()) { + ALOGE("Failed to call onComplete"); + } + }).detach(); + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std::shared_ptr& callback, int32_t* _aidl_return) { + long playLengthMs; + int ret; + + if (ledVib.mDetected) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + ALOGD("Vibrator perform effect %d", effect); + + if (effect < Effect::CLICK || + effect > Effect::HEAVY_CLICK) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + if (es != EffectStrength::LIGHT && es != EffectStrength::MEDIUM && es != EffectStrength::STRONG) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + ret = ff.playEffect((static_cast(effect)), es, &playLengthMs); + if (ret != 0) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); + + if (callback != nullptr) { + std::thread([=] { + ALOGD("Starting perform on another thread"); + usleep(playLengthMs * 1000); + ALOGD("Notifying perform complete"); + callback->onComplete(); + }).detach(); + } + + *_aidl_return = playLengthMs; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* _aidl_return) { + if (ledVib.mDetected) + return ndk::ScopedAStatus::ok(); + + *_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD, + Effect::POP, Effect::HEAVY_CLICK}; + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { + uint8_t tmp; + int ret; + + if (ledVib.mDetected) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + ALOGD("Vibrator set amplitude: %f", amplitude); + + if (amplitude <= 0.0f || amplitude > 1.0f) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); + + if (ff.mInExternalControl) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + tmp = (uint8_t)(amplitude * 0xff); + ret = ff.setAmplitude(tmp); + if (ret != 0) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) { + if (ledVib.mDetected) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + ALOGD("Vibrator set external control: %d", enabled); + if (!ff.mSupportExternalControl) + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); + + ff.mInExternalControl = enabled; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* maxDelayMs __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* maxSize __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector* supported __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive primitive __unused, + int32_t* durationMs __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::compose(const std::vector& composite __unused, + const std::shared_ptr& callback __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector* _aidl_return __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t id __unused, Effect effect __unused, + EffectStrength strength __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t id __unused) { + return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +} + +} // namespace vibrator +} // namespace hardware +} // namespace android +} // namespace aidl + diff --git a/vibrator/excluded-input-devices.xml b/vibrator/excluded-input-devices.xml new file mode 100644 index 0000000..dfea562 --- /dev/null +++ b/vibrator/excluded-input-devices.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vibrator/include/Vibrator.h b/vibrator/include/Vibrator.h new file mode 100644 index 0000000..e0694ca --- /dev/null +++ b/vibrator/include/Vibrator.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2018,2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace vibrator { + +class InputFFDevice { +public: + InputFFDevice(); + int playEffect(int effectId, EffectStrength es, long *playLengthMs); + int on(int32_t timeoutMs); + int off(); + int setAmplitude(uint8_t amplitude); + bool mSupportGain; + bool mSupportEffects; + bool mSupportExternalControl; + bool mInExternalControl; +private: + int play(int effectId, uint32_t timeoutMs, long *playLengthMs); + int mVibraFd; + int16_t mCurrAppId; + int16_t mCurrMagnitude; +}; + +class LedVibratorDevice { +public: + LedVibratorDevice(); + int on(int32_t timeoutMs); + int off(); + bool mDetected; +private: + int write_value(const char *file, const char *value); +}; + +class Vibrator : public BnVibrator { +public: + class InputFFDevice ff; + class LedVibratorDevice ledVib; + ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; + ndk::ScopedAStatus off() override; + ndk::ScopedAStatus on(int32_t timeoutMs, + const std::shared_ptr& callback) override; + ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, + const std::shared_ptr& callback, + int32_t* _aidl_return) override; + ndk::ScopedAStatus getSupportedEffects(std::vector* _aidl_return) override; + ndk::ScopedAStatus setAmplitude(float amplitude) override; + ndk::ScopedAStatus setExternalControl(bool enabled) override; + ndk::ScopedAStatus getCompositionDelayMax(int32_t* maxDelayMs); + ndk::ScopedAStatus getCompositionSizeMax(int32_t* maxSize); + ndk::ScopedAStatus getSupportedPrimitives(std::vector* supported) override; + ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, + int32_t* durationMs) override; + ndk::ScopedAStatus compose(const std::vector& composite, + const std::shared_ptr& callback) override; + ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector* _aidl_return) override; + ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; + ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; +}; + +} // namespace vibrator +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/vibrator/service.cpp b/vibrator/service.cpp new file mode 100644 index 0000000..ff9706d --- /dev/null +++ b/vibrator/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "vendor.qti.hardware.vibrator.service.xiaomi_holi" + +#include +#include +#include + +#include "Vibrator.h" + +using aidl::android::hardware::vibrator::Vibrator; + +int main() { + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr vib = ndk::SharedRefBase::make(); + + const std::string instance = std::string() + Vibrator::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(vib->asBinder().get(), instance.c_str()); + CHECK(status == STATUS_OK); + + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach +} diff --git a/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.rc b/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.rc new file mode 100644 index 0000000..1293483 --- /dev/null +++ b/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.rc @@ -0,0 +1,4 @@ +service vendor.qti.vibrator.xiaomi_holi /vendor/bin/hw/vendor.qti.hardware.vibrator.service.xiaomi_holi + class hal + user system + group system input diff --git a/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.xml b/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.xml new file mode 100644 index 0000000..df29ada --- /dev/null +++ b/vibrator/vendor.qti.hardware.vibrator.service.xiaomi_holi.xml @@ -0,0 +1,33 @@ + + + + android.hardware.vibrator + IVibrator/default + + diff --git a/wifi/WCNSS_qcom_cfg.ini b/wifi/WCNSS_qcom_cfg.ini new file mode 100644 index 0000000..f4c666f --- /dev/null +++ b/wifi/WCNSS_qcom_cfg.ini @@ -0,0 +1,569 @@ +# This file allows user to override the factory +# defaults for the WLAN Driver + +# Enable IMPS or not +gEnableImps=1 + +# Enable BMPS or not +gEnableBmps=1 + +# Phy Mode (auto, b, g, n, etc) +# Valid values are 0-9, with 0 = Auto, 4 = 11n, 9 = 11ac +# 1 = 11abg, 2 = 11b, 3 = 11g, 5 = 11g only, 6 = 11n only +# 7 = 11b only 8 = 11ac only. +gDot11Mode=0 + +# Assigned MAC Addresses - This will be used until NV items are in place +# Each byte of MAC address is represented in Hex format as XX +Intf0MacAddress=000AF58989FF +Intf1MacAddress=000AF58989FE +Intf2MacAddress=000AF58989FD +Intf3MacAddress=000AF58989FC + +# UAPSD service interval for VO,VI, BE, BK traffic +InfraUapsdVoSrvIntv=0 +InfraUapsdViSrvIntv=0 +InfraUapsdBeSrvIntv=0 +InfraUapsdBkSrvIntv=0 + +# Flag to allow STA send AddTspec even when ACM is Off +gAddTSWhenACMIsOff=1 + +#ExtR HONGMI-89896,jiyanan.wt,20210902,ADD,xiaomi general configurations +gSelect5GHzMargin=5 +roam_bad_rssi_thresh_offset_2g=0 +roam_bg_scan_bad_rssi_thresh=-76 +gStaKeepAlivePeriod = 30 +gEnablePacketLog=1 +gEnableModulatedDTIM=3 +gMaxLIModulatedDTIM=3 +groam_dense_rssi_thresh_offset=5 +gtraffic_threshold=50 +gRoamBmissFirstBcnt=10 +gRoamBmissFinalBcnt=20 +gper_roam_enabled=3 +arp_ac_category=0 +gEnableLPRx=0 +gEnableSelfRecovery=1 +enable_ftopen=0 + +# Flags to filter Mcast and Bcast RX packets. +# Value 0: No filtering, 1: Filter all Multicast. +# 2: Filter all Broadcast. 3: Filter all Mcast abd Bcast +McastBcastFilter=3 + +#Flag to enable HostARPOffload feature or not +hostArpOffload=1 + +#Flag to enable HostNSOffload feature or not +hostNSOffload=1 + +# 802.11n Protection flag +gEnableApProt=1 + +#Enable OBSS protection +gEnableApOBSSProt=1 + +#Enable/Disable UAPSD for SoftAP +gEnableApUapsd=1 + +# Fixed Rate +gFixedRate=0 + +# Maximum Tx power +# gTxPowerCap=30 + +# Fragmentation Threshold +# gFragmentationThreshold=2346 + +# RTS threshold +RTSThreshold=1048576 + +# Intra-BSS forward +gDisableIntraBssFwd=0 + +# WMM Enable/Disable +WmmIsEnabled=0 + +# 802.11d support +g11dSupportEnabled=0 + +# 802.11h support +g11hSupportEnabled=1 + +# DFS Master Capability +gEnableDFSMasterCap=1 + +# ESE Support and fast transition +EseEnabled=0 + +ImplicitQosIsEnabled=0 + +gNeighborScanTimerPeriod=200 +gNeighborLookupThreshold=76 +gNeighborScanChannelMinTime=20 +gNeighborScanChannelMaxTime=30 +gMaxNeighborReqTries=3 + +# Legacy (non-ESE, non-802.11r) Fast Roaming Support +# To enable, set FastRoamEnabled=1 +# To disable, set FastRoamEnabled=0 +FastRoamEnabled=1 + +# Check if the AP to which we are roaming is better than current AP in +# terms of RSSI. Checking is disabled if set to Zero.Otherwise it will +# use this value as to how better the RSSI of the new/roamable AP should +# be for roaming +RoamRssiDiff=5 + +# To enable, set gRoamIntraBand=1 (Roaming within band) +# To disable, set gRoamIntraBand=0 (Roaming across band) +gRoamIntraBand=0 + +#Short Guard Interval Enable/disable +gShortGI20Mhz=1 +gShortGI40Mhz=1 + +#Auto Shutdown Value in seconds. A value of 0 means Auto shutoff is disabled +gAPAutoShutOff=0 + +#Auto Shutdown wlan : Value in Seconds. 0 means disabled. Max 1 day = 86400 sec +gWlanAutoShutdown = 0 + +# Not used. +gApAutoChannelSelection=0 + +#Preferred band (both or 2.4 only or 5 only) +BandCapability=0 + +#Channel Bonding +gChannelBondingMode5GHz=1 + +#Say gGoKeepAlivePeriod(5 seconds) and gGoLinkMonitorPeriod(10 seconds). +#For every 10 seconds DUT send Qos Null frame(i.e., Keep Alive frame if link +#is idle for last 10 seconds.) For both active and power save clients. + +#Power save clients: DUT set TIM bit from 10th second onwards and till client +#honors TIM bit. If doesn't honor for 5 seconds then DUT remove client. + +#Active clients: DUT send Qos Null frame for 10th seconds onwards if it is not +#success still we try on 11th second if not tries on 12th and so on till 15th +#second. Hence before disconnection DUT will send 5 NULL frames. Hence in any +#case DUT will detect client got removed in (10+5) seconds. +#i.e., (gGoKeepAlivePeriod + gGoLinkMonitorPeriod).. + +#gGoLinkMonitorPeriod/ gApLinkMonitorPeriod is period where link is idle and +#it is period where we send NULL frame. +#gApLinkMonitorPeriod = 10 +#gGoLinkMonitorPeriod = 10 + +#gGoKeepAlivePeriod/gApKeepAlivePeriod is time to spend to check whether frame +#are succeed to send or not. Hence total effective detection time is +# (gGoLinkMonitorPeriod + gGoKeepAlivePeriod) / +# (gApLinkMonitorPeriod + gApKeepAlivePeriod) +gGoKeepAlivePeriod = 20 +gApKeepAlivePeriod = 20 + +#If set will start with active scan after driver load, otherwise will start with +#passive scan to find out the domain +gEnableBypass11d=1 + +#If set to 0, will not scan DFS channels +gEnableDFSChnlScan=1 + +# Enable DFS channel roam +# 0: DISABLE, 1: ENABLED_NORMAL, 2: ENABLED_ACTIVE +gAllowDFSChannelRoam=1 + +gVhtChannelWidth=2 + +#Data Inactivity Timeout when in powersave (in ms) +gDataInactivityTimeout=200 + +# Set txchainmask and rxchainmask +# These parameters are used only if gEnable2x2 is 0 +# Valid values are 1,2 +# Set gSetTxChainmask1x1=1 or gSetRxChainmask1x1=1 to select chain0. +# Set gSetTxChainmask1x1=2 or gSetRxChainmask1x1=2 to select chain1. +gSetTxChainmask1x1=1 +gSetRxChainmask1x1=1 + +# Scan Timing Parameters +# gPassiveMaxChannelTime=110 +# gPassiveMinChannelTime=60 +gActiveMaxChannelTime=40 +gActiveMinChannelTime=20 + +#If set to 0, MCC is not allowed. +gEnableMCCMode=1 + +# MCC to SCC Switch mode: +# 0-Disable +# 1-Enable +# 2-Force SCC if same band, with SAP restart +# 3-Force SCC if same band, without SAP restart by sending (E)CSA +# 4-Force SCC if same band (or) use SAP mandatory channel for DBS, +# without SAP restart by sending (E)CSA +gWlanMccToSccSwitchMode = 0 + +# 1=enable STBC; 0=disable STBC +gEnableRXSTBC=1 + +# 1=enable tx STBC; 0=disable +gEnableTXSTBC=1 + +# 1=enable rx LDPC; 0=disable +gEnableRXLDPC=1 + +#Enable/Disable Tx beamforming +gTxBFEnable=1 + +#Enable/Disable Tx beamformee in SAP mode +gEnableTxBFeeSAP=1 + +# Enable Tx beamforming in VHT20MHz +# Valid values are 0,1. If commented out, the default value is 0. +# 0=disable, 1=enable +gEnableTxBFin20MHz=1 + +#Enable/Disable SU Tx beamformer support. +gEnableTxSUBeamformer=1 + +gEnableFastRoamInConcurrency=1 + +#Maxium Channel time in msec +gMaxMediumTime = 6000 + +# 802.11K support +gRrmEnable=1 + +#Enable Power Save offload +gEnablePowerSaveOffload=2 + +#Enable firmware uart print +gEnablefwprint=0 + +# Firmware log mode +# Valid values are 0,1,2 +# 0=Disable, 1=WMI, 2=DIAG +gEnablefwlog=1 + +# Maximum Receive AMPDU size (VHT only. Valid values: +# 0->8k 1->16k 2->32k 3->64k 4->128k) +gVhtAmpduLenExponent=7 + +# Maximum MPDU length (VHT only. Valid values: +# 0->3895 octets, 1->7991 octets, 2->11454 octets) +gVhtMpduLen=2 + +# Maximum number of wow filters required +#gMaxWoWFilters=22 + +# WOW Enable/Disable. +# 0 - Disable both magic pattern match and pattern byte match. +# 1 - Enable magic pattern match on all interfaces. +# 2 - Enable pattern byte match on all interfaces. +# 3 - Enable both magic pattern and pattern byte match on all interfaces. +# Default value of gEnableWoW is 3. +# gEnableWoW=0 + +# Enable or Disable MCC Adaptive Scheduler at the FW +# 1=Enable (default), 0=Disable +gEnableMCCAdaptiveScheduler=1 + +#Enable or Disable p2p device address administered +isP2pDeviceAddrAdministrated=0 + +# Remove Overlap channel restriction +gEnableOverLapCh=0 + +#Enable VHT on 2.4Ghz +gEnableVhtFor24GHzBand=1 + +#Maximum number of offload peers supported +# gMaxOffloadPeers=2 + +# controlling the following offload patterns +# through ini parameter. Default value is 1 +# to disable set it to zero. ssdp = 0 +# Setup multicast pattern for mDNS 224.0.0.251, +# SSDP 239.255.255.250 and LLMNR 224.0.0.252 +ssdp=0 + +#Enable Memory Deep Sleep +gEnableMemDeepSleep=1 + +# Regulatory Setting; 0=STRICT; 1=CUSTOM +gRegulatoryChangeCountry=1 + +# RA filtering rate limit param, the current value would not +# help if the lifetime in RA is less than 3*60=3min. Then +# we need to change it, though it is uncommon. +# gRAFilterEnable=0 +gRArateLimitInterval=600 + +# Maximum number of concurrent connections +gMaxConcurrentActiveSessions=3 + +# Disable/Enable GreenAP +# 0 to disable, 1 to enable, default: 1 +gEnableGreenAp=1 + +# Radar PRI multiplier +gDFSradarMappingPriMultiplier=4 + +gPNOScanSupport=1 + +#Enable/Disable LPASS support +# 0 to disable, 1 to enable +gEnableLpassSupport=1 + +# Whether userspace country code setting shld have priority +gCountryCodePriority=1 + +# Enable(1)/Disable(0) SIFS burst +gEnableSifsBurst=1 + +# Enable or Disable Multi-user MIMO +# 1=Enable (default), 0=Disable +gEnableMuBformee=1 + +# Enable/Disable channel avoidance for SAP in SCC scenario +# 0 - disable +# 1 - enable +gSapSccChanAvoidance=0 + +# Inactivity time (in ms) to end TX Service Period while in IBSS power save mode +gIbssTxSpEndInactivityTime=10 + +# Enable TDLS External Control. That is, user space application has to +# first configure a peer MAC in wlan driver towards which TDLS is desired. +# Device will establish TDLS only towards those configured peers whenever +# TDLS criteria (throughput and RSSI threshold) is met and teardown TDLS +# when teardown criteria (idle packet count and RSSI) is met. However, +# device will accept TDLS connection if it is initiated from any other peer, +# even if that peer is not configured. +# 0 - disable +# 1 - enable +# For TDLS External Control, Implicit Trigger must also be enabled. +gTDLSExternalControl=0 + +# Enable support for TDLS off-channel operation +# 0 - disable +# 1 - enable +# TDLS off-channel operation will be invoked when there is only one +# TDLS connection. +gEnableTDLSOffChannel=0 + +# Enable or Disable Random MAC (Spoofing) +# 1=Enable (default), 0=Disable +gEnableMacAddrSpoof=1 + +################ Datapath feature set Begin ################ +# Bus bandwidth threshold values in terms of number of packets +gBusBandwidthHighThreshold=2000 +gBusBandwidthMediumThreshold=500 +gBusBandwidthLowThreshold=150 + +# Bus bandwidth compute timeout value in ms +gBusBandwidthComputeInterval=100 + +# VHT Tx/Rx MCS values +# Valid values are 0,1,2. If commented out, the default value is 0. +# 0=MCS0-7, 1=MCS0-8, 2=MCS0-9 +gVhtRxMCS=2 +gVhtTxMCS=2 + +# VHT Tx/Rx MCS values for 2x2 +# Valid values are 0,1,2. If commented out, the default value is 0. +# 0=MCS0-7, 1=MCS0-8, 2=MCS0-9 +gEnable2x2=1 +gVhtRxMCS2x2=2 +gVhtTxMCS2x2=2 + +#IPA config is a bit mask and following are the configurations. +#bit0 IPA Enable +#bit1 IPA PRE Filter enable +#bit2 IPv6 enable +#bit3 IPA Resource Manager (RM) enable +#bit4 IPA Clock scaling enable +#bit5 IPA uC ENABLE +#bit6 IPA uC STA ENABLE +#bit8 IPA Real Time Debugging +gIPAConfig=0x7d +gIPADescSize=800 + +# Enable/Disable RX full reorder offload +gReorderOffloadSupported=1 + +# Enable CE classification +# 1 - enable(default) 0 - disable +gCEClassifyEnable=1 + +# Enable Rx handling options +# Rx_thread=1 RPS=2(default for ROME) NAPI=4(default for ihelium) +rx_mode=5 + +# Enable(Tx) fastpath for data traffic. +# 1 - enable(default) 0 - disable +gEnableFastPath=1 + +# This flag enables IP, TCP and UDP checksum offload +# 1 - enable(default) 0 - disable +gEnableIpTcpUdpChecksumOffload=1 + +# Enable TCP Segmentation Offload +# 1 - enable 0 - disable +TSOEnable=1 + +# Enable Generic Receive Offload +# 1 - enable(default) 0 - disable +GROEnable=1 + +# Enable HT MPDU Density +# 4 for 2 micro sec +ght_mpdu_density=4 + +# Enable flow steering to enable multiple CEs for Rx flows. +# Multiple Rx CEs<==>Multiple Rx IRQs<==>probably different CPUs. +# Parallel Rx paths. +# 1 - enable 0 - disable(default) +gEnableFlowSteering=1 + +# Time in microseconds after which a NAPI poll must yield +ce_service_max_yield_time=500 + +#Maximum number of HTT messages to be processed per NAPI poll +ce_service_max_rx_ind_flush=1 + +# Maximum number of MSDUs the firmware will pack in one HTT_T2H_MSG_TYPE_RX_IN_ORD_PADDR_IND +maxMSDUsPerRxInd=8 + +# Enable NUD tracking feature +#ExtR HONGMI-89823,jiyanan.wt,20210909,DEL,remove the disconnect logic in driver when NUD_FAILED happen +# 1 - enable 0 - disable(default) 2- roam +gEnableNUDTracking=2 + +# Enable PEER UNMAP CONF SUPPORT +# 1 - enable 0 - disable(default) +gEnablePeerUnmapConfSupport=1 + +rpsRxQueueCpuMapList=f3 +################ Datapath feature set End ################ + +################ NAN feature set start ################### + +# Enable NAN discovery (NAN 1.0) +# 1 - enable 0 - disable(default) +gEnableNanSupport=1 +# Enable NAN Datapath +genable_nan_datapath=1 + +################ NAN feature set end ##################### + +adaptive_dwell_mode_enabled=1 + +hostscan_adaptive_dwell_mode=1 + +adapt_dwell_lpf_weight=80 + +adapt_dwell_wifi_act_threshold=10 + +MAWCEnabled=0 + +# Enable/Disable rtt sta mac randomization +enable_rtt_mac_randomization=1 + +#Enable/Disable SNR monitoring +gEnableSNRMonitoring=1 + +# Rx thread affinity mask in UL case +RX_THREAD_UL_CPU_AFFINITY_MASK=0xc0 + +#ExtR HONGMI-89826,jiyanan.wt,ADD,enable driver reg_db.c's modification +ignore_fw_reg_offload_ind=1 + +# Packet Log buffer size +PktlogBufSize=1 + +# Disable/Enbale Enhanced Green AP +# 0 to disable, 1 to enable, default: 0 +gEnableEGAP=1 + +# Enable support for TDLS +# 0 - disable +# 1 - enable +gEnableTDLSSupport=1 + +# Enable support for Implicit Trigger of TDLS. That is, wlan driver shall +# initiate TDLS Discovery towards a peer whenever setup criteria (throughput +# and RSSI) is met and then will initiate teardown when teardown criteria +# (idle packet count and RSSI) is met. +# 0 - disable +# 1 - enable +gEnableTDLSImplicitTrigger=1 + +# 0: Disable BPF packet filter +# 1: Enable BPF packet filter +gBpfFilterEnable=1 + +# set modulated DTIM interval +gEnableModulatedDTIM=3 +gMaxLIModulatedDTIM=3 + +#disable probe request deferral +oce_enable_probe_req_deferral=0 + +# WLM latency Enable +wlm_latency_enable=1 + +# WLM flags setting for ultralow level, bit9 for BMPS disabled +wlm_latency_flags_ultralow=0xe03 + +#Enable ETSI SRD channels by Xiaomi. Qualcom default value is disable +#ExtB HONGMI-117643,liupeng.wt.Add,20211221 add SAP + p2p mode +etsi13_srd_chan_in_master_mode=3 + +# Allow STASAP SCC on DFS channel with master mode support disabled +# PICASSO-986 +g_sta_sap_scc_on_dfs_chan=1 + +#max time for active 2G channel scan. +#if set to zero, gActiveMaxChannelTime is used for 2G channel scan. +active_max_channel_time_2g=0 + +# Create another interface during driver load +gEnableConcurrentSTA=wlan1 + +# mawc_roam_enabled - Enable/Disable MAWC during roaming +mawc_roam_enabled=0 + +# Enable/Disable the Motion Aided Wireless Connectivity +# based NLO using this parameter +mawc_nlo_enabled=0 + +# Enable Packet filters before going into suspend +# will clear those when resume +# bit-0 : drop MAC multicast and IPv4 multicast +# bit-1 : drop MAC unicast and IPv4 multicast +# bit-2 : drop IPv4 broadcast +# bit-3 : drop XID - Exchange station Identification packet +# bit-4 : drop STP - Spanning Tree Protocol +# bit-5 : drop DTP/LLC/CDP +g_enable_packet_filter_bitmap=0 +# This ini is used to allow STASAP SCC on LTE coex channel +# 0 - Disallow STASAP SCC on LTE coex channel +# 1 - Allow STASAP SCC on LTE coex channel +g_sta_sap_scc_on_lte_coex_chan=1 + +# enable/disable GCMP to fix throughput issue +gcmp_enabled=1 + +drop_bcn_on_chan_mismatch=0 + +#ExtB HONGMI-118308,jiyanan.wt,ADD,20220104,enable indoor channel in SAP mode +gindoor_channel_support=1 + +END + +# Note: Configuration parser would not read anything past the END marker diff --git a/wifi/p2p_supplicant_overlay.conf b/wifi/p2p_supplicant_overlay.conf new file mode 100644 index 0000000..2b27c5b --- /dev/null +++ b/wifi/p2p_supplicant_overlay.conf @@ -0,0 +1,4 @@ +disable_scan_offload=1 +p2p_no_group_iface=1 +persistent_reconnect=1 +bss_max_count=400 diff --git a/wifi/wpa_supplicant_overlay.conf b/wifi/wpa_supplicant_overlay.conf new file mode 100644 index 0000000..2b924ac --- /dev/null +++ b/wifi/wpa_supplicant_overlay.conf @@ -0,0 +1,8 @@ +disable_scan_offload=1 +p2p_disabled=1 +tdls_external_control=1 +wowlan_triggers=magic_pkt +bss_max_count=400 +interworking=1 +config_methods=virtual_display virtual_push_button keypad +driver_param="use_p2p_group_interface=1 no_rrm=1" -- cgit v1.2.3