1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifdef FEATURE_GNSS_SUPPORT
17 #include "gnss_event_callback.h"
18 #include <singleton.h>
19 #include "ipc_skeleton.h"
20 #include "common_utils.h"
21 #include "gnss_ability.h"
22 #include "location_log.h"
23
24 namespace OHOS {
25 namespace Location {
26 using namespace OHOS::HiviewDFX;
27
ReportLocation(const LocationInfo & location)28 int32_t GnssEventCallback::ReportLocation(const LocationInfo& location)
29 {
30 auto gnssAbility = DelayedSingleton<GnssAbility>::GetInstance();
31 if (gnssAbility == nullptr) {
32 LBSLOGE(GNSS, "ReportLocation: gnss ability is nullptr.");
33 return ERR_OK;
34 }
35 std::string identity = IPCSkeleton::ResetCallingIdentity();
36 std::shared_ptr<Location> locationNew = std::make_shared<Location>();
37 locationNew->SetLatitude(location.latitude);
38 locationNew->SetLongitude(location.longitude);
39 locationNew->SetAltitude(location.altitude);
40 locationNew->SetAccuracy(location.accuracy);
41 locationNew->SetSpeed(location.speed);
42 locationNew->SetDirection(location.direction);
43 locationNew->SetTimeStamp(location.timeStamp);
44 locationNew->SetTimeSinceBoot(location.timeSinceBoot);
45 locationNew->SetIsFromMock(false);
46 if (gnssAbility->IsMockEnabled()) {
47 LBSLOGE(GNSS, "location mock is enabled, do not report gnss location!");
48 IPCSkeleton::SetCallingIdentity(identity);
49 return ERR_OK;
50 }
51 gnssAbility->ReportLocationInfo(GNSS_ABILITY, locationNew);
52 #ifdef FEATURE_PASSIVE_SUPPORT
53 gnssAbility->ReportLocationInfo(PASSIVE_ABILITY, locationNew);
54 #endif
55 IPCSkeleton::SetCallingIdentity(identity);
56 return ERR_OK;
57 }
58
ReportGnssWorkingStatus(GnssWorkingStatus status)59 int32_t GnssEventCallback::ReportGnssWorkingStatus(GnssWorkingStatus status)
60 {
61 auto gnssAbility = DelayedSingleton<GnssAbility>::GetInstance();
62 if (gnssAbility == nullptr) {
63 LBSLOGE(GNSS, "ReportGnssWorkingStatus: gnss ability is nullptr.");
64 return ERR_OK;
65 }
66 gnssAbility.get()->ReportGnssSessionStatus(static_cast<int>(status));
67 return ERR_OK;
68 }
69
ReportNmea(int64_t timestamp,const std::string & nmea,int32_t length)70 int32_t GnssEventCallback::ReportNmea(int64_t timestamp, const std::string& nmea, int32_t length)
71 {
72 auto gnssAbility = DelayedSingleton<GnssAbility>::GetInstance();
73 if (gnssAbility == nullptr) {
74 LBSLOGE(GNSS, "ReportNmea: gnss ability is nullptr.");
75 return ERR_OK;
76 }
77 std::string nmeaStr = nmea;
78 gnssAbility.get()->ReportNmea(timestamp, nmeaStr);
79 return ERR_OK;
80 }
81
ReportGnssCapabilities(GnssCapabilities capabilities)82 int32_t GnssEventCallback::ReportGnssCapabilities(GnssCapabilities capabilities)
83 {
84 return ERR_OK;
85 }
86
ReportSatelliteStatusInfo(const SatelliteStatusInfo & info)87 int32_t GnssEventCallback::ReportSatelliteStatusInfo(const SatelliteStatusInfo& info)
88 {
89 auto gnssAbility = DelayedSingleton<GnssAbility>::GetInstance();
90 if (gnssAbility == nullptr) {
91 LBSLOGE(GNSS, "ReportSatelliteStatusInfo: gnss ability is nullptr.");
92 return ERR_OK;
93 }
94 std::unique_ptr<SatelliteStatus> svStatus = std::make_unique<SatelliteStatus>();
95 if (info.satellitesNumber <= 0) {
96 LBSLOGD(GNSS, "SvStatusCallback, satellites_num <= 0!");
97 return ERR_INVALID_VALUE;
98 }
99
100 svStatus->SetSatellitesNumber(info.satellitesNumber);
101 for (unsigned int i = 0; i < info.satellitesNumber; i++) {
102 svStatus->SetAltitude(info.elevation[i]);
103 svStatus->SetAzimuth(info.azimuths[i]);
104 svStatus->SetCarrierFrequencie(info.carrierFrequencies[i]);
105 svStatus->SetCarrierToNoiseDensity(info.carrierToNoiseDensitys[i]);
106 svStatus->SetSatelliteId(info.satelliteIds[i]);
107 }
108 gnssAbility.get()->ReportSv(svStatus);
109 return ERR_OK;
110 }
111
RequestGnssReferenceInfo(GnssRefInfoType type)112 int32_t GnssEventCallback::RequestGnssReferenceInfo(GnssRefInfoType type)
113 {
114 return ERR_OK;
115 }
116
RequestPredictGnssData()117 int32_t GnssEventCallback::RequestPredictGnssData()
118 {
119 return ERR_OK;
120 }
121
ReportCachedLocation(const std::vector<LocationInfo> & gnssLocations)122 int32_t GnssEventCallback::ReportCachedLocation(const std::vector<LocationInfo>& gnssLocations)
123 {
124 return ERR_OK;
125 }
126 } // namespace Location
127 } // namespace OHOS
128 #endif
129