[settings]AI检视意见CodeCity清理

Signed-off-by: 杨云鹏 <yangyunpeng7@huawei.com>
This commit is contained in:
侯志雄 2024-09-20 14:46:37 +08:00
parent 8b45884a9b
commit a159378c9c
3 changed files with 44 additions and 9 deletions

View File

@ -251,7 +251,10 @@ napi_value napi_get_uri(napi_env env, napi_callback_info info)
.uri = "", .uri = "",
.status = false, .status = false,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
std::string keyStr = unwrap_string_from_js(env, args[PARAM0]); std::string keyStr = unwrap_string_from_js(env, args[PARAM0]);
// get userId string // get userId string
std::vector<int> tmpId; std::vector<int> tmpId;
@ -759,7 +762,10 @@ napi_value napi_get_value(napi_env env, napi_callback_info info)
.uri = "", .uri = "",
.status = false, .status = false,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
if (wrapper != nullptr) { if (wrapper != nullptr) {
asyncCallbackInfo->dataAbilityHelper = wrapper->GetDataAbilityHelper(); asyncCallbackInfo->dataAbilityHelper = wrapper->GetDataAbilityHelper();
} }
@ -915,7 +921,10 @@ napi_value napi_get_value_ext(napi_env env, napi_callback_info info, const bool
.uri = "", .uri = "",
.status = false, .status = false,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
asyncCallbackInfo->dataShareHelper = getDataShareHelper(env, args[PARAM0], stageMode); asyncCallbackInfo->dataShareHelper = getDataShareHelper(env, args[PARAM0], stageMode);
asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]); asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]);
@ -1311,7 +1320,10 @@ napi_value napi_set_value(napi_env env, napi_callback_info info)
.uri = "", .uri = "",
.status = false, .status = false,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
if (wrapper != nullptr) { if (wrapper != nullptr) {
asyncCallbackInfo->dataAbilityHelper = wrapper->GetDataAbilityHelper(); asyncCallbackInfo->dataAbilityHelper = wrapper->GetDataAbilityHelper();
} }
@ -1351,7 +1363,10 @@ napi_value napi_set_value_ext(napi_env env, napi_callback_info info, const bool
.uri = "", .uri = "",
.status = false, .status = false,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
asyncCallbackInfo->dataShareHelper = getDataShareHelper(env, args[PARAM0], stageMode); asyncCallbackInfo->dataShareHelper = getDataShareHelper(env, args[PARAM0], stageMode);
asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]); asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]);
asyncCallbackInfo->uri = unwrap_string_from_js(env, args[PARAM2]); //temp asyncCallbackInfo->uri = unwrap_string_from_js(env, args[PARAM2]); //temp
@ -1492,7 +1507,10 @@ napi_value napi_enable_airplane_mode(napi_env env, napi_callback_info info)
.uri = "", .uri = "",
.status = 0, .status = 0,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
if (argc == paramOfCallback) { if (argc == paramOfCallback) {
SETTING_LOG_INFO("%{public}s, asyncCallback.", __func__); SETTING_LOG_INFO("%{public}s, asyncCallback.", __func__);
@ -1622,7 +1640,10 @@ napi_value napi_can_show_floating(napi_env env, napi_callback_info info)
.uri = "", .uri = "",
.status = 0, .status = 0,
}; };
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
napi_value resource = nullptr; napi_value resource = nullptr;
NAPI_CALL(env, napi_create_string_utf8(env, "enableAirplaneMode", NAPI_AUTO_LENGTH, &resource)); NAPI_CALL(env, napi_create_string_utf8(env, "enableAirplaneMode", NAPI_AUTO_LENGTH, &resource));
@ -1846,6 +1867,10 @@ napi_value napi_set_value_sync_ext(bool stageMode, size_t argc, napi_env env, na
{ {
SETTING_LOG_INFO("argv[0] is a context, Stage Model: %{public}d", stageMode); SETTING_LOG_INFO("argv[0] is a context, Stage Model: %{public}d", stageMode);
AsyncCallbackInfo *asyncCallbackInfo = new AsyncCallbackInfo(); AsyncCallbackInfo *asyncCallbackInfo = new AsyncCallbackInfo();
if (asyncCallbackInfo == nullptr) {
SETTING_LOG_ERROR("asyncCallbackInfo is null");
return wrap_void_to_js(env);
}
asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]); asyncCallbackInfo->key = unwrap_string_from_js(env, args[PARAM1]);
napi_valuetype valueType; napi_valuetype valueType;

View File

@ -34,9 +34,13 @@ using namespace OHOS::AccountSA;
namespace OHOS { namespace OHOS {
namespace Settings { namespace Settings {
std::map<std::string, sptr<SettingsObserver>> g_observerMap; std::map<std::string, sptr<SettingsObserver>> g_observerMap;
std::mutex g_observerMapMutex;
SettingsObserver::~SettingsObserver() SettingsObserver::~SettingsObserver()
{ {
if (this->cbInfo == nullptr) {
return;
}
delete this->cbInfo; delete this->cbInfo;
this->cbInfo = nullptr; this->cbInfo = nullptr;
} }
@ -163,12 +167,17 @@ namespace Settings {
return wrap_bool_to_js(env, false); return wrap_bool_to_js(env, false);
} }
AsyncCallbackInfo *callbackInfo = new AsyncCallbackInfo(); AsyncCallbackInfo *callbackInfo = new AsyncCallbackInfo();
if (callbackInfo == nullptr) {
SETTING_LOG_ERROR("%{public}s, failed to get callbackInfo.", __func__);
return wrap_bool_to_js(env, false);
}
callbackInfo->env = env; callbackInfo->env = env;
callbackInfo->key = unwrap_string_from_js(env, args[PARAM1]); callbackInfo->key = unwrap_string_from_js(env, args[PARAM1]);
callbackInfo->tableName = unwrap_string_from_js(env, args[PARAM2]); callbackInfo->tableName = unwrap_string_from_js(env, args[PARAM2]);
napi_create_reference(env, args[PARAM3], 1, &(callbackInfo->callbackRef)); napi_create_reference(env, args[PARAM3], 1, &(callbackInfo->callbackRef));
std::lock_guard<std::mutex> lockGuard(g_observerMapMutex);
if (g_observerMap.find(callbackInfo->key) != g_observerMap.end() && if (g_observerMap.find(callbackInfo->key) != g_observerMap.end() &&
g_observerMap[callbackInfo->key] != nullptr) { g_observerMap[callbackInfo->key] != nullptr) {
SETTING_LOG_INFO("%{public}s, already registered.", __func__); SETTING_LOG_INFO("%{public}s, already registered.", __func__);
@ -225,6 +234,7 @@ namespace Settings {
std::string key = unwrap_string_from_js(env, args[PARAM1]); std::string key = unwrap_string_from_js(env, args[PARAM1]);
std::string tableName = unwrap_string_from_js(env, args[PARAM2]); std::string tableName = unwrap_string_from_js(env, args[PARAM2]);
std::lock_guard<std::mutex> lockGuard(g_observerMapMutex);
if (g_observerMap.find(key) == g_observerMap.end()) { if (g_observerMap.find(key) == g_observerMap.end()) {
SETTING_LOG_ERROR("%{public}s, null.", __func__); SETTING_LOG_ERROR("%{public}s, null.", __func__);
return wrap_bool_to_js(env, false); return wrap_bool_to_js(env, false);

View File

@ -30,7 +30,7 @@ EXTERN_C_START
*/ */
static napi_value Init(napi_env env, napi_value exports) static napi_value Init(napi_env env, napi_value exports)
{ {
SETTING_LOG_INFO("napi_moudule Init start..."); SETTING_LOG_INFO("napi_module Init start...");
napi_property_descriptor desc[] = { napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("getURI", napi_get_uri), DECLARE_NAPI_FUNCTION("getURI", napi_get_uri),
@ -49,7 +49,7 @@ static napi_value Init(napi_env env, napi_value exports)
// init settings class // init settings class
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
InitNapiClass(env, exports); InitNapiClass(env, exports);
SETTING_LOG_INFO("napi_moudule Init end..."); SETTING_LOG_INFO("napi_module Init end...");
return exports; return exports;
} }
EXTERN_C_END EXTERN_C_END