• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 OHOS_MULTI_SIM_CONTROLLER_H
17 #define OHOS_MULTI_SIM_CONTROLLER_H
18 
19 #include <list>
20 
21 #include <ffrt.h>
22 #include "if_system_ability_manager.h"
23 #include "radio_protocol_controller.h"
24 #include "sim_constant.h"
25 #include "sim_file_manager.h"
26 #include "sim_rdb_helper.h"
27 #include "sim_state_manager.h"
28 #include "telephony_errors.h"
29 #include "tel_event_handler.h"
30 #include "want.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 class MultiSimController : public TelEventHandler {
35 public:
36     MultiSimController(std::shared_ptr<Telephony::ITelRilManager> telRilManager,
37         std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager,
38         std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager);
39     virtual ~MultiSimController();
40 
41     void AddExtraManagers(std::shared_ptr<Telephony::SimStateManager> simStateManager,
42         std::shared_ptr<Telephony::SimFileManager> simFileManager);
43 
44     void Init();
45     bool InitData(int32_t slotId);
46     int32_t GetDefaultVoiceSlotId();
47     int32_t SetDefaultVoiceSlotId(int32_t slotId);
48     int32_t GetDefaultSmsSlotId();
49     int32_t SetDefaultSmsSlotId(int32_t slotId);
50     int32_t GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info);
51     int32_t GetDefaultCellularDataSlotId();
52     int32_t SetDefaultCellularDataSlotId(int32_t slotId);
53     int32_t GetPrimarySlotId();
54     int32_t SetPrimarySlotId(int32_t slotId);
55     int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber);
56     int32_t SetShowNumber(int32_t slotId, std::u16string Number, bool force = false);
57     int32_t SetShowNumberToDB(int32_t slotId, std::u16string Number);
58     int32_t GetShowName(int32_t slotId, std::u16string &showName);
59     int32_t SetShowName(int32_t slotId, std::u16string name, bool force = false);
60     int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber);
61     bool IsSimActive(int32_t slotId);
62     int32_t SetActiveSim(int32_t slotId, int32_t enable, bool force = false);
63     int32_t SetActiveSimSatellite(int32_t slotId, int32_t enable, bool force = false);
64     bool SetActiveSimToRil(int32_t slotId, int32_t type, int32_t enable);
65     bool ForgetAllData();
66     bool ForgetAllData(int32_t slotId);
67     void ResetSetPrimarySlotRemain(int32_t slotId);
68     int32_t GetSlotId(int32_t simId);
69     int32_t GetSimId(int32_t slotId);
70     int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue);
71     int32_t QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue);
72     bool GetListFromDataBase();
73     int32_t GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList);
74     int32_t GetRadioProtocolTech(int32_t slotId);
75     void GetRadioProtocol(int32_t slotId);
76     bool InitShowName(int slotId);
77     void ReCheckPrimary();
78     bool IsDataShareError();
79     void ResetDataShareError();
80     int32_t UpdateOpKeyInfo();
81     bool IsSetActiveSimInProgress(int32_t slotId);
82     bool IsSetPrimarySlotIdInProgress();
83     int32_t SavePrimarySlotId(int32_t slotId);
84     int32_t GetDefaultMainSlotByIccId();
85 
86 public:
87     int32_t unInitModemSlotId_ = INVALID_VALUE;
88     static constexpr const char *PHONE_NUMBER_PREF = "sim_number_";
89     enum {
90         SET_PRIMARY_SLOT_RETRY_EVENT = 0,
91     };
92 
93 private:
94     bool IsValidData(int32_t slotId);
95     int32_t GetFirstActivedSlotId();
96     bool InitShowNumber(int slotId);
97     bool InitActive(int slotId);
98     bool InitIccId(int slotId);
99     int32_t UpdateDataByIccId(int slotId, const std::string &newIccId);
100     int32_t InsertData(int slotId, const std::string &newIccId);
101     void SortCache();
102     void SavePrimarySlotIdInfo(int32_t slotId);
103     void SaveDefaultCellularDataSlotIdInfo(int32_t slotId);
104     bool AnnouncePrimarySimIdChanged(int32_t simId);
105     bool AnnounceDefaultVoiceSimIdChanged(int32_t simId);
106     bool AnnounceDefaultSmsSimIdChanged(int32_t simId);
107     bool AnnounceDefaultCellularDataSimIdChanged(int32_t simId);
108     bool PublishSimFileEvent(const AAFwk::Want &want, int eventCode, const std::string &eventData);
109     bool RefreshActiveIccAccountInfoList();
110     std::string EncryptIccId(const std::string iccid);
111     void CheckIfNeedSwitchMainSlotId();
112     bool IsValidSlotId(int32_t slotId);
113     bool InitPrimary();
114     bool IsAllCardsReady();
115     bool IsAllCardsLoaded();
116     void SendMainCardBroadCast(int32_t slotId);
117     void SendDefaultCellularDataBroadCast(int32_t slotId);
118     void InitMainCardSlotId();
119     void PublishSetPrimaryEvent(bool setDone);
120     int32_t GetTargetDefaultSimId(int32_t slotId, int &simId);
121     size_t GetLocalCacheSize();
122     int32_t GetTargetSimId(int32_t slotId, int &simId);
123     int32_t GetTargetIccId(int32_t slotId, std::string &iccId);
124     bool IsAllModemInitDone();
125     int32_t IsSatelliteSupported();
126     int32_t SetActiveCommonSim(int32_t slotId, int32_t enable, bool force, int32_t curSimId);
127     void UpdateSubState(int32_t slotId, int32_t enable);
128     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
129     void SetPrimarySlotIdDone();
130 
131 private:
132     const int32_t IMS_SWITCH_STATUS_UNKNOWN = -1;
133     const int ACTIVE_SIM_IN_PROGRESS = 1;
134     const int ACTIVE_SIM_NOT_IN_PROGRESS = 0;
135     ffrt::condition_variable activeSimConn_;
136     ffrt::mutex activeSimMutex_;
137     int32_t maxCount_ = 0;
138     int32_t primarySimId_ = 0;
139     int32_t defaultSmsSimId_ = 0;
140     int32_t defaultCellularSimId_ = 0;
141     int32_t defaultVoiceSimId_ = 0;
142     int32_t lastPrimarySlotId_ = 0;
143     int32_t lastCellularDataSlotId_ = 0;
144     static constexpr int32_t WAIT_REMOTE_TIME_SEC = 4;
145     std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_;
146     std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_;
147     std::unique_ptr<SimRdbHelper> simDbHelper_ = nullptr;
148     IccAccountInfo iccAccountInfo_;
149     std::vector<IccAccountInfo> iccAccountInfoList_;
150     std::vector<SimRdbInfo> localCacheInfo_;
151     ffrt::mutex mutex_;
152     std::shared_ptr<RadioProtocolController> radioProtocolController_ = nullptr;
153     std::vector<int> isSetActiveSimInProgress_;
154     std::vector<int> setPrimarySlotRemainCount_;
155     bool isSetPrimarySlotIdInProgress_ = false;
156 };
157 } // namespace Telephony
158 } // namespace OHOS
159 #endif // OHOS_MULTI_SIM_CONTROLLER_H
160