• 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 OHOS_NAPI_ESIM_H
17 #define OHOS_NAPI_ESIM_H
18 
19 #include <array>
20 #include <string>
21 #include <vector>
22 #include "base_context.h"
23 #include "download_profile_config_info_parcel.h"
24 #include "download_profile_result_parcel.h"
25 #include "downloadable_profile_parcel.h"
26 #include "esim_state_type.h"
27 #include "euicc_info_parcel.h"
28 #include "get_downloadable_profiles_result_parcel.h"
29 #include "profile_info_list_parcel.h"
30 #include "profile_metadata_result_parcel.h"
31 #include "response_esim_result.h"
32 #include "telephony_napi_common_error.h"
33 #include "telephony_types.h"
34 
35 namespace OHOS {
36 namespace Telephony {
37 constexpr int WAIT_TIME_SECOND = 30;
38 constexpr int WAIT_LONG_TERM_TASK_SECOND = 180;
39 const int32_t DEFAULT_ERROR = -1;
40 
41 template<typename T>
42 struct AsyncContext {
43     BaseContext context;
44     int32_t slotId = ERROR_DEFAULT;
45     T callbackVal;
46     std::mutex callbackMutex;
47     std::condition_variable cv;
48     bool isCallbackEnd = false;
49     bool isSendRequest = false;
50 };
51 
52 struct AsyncContextInfo {
53     AsyncContext<int32_t> asyncContext;
54     std::string inputStr = "";
55 };
56 
57 struct AsyncCommonInfo {
58     AsyncContext<int32_t> asyncContext;
59 };
60 
61 struct AsyncEuiccInfo {
62     AsyncContext<napi_value> asyncContext;
63     EuiccInfo result;
64 };
65 
66 struct AsyncEuiccProfileInfoList {
67     AsyncContext<napi_value> asyncContext;
68     GetEuiccProfileInfoListResult result;
69 };
70 
71 struct AsyncSwitchProfileInfo {
72     AsyncContext<int32_t> asyncContext;
73     int32_t portIndex = ERROR_DEFAULT;
74     std::string iccid = "";
75     bool forceDisableProfile = false;
76 };
77 
78 struct AsyncAccessRule {
79     std::string certificateHashHexStr = "";
80     std::string packageName = "";
81     int32_t accessType = ERROR_DEFAULT;
82 };
83 
84 struct AsyncDownloadableProfile {
85     std::string activationCode = "";
86     std::string confirmationCode = "";
87     std::string carrierName = "";
88     std::vector<AsyncAccessRule> accessRules{};
89 };
90 
91 struct AsyncDownloadConfiguration {
92     bool switchAfterDownload = false;
93     bool forceDisableProfile = false;
94     bool isPprAllowed = false;
95 };
96 
97 struct AsyncDownloadProfileInfo {
98     AsyncContext<napi_value> asyncContext;
99     int32_t portIndex = ERROR_DEFAULT;
100     AsyncDownloadableProfile profile;
101     AsyncDownloadConfiguration configuration;
102     DownloadProfileResult result;
103 };
104 
105 struct AsyncDefaultProfileList {
106     AsyncContext<napi_value> asyncContext;
107     int32_t portIndex = ERROR_DEFAULT;
108     bool forceDisableProfile = false;
109     GetDownloadableProfilesResult result;
110 };
111 
112 struct AsyncProfileNickname {
113     AsyncContext<int32_t> asyncContext;
114     std::string iccid = "";
115     std::string nickname = "";
116 };
117 
118 struct AsyncCancelSession {
119     AsyncContext<int32_t> asyncContext;
120     std::string transactionId = "";
121     int32_t cancelReason = static_cast<int32_t>(CancelReason::CANCEL_REASON_POSTPONED);
122 };
123 
124 struct AsyncProfileMetadataInfo {
125     AsyncContext<napi_value> asyncContext;
126     int32_t portIndex = ERROR_DEFAULT;
127     AsyncDownloadableProfile profile;
128     bool forceDisableProfile = false;
129     GetDownloadableProfileMetadataResult result;
130 };
131 
132 struct AsyncResetMemory {
133     AsyncContext<int32_t> asyncContext;
134     int32_t option = ERROR_DEFAULT;
135 };
136 
137 struct AsyncAddProfileInfo {
138     AsyncContext<bool> asyncContext;
139     AsyncDownloadableProfile profile;
140 };
141 } // namespace Telephony
142 } // namespace OHOS
143 #endif // OHOS_NAPI_ESIM_H
144