mirror of
https://gitee.com/openharmony/telephony_core_service
synced 2024-11-23 08:00:07 +00:00
commit
3d54935f17
@ -122,6 +122,11 @@ struct AsyncResetMemory {
|
||||
AsyncContext<int32_t> asyncContext;
|
||||
int32_t option = ERROR_DEFAULT;
|
||||
};
|
||||
|
||||
struct AsyncAddProfileInfo {
|
||||
AsyncContext<bool> asyncContext;
|
||||
AsyncDownloadableProfile profile;
|
||||
};
|
||||
} // namespace Telephony
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_NAPI_ESIM_H
|
||||
|
@ -173,6 +173,19 @@ void NapiAsyncPermissionCompleteCallback(napi_env env, napi_status status, const
|
||||
NapiAsyncBaseCompleteCallback(env, asyncContext, error, funcIgnoreReturnVal);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void NapiAsyncCommomCompleteCallback(
|
||||
napi_env env, napi_status status, const AsyncContext<T> &asyncContext, bool funcIgnoreReturnVal)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
napi_throw_type_error(env, nullptr, "excute failed");
|
||||
return;
|
||||
}
|
||||
|
||||
JsError error = NapiUtil::ConverErrorMessageForJs(asyncContext.context.errorCode);
|
||||
NapiAsyncBaseCompleteCallback(env, asyncContext, error, funcIgnoreReturnVal);
|
||||
}
|
||||
|
||||
napi_value EuiccInfoConversion(napi_env env, const EuiccInfo &resultInfo)
|
||||
{
|
||||
napi_value val = nullptr;
|
||||
@ -450,6 +463,59 @@ napi_value IsSupported(napi_env env, napi_callback_info info)
|
||||
return value;
|
||||
}
|
||||
|
||||
void NativeAddProfile(napi_env env, void *data)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
AsyncAddProfileInfo *addProfileContext = static_cast<AsyncAddProfileInfo *>(data);
|
||||
int32_t slotId = GetDefaultEsimSlotId<int32_t>();
|
||||
DownloadableProfile profile = GetProfileInfo(addProfileContext->profile);
|
||||
int32_t errcode = DelayedRefSingleton<EsimServiceClient>::GetInstance().AddProfile(slotId, profile);
|
||||
if (errcode == ERROR_NONE) {
|
||||
addProfileContext->asyncContext.context.resolved = true;
|
||||
addProfileContext->asyncContext.callbackVal = true;
|
||||
} else {
|
||||
addProfileContext->asyncContext.context.resolved = false;
|
||||
addProfileContext->asyncContext.callbackVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AddProfileCallback(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
NAPI_CALL_RETURN_VOID(env, (data == nullptr ? napi_invalid_arg : napi_ok));
|
||||
std::unique_ptr<AsyncAddProfileInfo> context(static_cast<AsyncAddProfileInfo *>(data));
|
||||
if (context == nullptr) {
|
||||
TELEPHONY_LOGE("AddProfileCallback context is nullptr");
|
||||
return;
|
||||
}
|
||||
NapiAsyncCommomCompleteCallback(env, status, context->asyncContext, false);
|
||||
}
|
||||
|
||||
napi_value AddProfile(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto addProfile = new (std::nothrow) AsyncAddProfileInfo();
|
||||
if (addProfile == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
BaseContext &context = addProfile->asyncContext.context;
|
||||
napi_value object = NapiUtil::CreateUndefined(env);
|
||||
auto initPara = std::make_tuple(&object, &context.callbackRef);
|
||||
AsyncPara para{
|
||||
.funcName = "AddProfile",
|
||||
.env = env,
|
||||
.info = info,
|
||||
.execute = NativeAddProfile,
|
||||
.complete = AddProfileCallback,
|
||||
};
|
||||
napi_value result = NapiCreateAsyncWork2<AsyncAddProfileInfo>(para, addProfile, initPara);
|
||||
if (result) {
|
||||
ProfileInfoAnalyze(env, object, addProfile->profile);
|
||||
NAPI_CALL(env, napi_queue_async_work_with_qos(env, context.work, napi_qos_default));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void NativeGetEuiccInfo(napi_env env, void *data)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
@ -1621,6 +1687,7 @@ napi_status InitEuiccServiceInterface(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("isSupported", IsSupported),
|
||||
DECLARE_NAPI_FUNCTION("addProfile", AddProfile),
|
||||
DECLARE_NAPI_FUNCTION("getEid", GetEid),
|
||||
DECLARE_NAPI_FUNCTION("getOsuStatus", GetOsuStatus),
|
||||
DECLARE_NAPI_FUNCTION("startOsu", StartOsu),
|
||||
|
@ -323,5 +323,15 @@ bool EsimServiceClient::IsSupported(int32_t slotId)
|
||||
}
|
||||
return proxy->IsSupported(slotId);
|
||||
}
|
||||
|
||||
int32_t EsimServiceClient::AddProfile(int32_t slotId, DownloadableProfile profile)
|
||||
{
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
TELEPHONY_LOGE("proxy is null!");
|
||||
return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
|
||||
}
|
||||
return proxy->AddProfile(slotId, profile);
|
||||
}
|
||||
} // namespace Telephony
|
||||
} // namespace OHOS
|
||||
|
@ -65,4 +65,5 @@ interface OHOS.Telephony.IEsimService {
|
||||
void CancelSession([in] int slotId, [in] String transactionId, [in] int cancelReason,
|
||||
[out] ResponseEsimResult responseResult);
|
||||
void IsSupported([in] int slotId);
|
||||
void AddProfile([in] int slotId, [in] DownloadableProfile profile);
|
||||
}
|
@ -221,6 +221,15 @@ public:
|
||||
*/
|
||||
bool IsSupported(int32_t slotId);
|
||||
|
||||
/**
|
||||
* @brief Starts a page through an ability, on which users can touch the button to download a profile.
|
||||
*
|
||||
* @param slotId[in], indicates the card slot index number.
|
||||
* @param profile[in], the Bound Profile Package data returned by SM-DP+ server.
|
||||
* @return Return int32_t TELEPHONY_SUCCESS if the profile is added successfully; others on failure.
|
||||
*/
|
||||
int32_t AddProfile(int32_t slotId, DownloadableProfile profile);
|
||||
|
||||
private:
|
||||
void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
|
||||
class EsimServiceDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
|
Loading…
Reference in New Issue
Block a user