diff --git a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp index 3a7976008747973b56e72087b4377fc923fc1190..25c3510ae4e17fc662c09b6e7af13f15297d0aae 100644 --- a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp +++ b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp @@ -588,11 +588,27 @@ static ani_string GetAbilityLabelNative(ani_env* env, return nullptr; } std::string abilityLabel; - ErrCode ret = iBundleMgr->GetAbilityLabel(bundleName, moduleName, abilityName, abilityLabel); + ErrCode ret = CommonFunc::ConvertErrCode( + iBundleMgr->GetAbilityLabel(bundleName, moduleName, abilityName, abilityLabel)); + if (ret == ERROR_PARAM_CHECK_ERROR) { + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } else if (moduleName.empty()) { + APP_LOGW("moduleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + return nullptr; + } else { + APP_LOGW("abilityName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_ABILITYNAME_EMPTY_ERROR); + return nullptr; + } + } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("GetAbilityLabel failed ret: %{public}d", ret); - BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + BusinessErrorAni::ThrowCommonError(env, ret, isSync ? GET_ABILITY_LABEL_SYNC : GET_ABILITY_LABEL, BUNDLE_PERMISSIONS); return nullptr; } @@ -711,10 +727,16 @@ static ani_string GetSpecifiedDistributionType(ani_env* env, ani_string aniBundl return nullptr; } std::string specifiedDistributionType; - ErrCode ret = iBundleMgr->GetSpecifiedDistributionType(bundleName, specifiedDistributionType); + ErrCode ret = CommonFunc::ConvertErrCode( + iBundleMgr->GetSpecifiedDistributionType(bundleName, specifiedDistributionType)); + if (ret == ERROR_PARAM_CHECK_ERROR && bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } if (ret != ERR_OK) { APP_LOGE("GetSpecifiedDistributionType failed ret: %{public}d", ret); - BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + BusinessErrorAni::ThrowCommonError(env, ret, RESOURCE_NAME_OF_GET_SPECIFIED_DISTRIBUTION_TYPE, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); return nullptr; } @@ -927,6 +949,10 @@ static void SetApplicationEnabledNative(ani_env* env, return; } ErrCode ret = BundleManagerHelper::InnerSetApplicationEnabled(bundleName, isEnable, appIndex); + if (ret == ERROR_PARAM_CHECK_ERROR && bundleName.empty()) { + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return; + } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("SetApplicationEnabled failed ret: %{public}d", ret); diff --git a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp index 3ae284ae5eb26f1ec9999a77d827b0f012f1a8dd..05f89342b2b244ac0f4fe5d4354ecabd69e5d3b4 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp @@ -126,6 +126,11 @@ napi_value SetApplicationEnabledSync(napi_env env, napi_callback_info info) BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } if (!CommonFunc::ParseBool(env, args[ARGS_POS_ONE], isEnable)) { APP_LOGE("parse isEnable failed"); BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, IS_ENABLE, TYPE_BOOLEAN); @@ -519,14 +524,29 @@ ErrCode ParamsProcessGetAbilityLabelSync(napi_env env, napi_callback_info info, BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } if (!CommonFunc::ParseString(env, args[ARGS_POS_ONE], moduleName)) { BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, MODULE_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (moduleName.empty()) { + APP_LOGW("moduleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } if (!CommonFunc::ParseString(env, args[ARGS_POS_TWO], abilityName)) { BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (abilityName.empty()) { + APP_LOGW("abilityName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_ABILITYNAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } } else { BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR); return ERROR_PARAM_CHECK_ERROR;