• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GNSS_ABILITY_H
17 #define GNSS_ABILITY_H
18 
19 #include <mutex>
20 #include <singleton.h>
21 #include <v1_0/ignss_interface.h>
22 #include <v1_0/ia_gnss_interface.h>
23 
24 #include "event_handler.h"
25 #include "system_ability.h"
26 
27 #include "agnss_event_callback.h"
28 #include "common_utils.h"
29 #include "constant_definition.h"
30 #include "gnss_ability_skeleton.h"
31 #include "i_gnss_status_callback.h"
32 #include "i_nmea_message_callback.h"
33 #include "subability_common.h"
34 
35 namespace OHOS {
36 namespace Location {
37 #ifdef __aarch64__
38 #define VENDOR_GNSS_ADAPTER_SO_PATH "/system/lib64/vendorGnssAdapter.so"
39 #else
40 #define VENDOR_GNSS_ADAPTER_SO_PATH "/system/lib/vendorGnssAdapter.so"
41 #endif
42 
43 using HDI::Location::Gnss::V1_0::IGnssInterface;
44 using HDI::Location::Gnss::V1_0::IGnssCallback;
45 using HDI::Location::Gnss::V1_0::GNSS_START_TYPE_NORMAL;
46 using HDI::Location::Gnss::V1_0::GNSS_STATUS_NONE;
47 using HDI::Location::Gnss::V1_0::GNSS_STATUS_SESSION_BEGIN;
48 using HDI::Location::Gnss::V1_0::GNSS_STATUS_SESSION_END;
49 using HDI::Location::Gnss::V1_0::GNSS_STATUS_ENGINE_ON;
50 using HDI::Location::Gnss::V1_0::GNSS_STATUS_ENGINE_OFF;
51 using HDI::Location::Agnss::V1_0::IAGnssInterface;
52 using HDI::Location::Agnss::V1_0::IAGnssCallback;
53 using HDI::Location::Agnss::V1_0::AGNSS_TYPE_SUPL;
54 using HDI::Location::Agnss::V1_0::AGnssServerInfo;
55 
56 class GnssHandler : public AppExecFwk::EventHandler {
57 public:
58     explicit GnssHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner);
59     ~GnssHandler() override;
60     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override;
61 };
62 
63 class GnssAbility : public SystemAbility, public GnssAbilityStub, public SubAbility, DelayedSingleton<GnssAbility> {
64 DECLEAR_SYSTEM_ABILITY(GnssAbility);
65 
66 public:
67     DISALLOW_COPY_AND_MOVE(GnssAbility);
68     GnssAbility();
69     ~GnssAbility() override;
70     void OnStart() override;
71     void OnStop() override;
QueryServiceState()72     ServiceRunningState QueryServiceState() const
73     {
74         return state_;
75     }
76     LocationErrCode SendLocationRequest(WorkRecord &workrecord) override;
77     LocationErrCode SetEnable(bool state) override;
78     LocationErrCode RefrashRequirements() override;
79     LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
80     LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) override;
81     LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) override;
82     LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) override;
83     LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request,
84         const sptr<IRemoteObject>& callback) override;
85     LocationErrCode UnregisterCachedCallback(const sptr<IRemoteObject>& callback) override;
86     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
87     LocationErrCode GetCachedGnssLocationsSize(int &size) override;
88     LocationErrCode FlushCachedGnssLocations() override;
89     LocationErrCode SendCommand(std::unique_ptr<LocationCommand>& commands) override;
90     LocationErrCode AddFence(std::unique_ptr<GeofenceRequest>& request) override;
91     LocationErrCode RemoveFence(std::unique_ptr<GeofenceRequest>& request) override;
92     void ReportGnssSessionStatus(int status);
93     void ReportNmea(int64_t timestamp, const std::string &nmea);
94     void ReportSv(const std::unique_ptr<SatelliteStatus> &sv);
95     LocationErrCode EnableMock() override;
96     LocationErrCode DisableMock() override;
97     LocationErrCode SetMocked(const int timeInterval, const std::vector<std::shared_ptr<Location>> &location) override;
98     void RequestRecord(WorkRecord &workRecord, bool isAdded) override;
99     void SendReportMockLocationEvent() override;
100     void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) override;
101     void StartGnss();
102     void StopGnss();
103     bool EnableGnss();
104     void DisableGnss();
105     bool ConnectHdi();
106     bool RemoveHdi();
107     void SetAgnssServer();
108     void SetAgnssCallback();
109     void SetSetId(const SubscriberSetId& id);
110     void SetRefInfo(const AGnssRefInfo& refInfo);
111     bool IsMockEnabled();
112     void ProcessReportLocationMock();
113 private:
114     bool Init();
115     static void SaDumpInfo(std::string& result);
116     bool IsGnssEnabled();
117     int32_t ReportMockedLocation(const std::shared_ptr<Location> location);
118 
119     bool isHdiConnected_;
120     size_t mockLocationIndex_ = 0;
121     bool registerToAbility_ = false;
122     int gnssWorkingStatus_ = 0;
123     std::shared_ptr<GnssHandler> gnssHandler_;
124     ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
125     std::unique_ptr<std::map<pid_t, sptr<IGnssStatusCallback>>> gnssStatusCallback_;
126     std::unique_ptr<std::map<pid_t, sptr<INmeaMessageCallback>>> nmeaCallback_;
127     sptr<IGnssInterface> gnssInterface_;
128     sptr<IGnssCallback> gnssCallback_;
129     sptr<IAGnssCallback> agnssCallback_;
130     sptr<IAGnssInterface> agnssInterface_;
131     std::mutex gnssMutex_;
132 };
133 } // namespace Location
134 } // namespace OHOS
135 #endif // GNSS_ABILITY_H
136