GetHapModuleInfo

Signed-off-by: dujingcheng <dujingcheng@huawei.com>
This commit is contained in:
dujingcheng
2022-03-30 10:36:50 +08:00
parent 0edd5e1192
commit fb69b4e981
10 changed files with 137 additions and 4 deletions
@@ -238,6 +238,13 @@ private:
* @return Returns ERR_OK if called successfully; returns error code otherwise.
*/
ErrCode HandleGetHapModuleInfo(Parcel &data, Parcel &reply);
/**
* @brief Handles the GetHapModuleInfo function called from a IBundleMgr proxy object.
* @param data Indicates the data to be read.
* @param reply Indicates the reply to be sent;
* @return Returns ERR_OK if called successfully; returns error code otherwise.
*/
ErrCode HandleGetHapModuleInfoWithUserId(Parcel &data, Parcel &reply);
/**
* @brief Handles the GetLaunchWantForBundle function called from a IBundleMgr proxy object.
* @param data Indicates the data to be read.
@@ -334,6 +334,17 @@ public:
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) = 0;
/**
* @brief Obtain the HAP module info of a specific ability.
* @param abilityInfo Indicates the ability.
* @param userId Indicates the userId.
* @param hapModuleInfo Indicates the obtained HapModuleInfo object.
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo)
{
return false;
}
/**
* @brief Obtains the Want for starting the main ability of an application based on the given bundle name.
* @param bundleName Indicates the bundle name.
@@ -796,6 +807,7 @@ public:
VERIFY_CALLING_PERMISSION,
GET_ACCESSIBLE_APP_CODE_PATH,
QUERY_EXTENSION_ABILITY_INFO_BY_URI,
GET_HAP_MODULE_INFO_WITH_USERID,
};
};
} // namespace AppExecFwk
@@ -292,6 +292,15 @@ public:
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) override;
/**
* @brief Obtain the HAP module info of a specific ability through the proxy object.
* @param abilityInfo Indicates the ability.
* @param userId Indicates the userId.
* @param hapModuleInfo Indicates the obtained HapModuleInfo object.
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(
const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo) override;
/**
* @brief Obtains the Want for starting the main ability of an application
* based on the given bundle name through the proxy object.
@@ -301,6 +301,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa
case static_cast<uint32_t>(IBundleMgr::Message::GET_UID_BY_BUNDLE_NAME):
errCode = HandleGetUidByBundleName(data, reply);
break;
case static_cast<uint32_t>(IBundleMgr::Message::GET_HAP_MODULE_INFO_WITH_USERID):
errCode = HandleGetHapModuleInfoWithUserId(data, reply);
break;
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
@@ -917,6 +920,31 @@ ErrCode BundleMgrHost::HandleGetHapModuleInfo(Parcel &data, Parcel &reply)
return ERR_OK;
}
ErrCode BundleMgrHost::HandleGetHapModuleInfoWithUserId(Parcel &data, Parcel &reply)
{
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
if (!abilityInfo) {
APP_LOGE("ReadParcelable<abilityInfo> failed");
return ERR_APPEXECFWK_PARCEL_ERROR;
}
int32_t userId = data.ReadInt32();
HapModuleInfo info;
bool ret = GetHapModuleInfo(*abilityInfo, userId, info);
if (!reply.WriteBool(ret)) {
APP_LOGE("write failed");
return ERR_APPEXECFWK_PARCEL_ERROR;
}
if (ret) {
if (!reply.WriteParcelable(&info)) {
APP_LOGE("write failed");
return ERR_APPEXECFWK_PARCEL_ERROR;
}
}
return ERR_OK;
}
ErrCode BundleMgrHost::HandleGetLaunchWantForBundle(Parcel &data, Parcel &reply)
{
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
@@ -947,6 +947,36 @@ bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleI
return true;
}
bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo)
{
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
APP_LOGI("begin to GetHapModuleInfo of %{public}s", abilityInfo.package.c_str());
if (abilityInfo.bundleName.empty() || abilityInfo.package.empty()) {
APP_LOGE("fail to GetHapModuleInfo due to params empty");
return false;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
APP_LOGE("fail to GetHapModuleInfo due to write InterfaceToken fail");
return false;
}
if (!data.WriteParcelable(&abilityInfo)) {
APP_LOGE("fail to GetHapModuleInfo due to write abilityInfo fail");
return false;
}
if (!data.WriteInt32(userId)) {
APP_LOGE("fail to QueryAbilityInfo due to write want fail");
return false;
}
if (!GetParcelableInfo<HapModuleInfo>(IBundleMgr::Message::GET_HAP_MODULE_INFO_WITH_USERID, data, hapModuleInfo)) {
APP_LOGE("fail to GetHapModuleInfo from server");
return false;
}
return true;
}
bool BundleMgrProxy::GetLaunchWantForBundle(const std::string &bundleName, Want &want)
{
BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__);
+3 -1
View File
@@ -304,10 +304,12 @@ public:
/**
* @brief Obtain the HAP module info of a specific ability.
* @param abilityInfo Indicates the ability.
* @param userId Indicates the user ID.
* @param hapModuleInfo Indicates the obtained HapModuleInfo object.
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) const;
bool GetHapModuleInfo(const AbilityInfo &abilityInfo,
HapModuleInfo &hapModuleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const;
/**
* @brief Check whether the app is system app by it's UID.
* @param uid Indicates the uid.
@@ -280,6 +280,15 @@ public:
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) override;
/**
* @brief Obtain the HAP module info of a specific ability through the proxy object.
* @param abilityInfo Indicates the ability.
* @param userId Indicates the userId.
* @param hapModuleInfo Indicates the obtained HapModuleInfo object.
* @return Returns true if the HapModuleInfo is successfully obtained; returns false otherwise.
*/
virtual bool GetHapModuleInfo(
const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo) override;
/**
* @brief Obtains the Want for starting the main ability of an application based on the given bundle name.
* @param bundleName Indicates the bundle name.
+8 -2
View File
@@ -1143,9 +1143,15 @@ std::string BundleDataMgr::GetAbilityLabel(const std::string &bundleName, const
}
}
bool BundleDataMgr::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) const
bool BundleDataMgr::GetHapModuleInfo(
const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo, int32_t userId) const
{
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
int32_t requestUserId = GetUserId(userId);
if (requestUserId == Constants::INVALID_USERID) {
return false;
}
if (bundleInfos_.empty()) {
APP_LOGE("bundleInfos_ data is empty");
return false;
@@ -1163,7 +1169,7 @@ bool BundleDataMgr::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleIn
return false;
}
int32_t responseUserId = innerBundleInfo.GetResponseUserId(GetUserId());
int32_t responseUserId = innerBundleInfo.GetResponseUserId(requestUserId);
auto module = innerBundleInfo.FindHapModuleInfo(abilityInfo.package, responseUserId);
if (!module) {
APP_LOGE("can not find module %{public}s", abilityInfo.package.c_str());
@@ -383,6 +383,12 @@ bool BundleMgrHostImpl::GetBundleArchiveInfo(
bool BundleMgrHostImpl::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)
{
APP_LOGD("start GetHapModuleInfo");
return GetHapModuleInfo(abilityInfo, Constants::UNSPECIFIED_USERID, hapModuleInfo);
}
bool BundleMgrHostImpl::GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo)
{
APP_LOGD("start GetHapModuleInfo with userId: %{public}d", userId);
if (abilityInfo.bundleName.empty() || abilityInfo.package.empty()) {
APP_LOGE("fail to GetHapModuleInfo due to params empty");
return false;
@@ -392,7 +398,7 @@ bool BundleMgrHostImpl::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModu
APP_LOGE("DataMgr is nullptr");
return false;
}
return dataMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo);
return dataMgr->GetHapModuleInfo(abilityInfo, hapModuleInfo, userId);
}
bool BundleMgrHostImpl::GetLaunchWantForBundle(const std::string &bundleName, Want &want)
@@ -67,6 +67,7 @@ const std::string PROCESS_TEST = "test.process";
const std::string DEVICE_ID = "PHONE-001";
const int APPLICATION_INFO_FLAGS = 1;
const int DEFAULT_USER_ID_TEST = 100;
const int NEW_USER_ID_TEST = 200;
const std::string LABEL = "hello";
const std::string DESCRIPTION = "mainEntry";
const std::string THEME = "mytheme";
@@ -1999,6 +2000,29 @@ HWTEST_F(BmsBundleKitServiceTest, GetHapModuleInfo_0300, Function | SmallTest |
MockUninstallBundle(BUNDLE_NAME_TEST);
}
/**
* @tc.number: GetHapModuleInfo_0400
* @tc.name: test get the hap module info by userId
* @tc.desc: 1.system run normally
* 2.get the hap module info failed
*/
HWTEST_F(BmsBundleKitServiceTest, GetHapModuleInfo_0400, Function | SmallTest | Level1)
{
MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST);
AbilityInfo abilityInfo;
abilityInfo.bundleName = BUNDLE_NAME_TEST;
abilityInfo.package = PACKAGE_NAME;
HapModuleInfo hapModuleInfo;
bool ret = GetBundleDataMgr()->GetHapModuleInfo(abilityInfo, hapModuleInfo, DEFAULT_USER_ID_TEST);
EXPECT_EQ(true, ret);
ret = GetBundleDataMgr()->GetHapModuleInfo(abilityInfo, hapModuleInfo, NEW_USER_ID_TEST);
EXPECT_EQ(false, ret);
MockUninstallBundle(BUNDLE_NAME_TEST);
}
/**
* @tc.number: CheckApplicationEnabled_0100
* @tc.name: test can check bundle status is enable by no setting