diff --git a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp index d0b21044f0992558f20b2f46269e23061b922b98..8f019943849c0fc34c71e92feeafd31a6281c61b 100644 --- a/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp +++ b/interfaces/kits/ani/bundle_installer/ani_bundle_installer.cpp @@ -98,6 +98,9 @@ static bool CheckInstallParam(ani_env* env, InstallParam& installParam) static void ExecuteInstall(const std::vector& hapFiles, InstallParam& installParam, InstallResult& installResult) { + if (installParam.installFlag == InstallFlag::NORMAL) { + installParam.installFlag = InstallFlag::REPLACE_EXISTING; + } if (hapFiles.empty() && installParam.sharedBundleDirPaths.empty()) { installResult.resultCode = static_cast(IStatusReceiver::ERR_INSTALL_FILE_PATH_INVALID); return; @@ -113,6 +116,7 @@ static void ExecuteInstall(const std::vector& hapFiles, InstallPara APP_LOGD("InnerInstall resultCode %{public}d", installResult.resultCode); installResult.resultMsg = callback->GetResultMsg(); APP_LOGD("InnerInstall resultMsg %{public}s", installResult.resultMsg.c_str()); + installResult.innerCode = callback->GetInnerCode(); return; } APP_LOGE("install failed due to %{public}d", res); @@ -120,6 +124,8 @@ static void ExecuteInstall(const std::vector& hapFiles, InstallPara InstallerHelper::CreateProxyErrCode(proxyErrCodeMap); if (proxyErrCodeMap.find(res) != proxyErrCodeMap.end()) { installResult.resultCode = proxyErrCodeMap.at(res); + // append inner error code to TS interface result message + installResult.innerCode = res; } else { installResult.resultCode = IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR; } @@ -131,7 +137,7 @@ static void ProcessResult(ani_env* env, InstallResult& result, const InstallOpti if (result.resultCode != SUCCESS) { switch (option) { case InstallOption::INSTALL: - BusinessErrorAni::ThrowCommonError(env, result.resultCode, + BusinessErrorAni::ThrowInstallError(env, result.resultCode, result.innerCode, RESOURCE_NAME_OF_INSTALL, INSTALL_PERMISSION); break; case InstallOption::RECOVER: diff --git a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets index 0291e78efb94ee21cffd1f097bec1ec3d8f2c1fc..5d86fe2a5278577ab8de16dc073464854dd2cda4 100644 --- a/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets +++ b/interfaces/kits/ani/bundle_manager/ets/@ohos.bundle.bundleManager.ets @@ -40,6 +40,8 @@ namespace bundleManager { const PARAM_BUNDLENAME_EMPTY_ERROR: string = "BusinessError 401: Parameter error. parameter bundleName is empty"; const ERROR_ABILITY_NOT_EXIST: int = 17700003; const GETABILITYINFO_ERROR_MSG: string = "BusinessError 17700003: The specified ability is not found."; + const PARAM_BUNDLENAME_TYPE_ERROR: string = "BusinessError 401: Parameter error. The type of bundleName must be string."; + const PARAM_TYPE_CHECK_ERROR: string = "param type check error"; function createBusinessError(code: int, message: string) { let err = new BusinessError(); @@ -344,6 +346,9 @@ namespace bundleManager { } function getLaunchWantForBundleSync(bundleName: string, userId?: int): Want { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_TYPE_CHECK_ERROR); + } let userIdInfo: int = userId ?? EMPTY_VALUE; return bundleManager.getLaunchWantForBundleNative(bundleName, userIdInfo, true); } @@ -786,6 +791,9 @@ namespace bundleManager { } function getLaunchWantForBundle(bundleName: string, userId?: int): Promise { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); + } let p = new Promise(( resolve: (want: Want) => void, reject: (error: BusinessError) => void) => { let userIdInfo: int = userId ?? EMPTY_VALUE; @@ -805,6 +813,9 @@ namespace bundleManager { } function getLaunchWantForBundle(bundleName: string, userId: int, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); + } let execFun = (): Want => { return bundleManager.getLaunchWantForBundleNative(bundleName, userId, false); }; @@ -818,6 +829,9 @@ namespace bundleManager { } function getLaunchWantForBundle(bundleName: string, callback: AsyncCallback): void { + if (bundleName === "") { + throw createBusinessError(ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_TYPE_ERROR); + } let execFun = (): Want => { return bundleManager.getLaunchWantForBundleNative(bundleName, EMPTY_VALUE, false); }; diff --git a/interfaces/kits/ani/common/business_error_ani.cpp b/interfaces/kits/ani/common/business_error_ani.cpp index f941c21763132d94b361956026af96334883b325..e2180963097213c46d05e95ae785a12462fd7139 100644 --- a/interfaces/kits/ani/common/business_error_ani.cpp +++ b/interfaces/kits/ani/common/business_error_ani.cpp @@ -120,6 +120,17 @@ void BusinessErrorAni::ThrowCommonError(ani_env *env, int32_t err, ThrowError(env, error); } +void BusinessErrorAni::ThrowInstallError(ani_env *env, int32_t err, int32_t innerCode, + const std::string ¶meter, const std::string &type) +{ + if (env == nullptr) { + APP_LOGE("err is nullptr"); + return; + } + ani_object error = CreateInstallError(env, err, innerCode, parameter, type); + ThrowError(env, error); +} + void BusinessErrorAni::ThrowTooFewParametersError(ani_env *env, int32_t err) { if (env == nullptr) { @@ -157,6 +168,35 @@ ani_object BusinessErrorAni::CreateCommonError( return CreateError(env, err, errMessage); } +ani_object BusinessErrorAni::CreateInstallError(ani_env *env, int32_t err, int32_t innerCode, + const std::string &functionName, const std::string &permissionName) +{ + if (env == nullptr) { + APP_LOGE("err is nullptr"); + return nullptr; + } + std::string errMessage = BusinessErrorNS::ERR_MSG_BUSINESS_ERROR; + auto iter = errMessage.find(ERROR_MESSAGE_PLACEHOLDER); + if (iter != std::string::npos) { + errMessage = errMessage.replace(iter, 1, std::to_string(err)); + } + std::unordered_map errMap; + BusinessErrorMap::GetErrMap(errMap); + if (errMap.find(err) != errMap.end()) { + errMessage += errMap[err]; + } + errMessage += "[" + std::to_string(innerCode) + "]"; + iter = errMessage.find(ERROR_MESSAGE_PLACEHOLDER); + if (iter != std::string::npos) { + errMessage = errMessage.replace(iter, 1, functionName); + iter = errMessage.find(ERROR_MESSAGE_PLACEHOLDER); + if (iter != std::string::npos) { + errMessage = errMessage.replace(iter, 1, permissionName); + } + } + return CreateError(env, err, errMessage); +} + void BusinessErrorAni::ThrowEnumError(ani_env *env, const std::string ¶meter, const std::string &type) { diff --git a/interfaces/kits/ani/common/business_error_ani.h b/interfaces/kits/ani/common/business_error_ani.h index 5699647796c8ae9e23248f3646a56e770e4b5b70..54d5fd26682bec301f35e186136fdfd798ef0ebc 100644 --- a/interfaces/kits/ani/common/business_error_ani.h +++ b/interfaces/kits/ani/common/business_error_ani.h @@ -29,10 +29,14 @@ public: static ani_object CreateError(ani_env *env, int32_t code, const std::string &msg); static ani_object CreateCommonError( ani_env *env, int32_t err, const std::string &functionName = "", const std::string &permissionName = ""); + static ani_object CreateInstallError(ani_env *env, int32_t err, int32_t innerCode, + const std::string &functionName = "", const std::string &permissionName = ""); static ani_object CreateEnumError(ani_env *env, const std::string ¶meter, const std::string &enumClass); static void ThrowTooFewParametersError(ani_env *env, int32_t err); static void ThrowCommonError(ani_env *env, int32_t err, const std::string ¶meter, const std::string &type); + static void ThrowInstallError(ani_env *env, int32_t err, int32_t innerCode, + const std::string ¶meter, const std::string &type); static void ThrowEnumError(ani_env *env, const std::string ¶meter, const std::string &type); static void ThrowError(ani_env *env, int32_t err, const std::string &msg = ""); private: diff --git a/interfaces/kits/js/bundle_manager/bundle_manager.cpp b/interfaces/kits/js/bundle_manager/bundle_manager.cpp index a0e59c097e0dd8e40b92f077a4a73403680f4332..d62438a22b07a8e1f38e918443f01419d253c9a6 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager.cpp @@ -2781,12 +2781,12 @@ napi_value GetLaunchWantForBundle(napi_env env, napi_callback_info info) if (i == ARGS_POS_ZERO) { if (valueType != napi_string) { APP_LOGE("GetLaunchWantForBundle bundleName is not a string"); - BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, STRING_TYPE); + BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName); if (asyncCallbackInfo->bundleName.size() == 0) { - BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, STRING_TYPE); + BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } } else if (i == ARGS_POS_ONE) {