mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 06:50:40 +00:00
!10570 为TS侧提供GetAbilityInfo接口
Merge pull request !10570 from nzy/cherry-pick-1730962550
This commit is contained in:
commit
90381a35e4
@ -144,6 +144,7 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj)
|
||||
JsSceneSessionManager::InitWithRenderServiceAdded);
|
||||
BindNativeFunction(env, exportObj, "getAllAbilityInfo", moduleName, JsSceneSessionManager::GetAllAbilityInfos);
|
||||
BindNativeFunction(env, exportObj, "getBatchAbilityInfos", moduleName, JsSceneSessionManager::GetBatchAbilityInfos);
|
||||
BindNativeFunction(env, exportObj, "getAbilityInfo", moduleName, JsSceneSessionManager::GetAbilityInfo);
|
||||
BindNativeFunction(env, exportObj, "getAllWindowVisibilityInfos", moduleName,
|
||||
JsSceneSessionManager::GetAllWindowVisibilityInfos);
|
||||
BindNativeFunction(env, exportObj, "prepareTerminate", moduleName, JsSceneSessionManager::PrepareTerminate);
|
||||
@ -816,6 +817,13 @@ napi_value JsSceneSessionManager::GetBatchAbilityInfos(napi_env env, napi_callba
|
||||
return (me != nullptr) ? me->OnGetBatchAbilityInfos(env, info) : nullptr;
|
||||
}
|
||||
|
||||
napi_value JsSceneSessionManager::GetAbilityInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
TLOGD(WmsLogTag::WMS_SCB, "[NAPI]");
|
||||
JsSceneSessionManager* me = CheckParamsAndGetThis<JsSceneSessionManager>(env, info);
|
||||
return (me != nullptr) ? me->OnGetAbilityInfo(env, info) : nullptr;
|
||||
}
|
||||
|
||||
napi_value JsSceneSessionManager::PrepareTerminate(napi_env env, napi_callback_info info)
|
||||
{
|
||||
WLOGFD("[NAPI]");
|
||||
@ -1422,6 +1430,55 @@ napi_value JsSceneSessionManager::OnGetBatchAbilityInfos(napi_env env, napi_call
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsSceneSessionManager::OnGetAbilityInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = DEFAULT_ARG_COUNT;
|
||||
napi_value argv[DEFAULT_ARG_COUNT] = { nullptr };
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
if (argc != ARGC_FOUR) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Argc is invalid: %{public}zu", argc);
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
|
||||
"Input parameter is missing or invalid"));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
std::string bundleName;
|
||||
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to bundleName");
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
|
||||
"Input parameter is missing or invalid"));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
std::string moduleName;
|
||||
if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], moduleName)) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to moduleName");
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
|
||||
"Input parameter is missing or invalid"));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
std::string abilityName;
|
||||
if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], abilityName)) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to abilityName");
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
|
||||
"Input parameter is missing or invalid"));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
int32_t userId = 0;
|
||||
if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], userId)) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "[NAPI]Failed to convert parameter to userId");
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
|
||||
"Input parameter is missing or invalid"));
|
||||
return NapiGetUndefined(env);
|
||||
}
|
||||
SCBAbilityInfo scbAbilityInfo;
|
||||
WSErrorCode ret = WS_JS_TO_ERROR_CODE_MAP.at(SceneSessionManager::GetInstance().GetAbilityInfo(
|
||||
bundleName, moduleName, abilityName, userId, scbAbilityInfo));
|
||||
if (ret != WSErrorCode::WS_OK) {
|
||||
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_STATE_ABNORMALLY),
|
||||
"System is abnormal"));
|
||||
}
|
||||
return CreateSCBAbilityInfo(env, scbAbilityInfo);
|
||||
}
|
||||
|
||||
napi_value JsSceneSessionManager::OnInitUserInfo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 4;
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
static napi_value GetAllWindowVisibilityInfos(napi_env env, napi_callback_info info);
|
||||
static napi_value GetAllAbilityInfos(napi_env env, napi_callback_info info);
|
||||
static napi_value GetBatchAbilityInfos(napi_env env, napi_callback_info info);
|
||||
static napi_value GetAbilityInfo(napi_env env, napi_callback_info info);
|
||||
static napi_value PrepareTerminate(napi_env env, napi_callback_info info);
|
||||
static napi_value PerfRequestEx(napi_env env, napi_callback_info info);
|
||||
static napi_value UpdateWindowMode(napi_env env, napi_callback_info info);
|
||||
@ -147,6 +148,7 @@ private:
|
||||
napi_value OnGetAllWindowVisibilityInfos(napi_env env, napi_callback_info info);
|
||||
napi_value OnGetAllAbilityInfos(napi_env env, napi_callback_info info);
|
||||
napi_value OnGetBatchAbilityInfos(napi_env env, napi_callback_info info);
|
||||
napi_value OnGetAbilityInfo(napi_env env, napi_callback_info info);
|
||||
napi_value OnPrepareTerminate(napi_env env, napi_callback_info info);
|
||||
napi_value OnPerfRequestEx(napi_env env, napi_callback_info info);
|
||||
napi_value OnUpdateWindowMode(napi_env env, napi_callback_info info);
|
||||
|
@ -286,6 +286,8 @@ public:
|
||||
std::vector<SCBAbilityInfo>& scbAbilityInfos);
|
||||
WSError GetBatchAbilityInfos(const std::vector<std::string>& bundleNames, int32_t userId,
|
||||
std::vector<SCBAbilityInfo>& scbAbilityInfos);
|
||||
WSError GetAbilityInfo(const std::string& bundleName, const std::string& moduleName,
|
||||
const std::string& abilityName, int32_t userId, SCBAbilityInfo& scbAbilityInfo);
|
||||
WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate);
|
||||
|
||||
WSError TerminateSessionNew(
|
||||
@ -692,7 +694,7 @@ private:
|
||||
void DestroyExtensionSession(const sptr<IRemoteObject>& remoteExtSession);
|
||||
void EraseSceneSessionMapById(int32_t persistentId);
|
||||
void EraseSceneSessionAndMarkDirtyLockFree(int32_t persistentId);
|
||||
WSError GetAbilityInfosFromBundleInfo(std::vector<AppExecFwk::BundleInfo>& bundleInfos,
|
||||
WSError GetAbilityInfosFromBundleInfo(const std::vector<AppExecFwk::BundleInfo>& bundleInfos,
|
||||
std::vector<SCBAbilityInfo>& scbAbilityInfos);
|
||||
void GetOrientationFromResourceManager(AppExecFwk::AbilityInfo& abilityInfo);
|
||||
void UpdatePrivateStateAndNotifyForAllScreens();
|
||||
|
@ -6741,27 +6741,80 @@ __attribute__((no_sanitize("cfi"))) WSError SceneSessionManager::GetBatchAbility
|
||||
return GetAbilityInfosFromBundleInfo(bundleInfos, scbAbilityInfos);
|
||||
}
|
||||
|
||||
WSError SceneSessionManager::GetAbilityInfosFromBundleInfo(std::vector<AppExecFwk::BundleInfo>& bundleInfos,
|
||||
WSError SceneSessionManager::GetAbilityInfo(const std::string& bundleName, const std::string& moduleName,
|
||||
const std::string& abilityName, int32_t userId, SCBAbilityInfo& scbAbilityInfo)
|
||||
{
|
||||
if (bundleMgr_ == nullptr) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "bundleMgr_ is nullptr");
|
||||
return WSError::WS_ERROR_NULLPTR;
|
||||
}
|
||||
auto flags = (AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION |
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION |
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_METADATA |
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) |
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE));
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
if (bundleMgr_->GetBundleInfoV9(bundleName, flags, bundleInfo, userId)) {
|
||||
TLOGE(WmsLogTag::DEFAULT, "Query ability info from BMS failed, ability:%{public}s", abilityName.c_str());
|
||||
return WSError::WS_ERROR_INVALID_PARAM;
|
||||
}
|
||||
auto& hapModulesList = bundleInfo.hapModuleInfos;
|
||||
if (hapModulesList.empty()) {
|
||||
TLOGD(WmsLogTag::DEFAULT, "hapModulesList is empty, ability:%{public}s", abilityName.c_str());
|
||||
return WSError::WS_ERROR_INVALID_PARAM;
|
||||
}
|
||||
auto sdkVersion = bundleInfo.targetVersion % 100; // % 100 to get the real version
|
||||
for (auto& hapModule : hapModulesList) {
|
||||
auto& abilityInfoList = hapModule.abilityInfos;
|
||||
for (auto& abilityInfo : abilityInfoList) {
|
||||
if (abilityInfo.moduleName == moduleName && abilityInfo.name == abilityName) {
|
||||
scbAbilityInfo.abilityInfo_ = abilityInfo;
|
||||
scbAbilityInfo.sdkVersion_ = sdkVersion;
|
||||
scbAbilityInfo.codePath_ = bundleInfo.applicationInfo.codePath;
|
||||
GetOrientationFromResourceManager(scbAbilityInfo.abilityInfo_);
|
||||
return WSError::WS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
TLOGW(WmsLogTag::DEFAULT, "Ability info not found, ability:%{public}s", abilityName.c_str());
|
||||
return WSError::WS_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
WSError SceneSessionManager::GetAbilityInfosFromBundleInfo(const std::vector<AppExecFwk::BundleInfo>& bundleInfos,
|
||||
std::vector<SCBAbilityInfo>& scbAbilityInfos)
|
||||
{
|
||||
if (bundleInfos.empty()) {
|
||||
WLOGFE("bundleInfos is empty");
|
||||
return WSError::WS_ERROR_INVALID_PARAM;
|
||||
}
|
||||
for (auto bundleInfo: bundleInfos) {
|
||||
auto hapModulesList = bundleInfo.hapModuleInfos;
|
||||
for (auto& bundleInfo : bundleInfos) {
|
||||
auto& hapModulesList = bundleInfo.hapModuleInfos;
|
||||
auto sdkVersion = bundleInfo.targetVersion % 100; // %100 to get the real version
|
||||
if (hapModulesList.empty()) {
|
||||
WLOGFD("hapModulesList is empty");
|
||||
continue;
|
||||
}
|
||||
for (auto hapModule: hapModulesList) {
|
||||
auto abilityInfoList = hapModule.abilityInfos;
|
||||
for (auto abilityInfo : abilityInfoList) {
|
||||
if (bundleInfo.applicationInfo.codePath == std::to_string(CollaboratorType::RESERVE_TYPE) ||
|
||||
bundleInfo.applicationInfo.codePath == std::to_string(CollaboratorType::OTHERS_TYPE)) {
|
||||
auto iter = std::find_if(hapModulesList.begin(), hapModulesList.end(),
|
||||
[](const AppExecFwk::HapModuleInfo& hapModule) { return !hapModule.abilityInfos.empty(); });
|
||||
if (iter != hapModulesList.end()) {
|
||||
SCBAbilityInfo scbAbilityInfo;
|
||||
scbAbilityInfo.abilityInfo_ = iter->abilityInfos[0];
|
||||
scbAbilityInfo.sdkVersion_ = sdkVersion;
|
||||
scbAbilityInfo.codePath_ = bundleInfo.applicationInfo.codePath;
|
||||
GetOrientationFromResourceManager(scbAbilityInfo.abilityInfo_);
|
||||
scbAbilityInfos.push_back(scbAbilityInfo);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (auto& hapModule : hapModulesList) {
|
||||
auto& abilityInfoList = hapModule.abilityInfos;
|
||||
for (auto& abilityInfo : abilityInfoList) {
|
||||
SCBAbilityInfo scbAbilityInfo;
|
||||
scbAbilityInfo.abilityInfo_ = abilityInfo;
|
||||
scbAbilityInfo.sdkVersion_ = sdkVersion;
|
||||
scbAbilityInfo.codePath_ = bundleInfo.applicationInfo.codePath;
|
||||
GetOrientationFromResourceManager(scbAbilityInfo.abilityInfo_);
|
||||
scbAbilityInfos.push_back(scbAbilityInfo);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user