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 TELEPHONY_IMS_SMS_CLIENT_H 17 #define TELEPHONY_IMS_SMS_CLIENT_H 18 19 #include "event_handler.h" 20 #include "event_runner.h" 21 #include "ims_core_service_interface.h" 22 #include "ims_sms_interface.h" 23 #include "iremote_stub.h" 24 #include "rwlock.h" 25 #include "singleton.h" 26 #include "system_ability_status_change_stub.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 class ImsSmsClient { 31 DECLARE_DELAYED_SINGLETON(ImsSmsClient); 32 33 public: 34 /** 35 * Get ImsSms Remote Object 36 * 37 * @return sptr<ImsSmsInterface> 38 */ 39 sptr<ImsSmsInterface> GetImsSmsProxy(); 40 41 void Init(); 42 void UnInit(); 43 int32_t RegisterImsSmsCallbackHandler(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler); 44 45 /** 46 * Get Handler 47 * 48 * @param slotId Indicates the card slot index number, 49 * ranging from {@code 0} to the maximum card slot index number supported by the device. 50 * @return AppExecFwk::EventHandler 51 */ 52 std::shared_ptr<AppExecFwk::EventHandler> GetHandler(int32_t slotId); 53 54 /****************** sms basic ******************/ 55 int32_t ImsSendMessage(int32_t slotId, const ImsMessageInfo &imsMessageInfo); 56 int32_t ImsSetSmsConfig(int32_t slotId, int32_t imsSmsConfig); 57 int32_t ImsGetSmsConfig(int32_t slotId); 58 59 private: 60 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 61 public: SystemAbilityListener()62 SystemAbilityListener() {} ~SystemAbilityListener()63 ~SystemAbilityListener() {} 64 public: 65 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 66 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 67 }; 68 69 /** 70 * Is Connect ImsSms Remote Object 71 * 72 * @return bool 73 */ 74 bool IsConnect() const; 75 int32_t RegisterImsSmsCallback(); 76 int32_t ReConnectService(); 77 void Clean(); 78 79 private: 80 sptr<ImsCoreServiceInterface> imsCoreServiceProxy_ = nullptr; 81 sptr<ImsSmsInterface> imsSmsProxy_ = nullptr; 82 sptr<ImsSmsCallbackInterface> imsSmsCallback_ = nullptr; 83 std::map<int32_t, std::shared_ptr<AppExecFwk::EventHandler>> handlerMap_; 84 Utils::RWLock rwClientLock_; 85 std::mutex mutex_; 86 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 87 }; 88 } // namespace Telephony 89 } // namespace OHOS 90 91 #endif // TELEPHONY_IMS_SMS_CLIENT_H 92