15c735df2Sopenharmony_ci/*
25c735df2Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License.
55c735df2Sopenharmony_ci * You may obtain a copy of the License at
65c735df2Sopenharmony_ci *
75c735df2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85c735df2Sopenharmony_ci *
95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and
135c735df2Sopenharmony_ci * limitations under the License.
145c735df2Sopenharmony_ci */
155c735df2Sopenharmony_ci
165c735df2Sopenharmony_ci#ifndef AGNSS_NI_MANAGER_H
175c735df2Sopenharmony_ci#define AGNSS_NI_MANAGER_H
185c735df2Sopenharmony_ci#ifdef FEATURE_GNSS_SUPPORT
195c735df2Sopenharmony_ci
205c735df2Sopenharmony_ci#include <mutex>
215c735df2Sopenharmony_ci#include <singleton.h>
225c735df2Sopenharmony_ci#include <v2_0/ignss_interface.h>
235c735df2Sopenharmony_ci
245c735df2Sopenharmony_ci#include "common_utils.h"
255c735df2Sopenharmony_ci#include "constant_definition.h"
265c735df2Sopenharmony_ci#include "event_handler.h"
275c735df2Sopenharmony_ci#include "gnss_common_event_subscriber.h"
285c735df2Sopenharmony_ci#include "subability_common.h"
295c735df2Sopenharmony_ci#include "system_ability_status_change_stub.h"
305c735df2Sopenharmony_ci
315c735df2Sopenharmony_cinamespace OHOS {
325c735df2Sopenharmony_cinamespace Location {
335c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::IGnssInterface;
345c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GnssNiNotificationRequest;
355c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GnssNiRequestCategory;
365c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GnssNiResponseCmd;
375c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_NOTIFICATION_REQUIRE_NOTIFY;
385c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_NOTIFICATION_REQUIRE_VERIFY;
395c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_NOTIFICATION_REQUIRE_PRIVACY_OVERRIDE;
405c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_RESPONSE_CMD_ACCEPT;
415c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_RESPONSE_CMD_REJECT;
425c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_RESPONSE_CMD_NO_RESPONSE;
435c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_ENCODING_FORMAT_NULL;
445c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_ENCODING_FORMAT_SUPL_GSM_DEFAULT;
455c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_ENCODING_FORMAT_SUPL_UCS2;
465c735df2Sopenharmony_ciusing HDI::Location::Gnss::V2_0::GNSS_NI_ENCODING_FORMAT_SUPL_UTF8;
475c735df2Sopenharmony_ci
485c735df2Sopenharmony_ciclass SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub {
495c735df2Sopenharmony_cipublic:
505c735df2Sopenharmony_ci    void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
515c735df2Sopenharmony_ci    void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
525c735df2Sopenharmony_ci};
535c735df2Sopenharmony_ci
545c735df2Sopenharmony_ciclass AGnssNiManager {
555c735df2Sopenharmony_cipublic:
565c735df2Sopenharmony_ci    AGnssNiManager();
575c735df2Sopenharmony_ci    ~AGnssNiManager();
585c735df2Sopenharmony_ci    void Run();
595c735df2Sopenharmony_ci    void SubscribeSaStatusChangeListerner();
605c735df2Sopenharmony_ci    void RegisterAgnssNiEvent();
615c735df2Sopenharmony_ci    void UnRegisterAgnssNiEvent();
625c735df2Sopenharmony_ci    void RegisterNiResponseEvent();
635c735df2Sopenharmony_ci    void UnRegisterNiResponseEvent();
645c735df2Sopenharmony_ci    void CheckWapSuplInit(const EventFwk::Want &want);
655c735df2Sopenharmony_ci    void CheckSmsSuplInit(const EventFwk::Want &want);
665c735df2Sopenharmony_ci    void OnCallStateChanged(const EventFwk::Want &want);
675c735df2Sopenharmony_ci    void HandleNiNotification(const GnssNiNotificationRequest &notif);
685c735df2Sopenharmony_ci    void SendUserResponse(GnssNiResponseCmd responseCmd);
695c735df2Sopenharmony_ci    static AGnssNiManager* GetInstance();
705c735df2Sopenharmony_ci
715c735df2Sopenharmony_ciprivate:
725c735df2Sopenharmony_ci    void AgnssNiSuplInit();
735c735df2Sopenharmony_ci    bool IsInEmergency();
745c735df2Sopenharmony_ci    std::string BuildStartCommand(const GnssNiNotificationRequest &notif);
755c735df2Sopenharmony_ci    void OpenNiDialog(const GnssNiNotificationRequest &notif);
765c735df2Sopenharmony_ci    void SendNiNotification(const GnssNiNotificationRequest &notif);
775c735df2Sopenharmony_ci    std::string DecodeNiString(std::string original, int coding);
785c735df2Sopenharmony_ci
795c735df2Sopenharmony_ci    bool isInEmergencyCall_ = false;
805c735df2Sopenharmony_ci    short niNotificationId_ = 0;
815c735df2Sopenharmony_ci    int64_t emergencyCallEndTime_ = 0;
825c735df2Sopenharmony_ci    sptr<IGnssInterface> gnssInterface_ = nullptr;
835c735df2Sopenharmony_ci    std::shared_ptr<GnssCommonEventSubscriber> subscriber_ = nullptr;
845c735df2Sopenharmony_ci    std::shared_ptr<GnssCommonEventSubscriber> niResponseSubscriber_ = nullptr;
855c735df2Sopenharmony_ci    sptr<SystemAbilityStatusChangeListener> statusChangeListener_ = nullptr;
865c735df2Sopenharmony_ci    std::mutex mutex_;
875c735df2Sopenharmony_ci    std::mutex callStateMutex_;
885c735df2Sopenharmony_ci};
895c735df2Sopenharmony_ci} // namespace Location
905c735df2Sopenharmony_ci} // namespace OHOS
915c735df2Sopenharmony_ci
925c735df2Sopenharmony_ci#endif // FEATURE_GNSS_SUPPORT
935c735df2Sopenharmony_ci#endif // AGNSS_NI_MANAGER_H
94