Description:Split big func.

Sig:SIG_ApplicationFramework
Feature or BugFix: Feature
Binary Source: No

Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com>
Change-Id: I12505b2af15f1b3484cac3d7583f2ff6850ee435
This commit is contained in:
zhangyafei.echo 2023-12-11 19:44:01 +08:00
parent 19c273bdc7
commit 5c53493c0d
4 changed files with 79 additions and 42 deletions

View File

@ -114,6 +114,7 @@ private:
bool ParseAbilityInfo(const std::string &abilitySrcPath);
bool LoadRuntimeEnv(napi_env env, napi_value globalObject);
static napi_value RequireNapi(napi_env env, napi_callback_info info);
inline void SetHostResolveBufferTracker();
panda::ecmascript::EcmaVM *CreateJSVM();
Options options_;
@ -661,24 +662,7 @@ bool SimulatorImpl::OnInit()
return false;
}
panda::JSNApi::SetHostResolveBufferTracker(vm_,
[](const std::string &inputPath, uint8_t **buff, size_t *buffSize) -> bool {
if (inputPath.empty() || buff == nullptr || buffSize == nullptr) {
HILOG_ERROR("Param invalid.");
return false;
}
HILOG_DEBUG("Get module buffer, input path: %{public}s.", inputPath.c_str());
auto data = Ide::StageContext::GetInstance().GetModuleBuffer(inputPath);
if (data == nullptr) {
HILOG_ERROR("Get module buffer failed, input path: %{public}s.", inputPath.c_str());
return false;
}
*buff = data->data();
*buffSize = data->size();
return true;
});
SetHostResolveBufferTracker();
panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, (options_.debugPort != 0), options_.debugPort};
panda::JSNApi::StartDebugger(vm_, debugOption, 0,
std::bind(&DebuggerTask::OnPostTask, &debuggerTask_, std::placeholders::_1));
@ -798,5 +782,27 @@ std::unique_ptr<Simulator> Simulator::Create(const Options &options)
}
return nullptr;
}
void SimulatorImpl::SetHostResolveBufferTracker()
{
panda::JSNApi::SetHostResolveBufferTracker(vm_,
[](const std::string &inputPath, uint8_t **buff, size_t *buffSize) -> bool {
if (inputPath.empty() || buff == nullptr || buffSize == nullptr) {
HILOG_ERROR("Param invalid.");
return false;
}
HILOG_DEBUG("Get module buffer, input path: %{public}s.", inputPath.c_str());
auto data = Ide::StageContext::GetInstance().GetModuleBuffer(inputPath);
if (data == nullptr) {
HILOG_ERROR("Get module buffer failed, input path: %{public}s.", inputPath.c_str());
return false;
}
*buff = data->data();
*buffSize = data->size();
return true;
});
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -81,6 +81,7 @@ public:
private:
bool CheckTaskRunningState(const std::string &bundleName);
void AddApplyTask(std::shared_ptr<QuickFixManagerApplyTask> applyTask);
int32_t GetQuickFixInfo(const std::string &bundleName, bool &patchExists, bool &isSoContained);
static std::mutex mutex_;
static sptr<QuickFixManagerService> instance_;

View File

@ -140,30 +140,11 @@ int32_t QuickFixManagerService::RevokeQuickFix(const std::string &bundleName)
return QUICK_FIX_DEPLOYING_TASK;
}
auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
if (bundleMgrHelper == nullptr) {
HILOG_ERROR("Failed to get bundle manager helper.");
return QUICK_FIX_CONNECT_FAILED;
}
AppExecFwk::BundleInfo bundleInfo;
if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo,
AppExecFwk::Constants::ANY_USERID)) {
HILOG_ERROR("Get bundle info failed.");
return QUICK_FIX_GET_BUNDLE_INFO_FAILED;
}
auto isSoContained = !bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath.empty();
auto patchExists = true;
for (auto &item : bundleInfo.hapModuleInfos) {
if (!item.hqfInfo.moduleName.empty()) {
patchExists = false;
break;
}
}
if (patchExists) {
HILOG_ERROR("Patch does not exist.");
auto patchExists = false;
auto isSoContained = false;
auto ret = GetQuickFixInfo(bundleName, patchExists, isSoContained);
if (ret != QUICK_FIX_OK || !patchExists) {
HILOG_ERROR("Get bundle info failed or patch does not exist.");
return QUICK_FIX_GET_BUNDLE_INFO_FAILED;
}
@ -222,5 +203,31 @@ bool QuickFixManagerService::CheckTaskRunningState(const std::string &bundleName
HILOG_DEBUG("bundleName %{public}s not found in tasks.", bundleName.c_str());
return false;
}
int32_t QuickFixManagerService::GetQuickFixInfo(const std::string &bundleName, bool &patchExists, bool &isSoContained)
{
auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
if (bundleMgrHelper == nullptr) {
HILOG_ERROR("Failed to get bundle manager helper.");
return QUICK_FIX_CONNECT_FAILED;
}
AppExecFwk::BundleInfo bundleInfo;
if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo,
AppExecFwk::Constants::ANY_USERID)) {
HILOG_ERROR("Get bundle info failed.");
return QUICK_FIX_GET_BUNDLE_INFO_FAILED;
}
for (auto &item : bundleInfo.hapModuleInfos) {
if (!item.hqfInfo.moduleName.empty()) {
patchExists = true;
break;
}
}
isSoContained = !bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath.empty();
return QUICK_FIX_OK;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -221,5 +221,28 @@ HWTEST_F(QuickFixManagerServiceTest, RevokeQuickFix_0300, TestSize.Level1)
HILOG_INFO("%{public}s end.", __func__);
}
/**
* @tc.name: GetQuickFixInfo_0100
* @tc.desc: RevokeQuickFix GetQuickFixInfo
* @tc.type: FUNC
*/
HWTEST_F(QuickFixManagerServiceTest, GetQuickFixInfo_0100, TestSize.Level1)
{
HILOG_INFO("GetQuickFixInfo_0100 start.");
auto mockGetBundleInstaller = []() { return mockBundleInstaller; };
EXPECT_CALL(*mockBundleMgr, GetBundleInstaller()).WillOnce(testing::Invoke(mockGetBundleInstaller));
std::string bundleName = "com.ohos.quickfix";
auto patchExists = false;
auto isSoContained = false;
auto ret = quickFixMs_->GetQuickFixInfo(bundleName, patchExists, isSoContained);
EXPECT_EQ(ret, QUICK_FIX_OK);
EXPECT_EQ(patchExists, true);
EXPECT_EQ(isSoContained, true);
HILOG_INFO("GetQuickFixInfo_0100 end.");
}
} // namespace AppExecFwk
} // namespace OHOS