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_SERVICE_CLIENT_H
17 #define SATELLITE_SERVICE_CLIENT_H
18 
19 #include <cstdint>
20 
21 #include "i_satellite_service.h"
22 #include "iremote_object.h"
23 #include "network_search_handler.h"
24 #include "sim_state_handle.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class SatelliteServiceClient : public std::enable_shared_from_this<SatelliteServiceClient> {
30     DECLARE_DELAYED_SINGLETON(SatelliteServiceClient);
31 
32 public:
33     sptr<ISatelliteService> GetProxy();
34     void OnRemoteDied(const wptr<IRemoteObject> &remote);
35     bool IsSatelliteEnabled();
36     int32_t AddSimHandler(int32_t slotId, const std::shared_ptr<TelEventHandler> &handler);
37     int32_t AddNetworkHandler(int32_t slotId, const std::shared_ptr<TelEventHandler> &handler);
38     int32_t RegisterCoreNotify(int32_t slotId, int32_t what, const sptr<ISatelliteCoreCallback> &callback);
39     int32_t UnRegisterCoreNotify(int32_t slotId, int32_t what);
40     int32_t SetRadioState(int32_t slotId, int32_t isRadioOn, int32_t rst);
41     std::string GetImei();
42     int32_t GetSatelliteCapability();
43     sptr<IRemoteObject> GetProxyObjectPtr(SatelliteServiceProxyType type);
44 
45 private:
46     void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
47     void ServiceOn();
48     void ServiceOff();
49 
50     class SatelliteServiceDeathRecipient : public IRemoteObject::DeathRecipient {
51     public:
SatelliteServiceDeathRecipient(SatelliteServiceClient & client)52         explicit SatelliteServiceDeathRecipient(SatelliteServiceClient &client) : client_(client) {}
53         ~SatelliteServiceDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)54         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
55         {
56             client_.OnRemoteDied(remote);
57         }
58 
59     private:
60         SatelliteServiceClient &client_;
61     };
62 
63     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
64     public:
SystemAbilityListener()65         SystemAbilityListener() {}
~SystemAbilityListener()66         ~SystemAbilityListener() {}
67 
68     public:
69         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
70         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
71     };
72 
73 private:
74     std::mutex mutexProxy_;
75     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
76     sptr<ISatelliteService> proxy_ { nullptr };
77     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
78     std::map<int32_t, std::shared_ptr<TelEventHandler>> simHandlerMap_;
79     std::map<int32_t, std::shared_ptr<TelEventHandler>> networkHandlerMap_;
80 };
81 } // namespace Telephony
82 } // namespace OHOS
83 #endif // SATELLITE_SERVICE_CLIENT_H
84