• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 ESIM_SERVICE_CLIENT_H
17 #define ESIM_SERVICE_CLIENT_H
18 
19 #include <cstdint>
20 #include <iremote_object.h>
21 #include <singleton.h>
22 #include <string_ex.h>
23 
24 #include "iesim_service.h"
25 #include "iesim_service_callback.h"
26 #include "system_ability_load_callback_stub.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 class EsimServiceClientCallback : public SystemAbilityLoadCallbackStub {
31 public:
32     void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
33     void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
34     bool IsFailed();
35     const sptr<IRemoteObject> &GetRemoteObject() const;
36 
37 private:
38     bool isLoadSAFailed_ = false;
39     sptr<IRemoteObject> remoteObject_ = nullptr;
40 };
41 
42 class EsimServiceClient : public DelayedRefSingleton<EsimServiceClient> {
43     DECLARE_DELAYED_REF_SINGLETON(EsimServiceClient);
44 
45 public:
46     /**
47      * @brief Get the EID identifying for the eUICC hardware.
48      *
49      * @param slotId[in], indicates the card slot index number.
50      * @param callback[in], call back function.
51      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
52      */
53     int32_t GetEid(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
54 
55     /**
56      * @brief Get the current status of eUICC OSU.
57      *
58      * @param slotId[in], indicates the card slot index number.
59      * @param osuStatus[out], the status of eUICC OSU update.
60      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
61      */
62     int32_t GetOsuStatus(int32_t slotId, int32_t &osuStatus);
63 
64     /**
65      * @brief Execute OSU if current OSU is not the latest one.
66      *
67      * @param slotId[in], indicates the card slot index number.
68      * @param callback[in], call back function.
69      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
70      */
71     int32_t StartOsu(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
72 
73     /**
74      * @brief Fills in the metadata for a downloadable profile.
75      *
76      * @param slotId[in], indicates the card slot index number.
77      * @param portIndex[in], index of the port from the slot.
78      * @param profile[in], the Bound Profile Package data returned by SM-DP+ server.
79      * @param forceDisableProfile[in], if true, and if an active SIM must be deactivated to access the eUICC,
80      * perform this action automatically.
81      * @param callback[in], call back function.
82      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
83      */
84     int32_t GetDownloadableProfileMetadata(int32_t slotId, int32_t portIndex, const DownloadableProfile &profile,
85         bool forceDisableProfile, const sptr<IEsimServiceCallback> &callback);
86 
87     /**
88      * @brief Gets downloadable profile List which are available for download on this device.
89      *
90      * @param slotId[in], indicates the card slot index number.
91      * @param forceDisableProfile[in], if true, and if an active SIM must be deactivated to access the eUICC,
92      * perform this action automatically.
93      * @param callback[in], call back function.
94      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
95      */
96     int32_t GetDownloadableProfiles(
97         int32_t slotId, int32_t portIndex, bool forceDisableProfile, const sptr<IEsimServiceCallback> &callback);
98 
99     /**
100      * @brief Attempt to download the given downloadable Profile.
101      *
102      * @param slotId[in], indicates the card slot index number.
103      * @param configInfo[in], downloadprofile config info.
104      * @param profile[in], the Bound Profile Package data returned by SM-DP+ server.
105      * @param callback[in], call back function.
106      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
107      */
108     int32_t DownloadProfile(int32_t slotId, DownloadProfileConfigInfo configInfo, const DownloadableProfile &profile,
109         const sptr<IEsimServiceCallback> &callback);
110 
111     /**
112      * @brief Get a list of all euiccProfile informations.
113      *
114      * @param slotId[in], indicates the card slot index number.
115      * @param callback[in], call back function.
116      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
117      */
118     int32_t GetEuiccProfileInfoList(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
119 
120     /**
121      * @brief Get information about the eUICC chip/device.
122      *
123      * @param slotId[in], indicates the card slot index number.
124      * @param callback[in], call back function.
125      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
126      */
127     int32_t GetEuiccInfo(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
128 
129     /**
130      * @brief Delete the given profile.
131      *
132      * @param slotId[in], indicates the card slot index number.
133      * @param iccId[in], the iccId of the profile.
134      * @param callback[in], call back function.
135      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
136      */
137     int32_t DeleteProfile(int32_t slotId, const std::string &iccId, const sptr<IEsimServiceCallback> &callback);
138 
139     /**
140      * @brief Switch to (enable) the given profile.
141      *
142      * @param slotId[in], indicates the card slot index number.
143      * @param portIndex[in], index of the port from the slot.
144      * @param iccId[in], the iccId of the profile.
145      * @param forceDisableProfile[in], if true, and if an active SIM must be deactivated to access the eUICC,
146      * perform this action automatically.
147      * @param callback[in], call back function.
148      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
149      */
150     int32_t SwitchToProfile(int32_t slotId, int32_t portIndex,
151         const std::string &iccId, bool forceDisableProfile, const sptr<IEsimServiceCallback> &callback);
152 
153     /**
154      * @brief Set the nickname for the given profile.
155      *
156      * @param slotId[in], indicates the card slot index number.
157      * @param iccId[in], the iccId of the profile.
158      * @param nickname[in], the nickname of the profile.
159      * @param callback[in], call back function.
160      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
161      */
162     int32_t SetProfileNickname(int32_t slotId, const std::string &iccId, const std::string &nickname,
163         const sptr<IEsimServiceCallback> &callback);
164 
165     /**
166      * @brief Erase all specific profiles and reset the eUICC.
167      *
168      * @param slotId[in], indicates the card slot index number.
169      * @param resetOption[in], options for resetting eUICC memory.
170      * @param callback[in], call back function.
171      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
172      */
173     int32_t ResetMemory(int32_t slotId, int32_t resetOption, const sptr<IEsimServiceCallback> &callback);
174 
175     /**
176      * @brief Ensure that profiles will be retained on the next factory reset.
177      *
178      * @param slotId[in], indicates the card slot index number.
179      * @param restoreResult[out], the result code.
180      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
181      */
182     int32_t ReserveProfilesForFactoryRestore(int32_t slotId, int32_t &restoreResult);
183 
184     /**
185      * @brief Set or update the default SM-DP+ address stored in an eUICC.
186      *
187      * @param slotId[in], indicates the card slot index number.
188      * @param defaultSmdpAddress[in], the default SM-DP+ address to set.
189      * @param callback[in], call back function.
190      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
191      */
192     int32_t SetDefaultSmdpAddress(
193         int32_t slotId, const std::string &defaultSmdpAddress, const sptr<IEsimServiceCallback> &callback);
194 
195     /**
196      * @brief Gets the default SM-DP+ address stored in an eUICC.
197      *
198      * @param slotId[in], indicates the card slot index number.
199      * @param callback[in], call back function.
200      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
201      */
202     int32_t GetDefaultSmdpAddress(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
203 
204     /**
205      * @brief Cancel session.
206      *
207      * @param slotId[in], indicates the card slot index number.
208      * @param transactionId[in], the transaction ID returned by SM-DP+ server.
209      * @param cancelReason[in], the cancel reason.
210      * @param callback[in], call back function.
211      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
212      */
213     int32_t CancelSession(int32_t slotId, const std::string &transactionId,
214         int32_t cancelReason, const sptr<IEsimServiceCallback> &callback);
215 
216     /**
217      * @brief Check whether embedded subscriptions are currently supported.
218      *
219      * @param slotId[in], indicates the card slot index number.
220      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
221      */
222     int32_t IsSupported(int32_t slotId);
223 
224     /**
225      * @brief Starts a page through an ability, on which users can touch the button to download a profile.
226      *
227      * @param slotId[in], indicates the card slot index number.
228      * @param profile[in], the Bound Profile Package data returned by SM-DP+ server.
229      * @return Return int32_t TELEPHONY_SUCCESS if the profile is added successfully; others on failure.
230      */
231     int32_t AddProfile(int32_t slotId, DownloadableProfile profile);
232 
233     /**
234      * @brief Get supported pkids string.
235      *
236      * @param slotId[in], indicates the card slot index number.
237      * @param callback[in], call back function.
238      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
239      */
240     int32_t GetSupportedPkids(int32_t slotId, const sptr<IEsimServiceCallback> &callback);
241 
242     /**
243      * @brief Get contract info string.
244      *
245      * @param slotId[in], indicates the card slot index number.
246      * @param contractRequestData[in], contractRequestData contract request data required to sign and encrypt
247      * @param callback[in], call back function.
248      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
249      */
250     int32_t GetContractInfo(int32_t slotId, ContractRequestData &contractRequestData,
251         const sptr<IEsimServiceCallback> &callback);
252 
253 private:
254     void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
255     class EsimServiceDeathRecipient : public IRemoteObject::DeathRecipient {
256     public:
EsimServiceDeathRecipient(EsimServiceClient & client)257         explicit EsimServiceDeathRecipient(EsimServiceClient &client) : client_(client) {}
258         ~EsimServiceDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)259         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
260         {
261             client_.OnRemoteDied(remote);
262         }
263 
264     private:
265         EsimServiceClient &client_;
266     };
267 
268 private:
269     std::mutex mutexProxy_;
270     sptr<IEsimService> proxy_ { nullptr };
271     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
272     sptr<IEsimServiceCallback> remoteCallback_ = nullptr;
273     sptr<IEsimService> GetProxy();
274     void OnRemoteDied(const wptr<IRemoteObject> &remote);
275 };
276 } // namespace Telephony
277 } // namespace OHOS
278 #endif // ESIM_SERVICE_CLIENT_H