From 2f509a159284ef846ad4b38b5a27ddab9839877b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E9=9B=A8=E6=B8=85=E9=A3=8E?= Date: Mon, 22 Apr 2024 09:34:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=92=8C=E6=95=B0=E6=8D=AE=E6=BC=AB=E6=B8=B8?= =?UTF-8?q?=E7=9A=84=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 暮雨清风 --- frameworks/js/napi/src/napi_cellular_data.cpp | 45 +++++++++++++++++++ interfaces/innerkits/cellular_data_client.h | 17 +++++++ 2 files changed, 62 insertions(+) diff --git a/frameworks/js/napi/src/napi_cellular_data.cpp b/frameworks/js/napi/src/napi_cellular_data.cpp index f809ac8..0fe8737 100644 --- a/frameworks/js/napi/src/napi_cellular_data.cpp +++ b/frameworks/js/napi/src/napi_cellular_data.cpp @@ -242,6 +242,30 @@ static napi_value IsCellularDataEnabled(napi_env env, napi_callback_info info) NativeIsCellularDataEnabled, IsCellularDataEnabledCallback); } +static napi_value IsCellularDataEnabledSync(napi_env env, napi_callback_info info) +{ + size_t parameterCount = 0; + napi_value parameters[] = { nullptr }; + napi_value thisVar = nullptr; + void *data = nullptr; + bool isEnabled = false; + + NAPI_CALL(env, napi_get_cb_info(env, info, ¶meterCount, parameters, &thisVar, &data)); + if (!MatchCellularDataParameters(env, parameters, parameterCount)) { + TELEPHONY_LOGE("IsCellularDataEnabled MatchCellularDataParameters failed."); + NapiUtil::ThrowParameterError(env); + return nullptr; + } + + if (parameterCount == 0) { + CellularDataClient::GetInstance().IsCellularDataEnabled(isEnabled); + } + + napi_value value = nullptr; + NAPI_CALL(env, napi_create_int32(env, isEnabled, &value)); + return value; +} + static void NativeEnableCellularData(napi_env env, void *data) { auto asyncContext = static_cast(data); @@ -587,6 +611,25 @@ static napi_value IsCellularDataRoamingEnabled(napi_env env, napi_callback_info NativeIsCellularDataRoamingEnabled, IsCellularDataRoamingEnabledCallback); } +static napi_value IsCellularDataRoamingEnabledSync(napi_env env, napi_callback_info info) +{ + const size_t paramLimitTwo = 2; + size_t parameterCount = paramLimitTwo; + napi_value parameters[paramLimitTwo] = {0}; + napi_value thisVar = nullptr; + void *data = nullptr; + bool dataRoamingEnabled; + int32_t slotId; + + napi_get_cb_info(env, info, ¶meterCount, parameters, &thisVar, &data); + napi_get_value_int32(env, parameters[0], slotId); + CellularDataClient::GetInstance().IsCellularDataRoamingEnabled(slotId, dataRoamingEnabled); + + napi_value value = nullptr; + NAPI_CALL(env, napi_create_int32(env, dataRoamingEnabled, &value)); + return value; +} + static bool MatchGetDefaultCellularDataSlotIdParameters( napi_env env, const napi_value parameters[], const size_t parameterCount) { @@ -949,11 +992,13 @@ napi_value RegistCellularData(napi_env env, napi_value exports) napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("getCellularDataState", GetCellularDataState), DECLARE_NAPI_FUNCTION("isCellularDataEnabled", IsCellularDataEnabled), + DECLARE_NAPI_FUNCTION("isCellularDataEnabledSync", IsCellularDataEnabledSync), DECLARE_NAPI_FUNCTION("enableCellularData", EnableCellularData), DECLARE_NAPI_FUNCTION("disableCellularData", DisableCellularData), DECLARE_NAPI_FUNCTION("enableCellularDataRoaming", EnableCellularDataRoaming), DECLARE_NAPI_FUNCTION("disableCellularDataRoaming", DisableCellularDataRoaming), DECLARE_NAPI_FUNCTION("isCellularDataRoamingEnabled", IsCellularDataRoamingEnabled), + DECLARE_NAPI_FUNCTION("isCellularDataRoamingEnabledSync", IsCellularDataRoamingEnabledSync), DECLARE_NAPI_FUNCTION("getDefaultCellularDataSlotId", GetDefaultCellularDataSlotId), DECLARE_NAPI_FUNCTION("getDefaultCellularDataSimId", GetDefaultCellularDataSimId), DECLARE_NAPI_FUNCTION("getDefaultCellularDataSlotIdSync", GetDefaultCellularDataSlotIdSync), diff --git a/interfaces/innerkits/cellular_data_client.h b/interfaces/innerkits/cellular_data_client.h index 74be751..362870f 100644 --- a/interfaces/innerkits/cellular_data_client.h +++ b/interfaces/innerkits/cellular_data_client.h @@ -63,6 +63,14 @@ public: */ int32_t IsCellularDataEnabled(bool &dataEnabled); + /** + * @brief Whether the cellular data user switch is enabled + * + * @param dataEnabled Indicates the result of data enabled status. + * @return Returns error code. + */ + int32_t IsCellularDataEnabledSync(bool &dataEnabled); + /** * @brief Cellular data connection status * @@ -99,6 +107,15 @@ public: */ int32_t IsCellularDataRoamingEnabled(int32_t slotId, bool &dataRoamingEnabled); + /** + * @brief Whether roaming is allowed + * + * @param slotId Indicates card slot identification + * @param dataRoamingEnabled Indicates the result of data roaming enabled status. + * @return Returns error code. + */ + int32_t IsCellularDataRoamingEnabledSync(int32_t slotId, bool &dataRoamingEnabled); + /** * @brief Whether roaming switches are allowed * -- Gitee From 325c6e7b68cf9b3618734577e632d0eede5ae4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E9=9B=A8=E6=B8=85=E9=A3=8E?= Date: Mon, 22 Apr 2024 11:36:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=92=8C=E6=95=B0=E6=8D=AE=E6=BC=AB=E6=B8=B8?= =?UTF-8?q?=E7=9A=84=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 暮雨清风 --- frameworks/js/napi/src/napi_cellular_data.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frameworks/js/napi/src/napi_cellular_data.cpp b/frameworks/js/napi/src/napi_cellular_data.cpp index 0fe8737..b13ed2b 100644 --- a/frameworks/js/napi/src/napi_cellular_data.cpp +++ b/frameworks/js/napi/src/napi_cellular_data.cpp @@ -613,18 +613,17 @@ static napi_value IsCellularDataRoamingEnabled(napi_env env, napi_callback_info static napi_value IsCellularDataRoamingEnabledSync(napi_env env, napi_callback_info info) { - const size_t paramLimitTwo = 2; - size_t parameterCount = paramLimitTwo; - napi_value parameters[paramLimitTwo] = {0}; + size_t parameterCount = 0; + napi_value parameters[] = { nullptr }; napi_value thisVar = nullptr; void *data = nullptr; bool dataRoamingEnabled; - int32_t slotId; + int32_t slotId = -1; napi_get_cb_info(env, info, ¶meterCount, parameters, &thisVar, &data); - napi_get_value_int32(env, parameters[0], slotId); - CellularDataClient::GetInstance().IsCellularDataRoamingEnabled(slotId, dataRoamingEnabled); - + if (parameterCount == 0) { + CellularDataClient::GetInstance().IsCellularDataRoamingEnabled(slotId, dataRoamingEnabled); + } napi_value value = nullptr; NAPI_CALL(env, napi_create_int32(env, dataRoamingEnabled, &value)); return value; -- Gitee