• 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 BASE_PHONE_SERVICE_H
17 #define BASE_PHONE_SERVICE_H
18 
19 #include "core_service_stub.h"
20 #include "i_network_search.h"
21 #include "i_sim_manager.h"
22 #include "i_esim_manager.h"
23 #include "i_tel_ril_manager.h"
24 #include "if_system_ability_manager.h"
25 #include "singleton.h"
26 #include "system_ability.h"
27 #include "tel_ril_sim_parcel.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 static const int32_t DEFAULT_SLOT_ID = 0;
32 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
33 class CoreService : public SystemAbility, public CoreServiceStub {
34     DECLARE_DELAYED_SINGLETON(CoreService)
35     DECLARE_SYSTEM_ABILITY(CoreService)
36 
37 public:
38     void OnStart() override;
39 
40     void OnStop() override;
41 
42     int32_t GetPsRadioTech(int32_t slotId, int32_t &psRadioTech) override;
43 
44     int32_t GetCsRadioTech(int32_t slotId, int32_t &csRadioTech) override;
45 
46     int32_t GetSignalInfoList(int32_t slotId, std::vector<sptr<SignalInformation>> &signals) override;
47 
48     std::u16string GetOperatorNumeric(int32_t slotId) override;
49 
50     std::string GetResidentNetworkNumeric(int32_t slotId) override;
51 
52     int32_t GetOperatorName(int32_t slotId, std::u16string &operatorName) override;
53 
54     int32_t GetNetworkState(int32_t slotId, sptr<NetworkState> &networkState) override;
55 
56     int32_t SetRadioState(int32_t slotId, bool isOn, const sptr<INetworkSearchCallback> &callback) override;
57 
58     int32_t GetRadioState(int32_t slotId, const sptr<INetworkSearchCallback> &callback) override;
59 
60     int32_t GetImei(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
61 
62     int32_t GetImeiSv(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
63 
64     int32_t GetMeid(int32_t slotId, std::u16string &meid) override;
65 
66     int32_t GetUniqueDeviceId(int32_t slotId, std::u16string &deviceId) override;
67 
68     bool IsNrSupported(int32_t slotId) override;
69 
70     int32_t SetNrOptionMode(int32_t slotId, int32_t mode, const sptr<INetworkSearchCallback> &callback) override;
71 
72     int32_t GetNrOptionMode(int32_t slotId, const sptr<INetworkSearchCallback> &callback) override;
73 
74     int32_t HasSimCard(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
75 
76     int32_t GetSimState(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
77 
78     int32_t GetDsdsMode(int32_t &dsdsMode) override;
79 
80     int32_t GetCardType(int32_t slotId, CardType &cardType) override;
81 
82     int32_t GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric) override;
83 
84     int32_t GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode) override;
85 
86     int32_t GetSimSpn(int32_t slotId, std::u16string &spn) override;
87 
88     int32_t GetSimIccId(int32_t slotId, std::u16string &iccId) override;
89 
90     int32_t GetIMSI(int32_t slotId, std::u16string &imsi) override;
91 
92     int32_t IsCTSimCard(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
93 
94     bool IsSimActive(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
95 
96     int32_t GetSlotId(int32_t simId) override;
97 
98     int32_t GetSimId(int32_t slotId) override;
99 
100     int32_t GetNetworkSearchInformation(int32_t slotId, const sptr<INetworkSearchCallback> &callback) override;
101 
102     int32_t GetNetworkSelectionMode(int32_t slotId, const sptr<INetworkSearchCallback> &callback) override;
103 
104     std::u16string GetLocaleFromDefaultSim() override;
105 
106     int32_t GetSimGid1(int32_t slotId, std::u16string &gid1) override;
107 
108     std::u16string GetSimGid2(int32_t slotId) override;
109 
110     std::u16string GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired) override;
111 
112     int32_t SetNetworkSelectionMode(int32_t slotId, int32_t selectMode,
113         const sptr<NetworkInformation> &networkInformation, bool resumeSelection,
114         const sptr<INetworkSearchCallback> &callback) override;
115 
116     int32_t GetIsoCountryCodeForNetwork(int32_t slotId, std::u16string &countryCode) override;
117 
118     int32_t UnlockPin(int32_t slotId, const std::u16string &pin, const sptr<IRawParcelCallback> &callback) override;
119 
120     int32_t UnlockPuk(int32_t slotId, const std::u16string &newPin, const std::u16string &puk,
121         const sptr<IRawParcelCallback> &callback) override;
122 
123     int32_t AlterPin(int32_t slotId, const std::u16string &newPin, const std::u16string &oldPin,
124         const sptr<IRawParcelCallback> &callback) override;
125 
126     int32_t UnlockPin2(int32_t slotId, const std::u16string &pin2, const sptr<IRawParcelCallback> &callback) override;
127 
128     int32_t UnlockPuk2(int32_t slotId, const std::u16string &newPin2, const std::u16string &puk2,
129         const sptr<IRawParcelCallback> &callback) override;
130 
131     int32_t AlterPin2(int32_t slotId, const std::u16string &newPin2, const std::u16string &oldPin2,
132         const sptr<IRawParcelCallback> &callback) override;
133 
134     int32_t SetLockState(int32_t slotId, const LockInfo &options, const sptr<IRawParcelCallback> &callback) override;
135 
136     int32_t GetLockState(int32_t slotId, LockType lockType, const sptr<IRawParcelCallback> &callback) override;
137 
138     int32_t GetSimAccountInfo(int32_t slotId, IccAccountInfo &info) override;
139 
140     int32_t SetDefaultVoiceSlotId(int32_t slotId) override;
141 
142     int32_t GetDefaultVoiceSlotId() override;
143 
144     int32_t GetDefaultVoiceSimId(const sptr<IRawParcelCallback> &callback) override;
145 
146     int32_t SetPrimarySlotId(int32_t slotId) override;
147 
148     int32_t GetPrimarySlotId(int32_t &slotId) override;
149 
150     int32_t SetShowNumber(int32_t slotId, const std::u16string &number,
151         const sptr<IRawParcelCallback> &callback) override;
152 
153     int32_t GetShowNumber(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
154 
155     int32_t SetShowName(int32_t slotId, const std::u16string &name, const sptr<IRawParcelCallback> &callback) override;
156 
157     int32_t GetShowName(int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
158 
159     int32_t RefreshSimState(int32_t slotId) override;
160 
161     int32_t SetActiveSim(int32_t slotId, int32_t enable) override;
162 
163     int32_t SetActiveSimSatellite(int32_t slotId, int32_t enable) override;
164 
165     int32_t GetPreferredNetwork(int32_t slotId, const sptr<INetworkSearchCallback> &callback) override;
166 
167     int32_t SetPreferredNetwork(
168         int32_t slotId, int32_t networkMode, const sptr<INetworkSearchCallback> &callback) override;
169 
170     int32_t GetNetworkCapability(
171         int32_t slotId, int32_t networkCapabilityType, int32_t &networkCapabilitytate) override;
172 
173     int32_t SetNetworkCapability(int32_t slotId, int32_t networkCapabilityType, int32_t networkCapabilitytate) override;
174 
175     int32_t GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList) override;
176 
177     int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc) override;
178 
179     int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber) override;
180 
181     std::u16string GetSimTeleNumberIdentifier(const int32_t slotId) override;
182 
183     int32_t GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier) override;
184 
185     int32_t GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber) override;
186 
187     int32_t GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount) override;
188 
189     int32_t SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount) override;
190 
191     int32_t SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number) override;
192 
193     int32_t QueryIccDiallingNumbers(
194         int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result) override;
195 
196     int32_t AddIccDiallingNumbers(
197         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
198 
199     int32_t DelIccDiallingNumbers(
200         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
201 
202     int32_t UpdateIccDiallingNumbers(
203         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
204 
205     int32_t SetVoiceMailInfo(
206         const int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber) override;
207 
208     int32_t GetImsRegStatus(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) override;
209 
210     int32_t GetMaxSimCount() override;
211 
212     int32_t GetOpKey(int32_t slotId, std::u16string &opkey) override;
213 
214     int32_t GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt) override;
215 
216     int32_t GetOpName(int32_t slotId, std::u16string &opname) override;
217 
218     int32_t SendEnvelopeCmd(int32_t slotId, const std::string &cmd) override;
219 
220     int32_t SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) override;
221 
222     int32_t SendCallSetupRequestResult(int32_t slotId, bool accept) override;
223 
224     int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response) override;
225 
226     int32_t GetCellInfoList(int32_t slotId, std::vector<sptr<CellInformation>> &cellInfo) override;
227 
228     int32_t GetNeighboringCellInfoList(int32_t slotId, std::vector<sptr<CellInformation>> &cellInfo) override;
229 
230     int32_t SendUpdateCellLocationRequest(int32_t slotId) override;
231 
232     int32_t HasOperatorPrivileges(const int32_t slotId, const sptr<IRawParcelCallback> &callback) override;
233 
234     int32_t SimAuthentication(
235         int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response) override;
236 
237     int32_t RegisterImsRegInfoCallback(
238         int32_t slotId, ImsServiceType imsSrvType, const sptr<ImsRegInfoCallback> &callback) override;
239 
240     int32_t UnregisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType) override;
241 
242     int32_t GetBasebandVersion(int32_t slotId, std::string &version) override;
243 
244     int32_t FactoryReset(int32_t slotId) override;
245 
246     int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override;
247 
248     int64_t GetBindTime();
249 
250     int64_t GetEndTime();
251 
252     int64_t GetSpendTime();
253 
254     int32_t GetServiceRunningState();
255 
256     int32_t GetNrSsbIdInfo(int32_t slotId, const std::shared_ptr<NrSsbInformation> &nrSsbInformation) override;
257 
258     bool IsAllowedInsertApn(std::string &value) override;
259 
260     int32_t GetTargetOpkey(int32_t slotId, std::u16string &opkey) override;
261 
262     int32_t GetOpkeyVersion(std::string &versionInfo) override;
263 
264     int32_t GetOpnameVersion(std::string &versionInfo) override;
265 
266     int32_t GetSimIO(int32_t slotId, int32_t command, int32_t fileId,
267         const std::string &data, const std::string &path, SimAuthenticationResponse &response) override;
268     int32_t GetSimLabel(int32_t slotId, SimLabel &simLabel, const sptr<IRawParcelCallback> &callback) override;
269     int32_t GetAllSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList) override;
270     int32_t SendApduData(int32_t slotId, const std::u16string &aid, const EsimApduData &apduData,
271         ResponseEsimResult &responseResult) override;
272 private:
273     bool Init();
274     bool NotifyCoreServiceReady();
275     virtual void AsyncNetSearchExecute(const std::function<void()> task);
276     virtual void AsyncSimGeneralExecute(const std::function<void()> task);
277     virtual void AsyncSimPinExecute(const std::function<void()> task);
278 
279 private:
280     int32_t slotId_ = DEFAULT_SLOT_ID;
281     bool registerToService_ = false;
282     sptr<ISystemAbilityManager> systemManager_ = nullptr;
283     ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
284     std::shared_ptr<ISimManager> simManager_ = nullptr;
285     std::shared_ptr<IEsimManager> esimManager_ = nullptr;
286     std::shared_ptr<INetworkSearch> networkSearchManager_ = nullptr;
287     std::shared_ptr<ITelRilManager> telRilManager_ = nullptr;
288     std::shared_ptr<AppExecFwk::EventHandler> networkSearchManagerHandler_;
289     std::shared_ptr<AppExecFwk::EventHandler> simGeneralHandler_;
290     std::shared_ptr<AppExecFwk::EventHandler> simPinHandler_;
291     std::mutex handlerInitMutex_;
292     int64_t spendTime_ = 0;
293     int64_t bindTime_ = 0;
294     int64_t endTime_ = 0;
295 };
296 } // namespace Telephony
297 } // namespace OHOS
298 #endif // BASE_PHONE_SERVICE_H
299