1 /* 2 * Copyright (C) 2021 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_SIMSTATETRACKER_H 17 #define TELEPHONY_SIMSTATETRACKER_H 18 19 #include <string> 20 21 #include "common_event_subscriber.h" 22 #include "iservice_registry.h" 23 #include "operator_config_cache.h" 24 #include "operator_config_loader.h" 25 #include "system_ability_definition.h" 26 #include "system_ability_status_change_stub.h" 27 #include "telephony_log_wrapper.h" 28 29 namespace OHOS { 30 namespace Telephony { 31 using namespace OHOS::EventFwk; 32 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 33 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 34 class SimStateTracker : public TelEventHandler { 35 public: 36 SimStateTracker(std::weak_ptr<SimFileManager> simFileManager, 37 std::shared_ptr<OperatorConfigCache> operatorConfigCache, int32_t slotId); 38 ~SimStateTracker(); 39 void InitListener(); 40 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 41 bool RegisterForIccLoaded(); 42 bool UnRegisterForIccLoaded(); 43 44 std::shared_ptr<OperatorConfigLoader> operatorConfigLoader_ = nullptr; 45 46 private: 47 inline static const std::string OPERATOR_CONFIG_CHANGED = "operatorConfigChanged"; 48 std::weak_ptr<SimFileManager> simFileManager_; 49 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 50 std::shared_ptr<OperatorConfigCache> operatorConfigCache_ = nullptr; 51 int32_t slotId_; 52 OperatorConfig config_; 53 54 private: 55 class UserSwitchEventSubscriber : public CommonEventSubscriber { 56 public: UserSwitchEventSubscriber(const CommonEventSubscribeInfo & info,int32_t slotId,std::shared_ptr<OperatorConfigLoader> configLoader)57 explicit UserSwitchEventSubscriber( 58 const CommonEventSubscribeInfo &info, int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader) 59 : CommonEventSubscriber(info), slotId_(slotId), configLoader_(configLoader) 60 {} 61 ~UserSwitchEventSubscriber() = default; 62 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 63 64 private: 65 const int32_t slotId_; 66 std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr; 67 }; 68 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 69 public: 70 explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader); 71 ~SystemAbilityStatusChangeListener() = default; 72 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 73 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 74 75 private: 76 const int32_t slotId_; 77 std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr; 78 std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr; 79 }; 80 }; 81 } // namespace Telephony 82 } // namespace OHOS 83 #endif // TELEPHONY_SIMSTATETRACKER_H