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 OHOS_MULTI_SIM_MONITOR_H 17 #define OHOS_MULTI_SIM_MONITOR_H 18 19 #include <list> 20 21 #include "multi_sim_controller.h" 22 #include "sim_file_manager.h" 23 #include "telephony_log_wrapper.h" 24 #include "sim_constant.h" 25 #include "sim_data.h" 26 #include "rdb_sim_helper.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 class MultiSimMonitor : public AppExecFwk::EventHandler { 31 public: 32 MultiSimMonitor(const std::shared_ptr<AppExecFwk::EventRunner> &runner, 33 const std::shared_ptr<MultiSimController> &controller, 34 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager, 35 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager); 36 virtual ~MultiSimMonitor() = default; 37 38 void Init(); 39 bool RegisterForIccLoaded(int32_t slotId); 40 bool UnRegisterForIccLoaded(int32_t slotId); 41 bool RegisterForSimStateChanged(int32_t slotId); 42 bool UnRegisterForSimStateChanged(int32_t slotId); 43 void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what); 44 int32_t RegisterSimAccountCallback(const std::string &bundleName, const sptr<SimAccountCallback> &callback); 45 int32_t UnregisterSimAccountCallback(const std::string &bundleName); 46 void NotifySimAccountChanged(); 47 48 private: 49 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 50 void RefreshData(int32_t slotId); 51 void InitData(int32_t slotId); 52 bool IsValidSlotId(int32_t slotId); 53 54 private: 55 struct SimAccountCallbackRecord { 56 std::string bundleName; 57 sptr<SimAccountCallback> simAccountCallback; 58 }; 59 60 bool ready_ = false; 61 std::shared_ptr<MultiSimController> controller_ = nullptr; 62 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 63 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 64 std::unique_ptr<ObserverHandler> observerHandler_ = nullptr; 65 std::list<SimAccountCallbackRecord> listSimAccountCallbackRecord_; 66 std::mutex mutexInner_; 67 }; 68 } // namespace Telephony 69 } // namespace OHOS 70 #endif // OHOS_MULTI_SIM_MONITOR_H 71 72