1 /*
2  * Copyright (C) 2023 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 SATELLITE_SMS_CLIENT_H
17 #define SATELLITE_SMS_CLIENT_H
18 
19 #include <cstdint>
20 
21 #include "gsm_sms_receive_handler.h"
22 #include "gsm_sms_sender.h"
23 #include "i_satellite_service.h"
24 #include "iremote_object.h"
25 #include "satellite/i_satellite_sms_service.h"
26 #include "singleton.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 class SatelliteSmsClient : public DelayedRefSingleton<SatelliteSmsClient> {
31     DECLARE_DELAYED_REF_SINGLETON(SatelliteSmsClient);
32 
33 public:
34     sptr<ISatelliteSmsService> GetProxy();
35     void OnRemoteDied(const wptr<IRemoteObject> &remote);
36 
37     bool GetSatelliteSupported();
38     bool IsSatelliteEnabled();
39     int32_t GetSatelliteCapability();
40     int32_t RegisterSmsNotify(int32_t slotId, int32_t what, const sptr<ISatelliteSmsCallback> &callback);
41     int32_t UnRegisterSmsNotify(int32_t slotId, int32_t what);
42     int32_t AddSendHandler(int32_t slotId, const std::shared_ptr<TelEventHandler> sender);
43     int32_t AddReceiveHandler(int32_t slotId, const std::shared_ptr<TelEventHandler> receiver);
44 
45     int32_t SendSms(int32_t slotId, int32_t eventId, SatelliteMessage &message);
46     int32_t SendSmsMoreMode(int32_t slotId, int32_t eventId, SatelliteMessage &message);
47     int32_t SendSmsAck(int32_t slotId, int32_t eventId, bool success, int32_t cause);
48 
49 private:
50     sptr<ISatelliteService> GetServiceProxy();
51     void ServiceOn();
52     void ServiceOff();
53 
54     void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
55     class SatelliteServiceDeathRecipient : public IRemoteObject::DeathRecipient {
56     public:
SatelliteServiceDeathRecipient(SatelliteSmsClient & client)57         explicit SatelliteServiceDeathRecipient(SatelliteSmsClient &client) : client_(client) {}
58         ~SatelliteServiceDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)59         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
60         {
61             client_.OnRemoteDied(remote);
62         }
63 
64     private:
65         SatelliteSmsClient &client_;
66     };
67 
68     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
69     public:
SystemAbilityListener()70         SystemAbilityListener() {}
~SystemAbilityListener()71         ~SystemAbilityListener() {}
72 
73     public:
74         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
75         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
76     };
77 
78 private:
79     std::mutex mutexProxy_;
80     std::mutex mutexMap_;
81     sptr<ISystemAbilityStatusChange> statusChangeListener_ { nullptr };
82     sptr<ISatelliteService> satelliteServiceProxy_ { nullptr };
83     sptr<ISatelliteSmsService> proxy_ { nullptr };
84     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
85     std::map<int32_t, std::shared_ptr<TelEventHandler>> senderMap_;
86     std::map<int32_t, std::shared_ptr<TelEventHandler>> receiverMap_;
87 };
88 } // namespace Telephony
89 } // namespace OHOS
90 #endif // SATELLITE_SMS_CLIENT_H
91