os_account做条件编译

issue:https://gitee.com/openharmony/ability_dmsfwk/issues/I83DQF

Signed-off-by: liuxiaowei42 <liuxiaowei42@huawei.com>
This commit is contained in:
liuxiaowei42 2023-09-21 20:05:43 +08:00
parent 7c345c4a2b
commit 27326cf9a7
14 changed files with 128 additions and 78 deletions

View File

@ -42,4 +42,10 @@ declare_args() {
} else {
token_sync_enable = false
}
if (!defined(global_parts_info) ||
defined(global_parts_info.account_os_account)) {
os_account_part = true
} else {
os_account_part = false
}
}

View File

@ -13,6 +13,7 @@
import("//build/ohos.gni")
import("//build/ohos_var.gni")
import("//foundation/ability/dmsfwk/dmsfwk.gni")
group("unittest") {
testonly = true
@ -66,10 +67,12 @@ ohos_shared_library("distributed_ability_manager_svr") {
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (os_account_part) {
external_deps += [ "os_account:os_account_innerkits" ]
}
part_name = "dmsfwk"
subsystem_name = "ability"

View File

@ -70,7 +70,7 @@ private:
const std::vector<ContinuationResult>& continuationResults);
int32_t ConnectAbility(int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
int32_t DisconnectAbility();
bool QueryExtensionAbilityInfo(const std::vector<int32_t>& ids, const AAFwk::Want& want,
bool QueryExtensionAbilityInfo(const int32_t& activeAccountId, const AAFwk::Want& want,
AppExecFwk::ExtensionAbilityInfo& extensionInfo);
bool HandleDisconnectAbility();
void HandleNotifierDied(const sptr<IRemoteObject>& notifier);

View File

@ -343,26 +343,30 @@ int32_t DistributedAbilityManagerService::ConnectAbility(int32_t token,
{
AAFwk::Want want;
want.SetAction(DMS_HIPLAY_ACTION);
int32_t activeAccountId = -1;
#ifdef OS_ACCOUNT_PART
std::vector<int32_t> ids;
int32_t errCode = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (errCode != ERR_OK || ids.empty()) {
int32_t ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
return INVALID_PARAMETERS_ERR;
}
activeAccountId = ids[0];
#endif
AppExecFwk::ExtensionAbilityInfo extensionInfo;
if (!QueryExtensionAbilityInfo(ids, want, extensionInfo)) {
if (!QueryExtensionAbilityInfo(activeAccountId, want, extensionInfo)) {
HILOGE("QueryExtensionAbilityInfo failed");
return CONNECT_ABILITY_FAILED;
}
if (connect_ == nullptr) {
connect_ = new AppConnectionStub(token, continuationExtraParams);
}
errCode = AAFwk::AbilityManagerClient::GetInstance()->Connect();
int32_t errCode = AAFwk::AbilityManagerClient::GetInstance()->Connect();
if (errCode != ERR_OK) {
HILOGE("connect ability manager server failed, errCode=%{public}d", errCode);
return errCode;
}
errCode = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want,
iface_cast<AAFwk::IAbilityConnection>(connect_), this, ids[0]);
iface_cast<AAFwk::IAbilityConnection>(connect_), this, activeAccountId);
if (errCode != ERR_OK) {
HILOGE("ConnectAbility failed");
connect_ = nullptr;
@ -371,7 +375,7 @@ int32_t DistributedAbilityManagerService::ConnectAbility(int32_t token,
return ERR_OK;
}
bool DistributedAbilityManagerService::QueryExtensionAbilityInfo(const std::vector<int32_t>& ids,
bool DistributedAbilityManagerService::QueryExtensionAbilityInfo(const int32_t& activeAccountId,
const AAFwk::Want& want, AppExecFwk::ExtensionAbilityInfo& extensionInfo)
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -392,7 +396,7 @@ bool DistributedAbilityManagerService::QueryExtensionAbilityInfo(const std::vect
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
std::string identity = IPCSkeleton::ResetCallingIdentity();
bundleMgr->QueryExtensionAbilityInfos(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT
| AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, ids[0], extensionInfos);
| AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, activeAccountId, extensionInfos);
IPCSkeleton::SetCallingIdentity(identity);
if (extensionInfos.empty()) {
HILOGE("QueryExtensionAbilityInfo failed");

View File

@ -52,10 +52,12 @@ dtbabilitymgr_external_deps = [
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (os_account_part) {
dtbabilitymgr_external_deps += [ "os_account:os_account_innerkits" ]
}
dtbabilitymgr_public_deps = [
"//foundation/ability/dmsfwk/services/dtbschedmgr:distributedschedsvr",

View File

@ -46,6 +46,9 @@ config("distributed_sched_config") {
if (dmsfwk_service_disable) {
defines += [ "DMS_SERVICE_DISABLE" ]
}
if (os_account_part) {
defines += [ "OS_ACCOUNT_PART" ]
}
}
ohos_shared_library("distributedschedsvr") {
@ -119,10 +122,12 @@ ohos_shared_library("distributedschedsvr") {
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (os_account_part) {
external_deps += [ "os_account:os_account_innerkits" ]
}
if (efficiency_manager_service_enable) {
external_deps += [ "efficiency_manager:suspend_manager_client" ]

View File

@ -52,6 +52,7 @@ public:
const uint32_t accessTokenId, std::string& bundleName);
static int32_t GetApplicationInfoFromBms(const std::string& bundleName, const AppExecFwk::BundleFlag flag,
const int32_t userId, AppExecFwk::ApplicationInfo &appInfo);
static ErrCode QueryOsAccount(int32_t& activeAccountId);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -240,6 +240,7 @@ private:
int32_t SaveConnectToken(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect);
void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId);
void RemoveConnectAbilityInfo(const std::string& deviceId);
ErrCode QueryOsAccount(int32_t& activeAccountId);
std::shared_ptr<DSchedContinuation> dschedContinuation_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;

View File

@ -51,12 +51,11 @@ bool BundleManagerInternal::GetCallerAppIdFromBms(const std::string& bundleName,
HILOGE("failed to get bms");
return false;
}
std::vector<int32_t> ids;
ErrCode result = OsAccountManager::QueryActiveOsAccountIds(ids);
if (result != ERR_OK || ids.empty()) {
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return false;
}
int32_t activeAccountId = ids[0];
appId = bundleMgr->GetAppIdByBundleName(bundleName, activeAccountId);
HILOGD("appId:%s", appId.c_str());
return true;
@ -93,12 +92,11 @@ bool BundleManagerInternal::GetBundleNameListFromBms(int32_t callingUid,
bool BundleManagerInternal::QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo)
{
std::vector<int32_t> ids;
int32_t ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return false;
}
int32_t activeAccountId = ids[0];
auto bundleMgr = GetBundleManager();
if (bundleMgr == nullptr) {
HILOGE("failed to get bms");
@ -116,12 +114,11 @@ bool BundleManagerInternal::QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk
bool BundleManagerInternal::QueryExtensionAbilityInfo(const AAFwk::Want& want,
AppExecFwk::ExtensionAbilityInfo& extensionInfo)
{
std::vector<int32_t> ids;
int32_t ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return false;
}
int32_t activeAccountId = ids[0];
auto bundleMgr = GetBundleManager();
if (bundleMgr == nullptr) {
HILOGE("failed to get bms");
@ -178,13 +175,11 @@ int32_t BundleManagerInternal::GetLocalBundleInfo(const std::string& bundleName,
return INVALID_PARAMETERS_ERR;
}
std::vector<int32_t> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds failed");
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
int32_t activeAccountId = ids[0];
if (!bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT,
localBundleInfo, activeAccountId)) {
HILOGE("get local bundle info failed");
@ -202,13 +197,11 @@ int32_t BundleManagerInternal::GetLocalBundleInfoV9(const std::string& bundleNam
return INVALID_PARAMETERS_ERR;
}
std::vector<int32_t> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds failed");
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = 0;
ErrCode ret = QueryOsAccount(activeAccountId);
if (ret != ERR_OK) {
return ret;
}
int32_t activeAccountId = ids[0];
ret = bms->GetBundleInfoV9(bundleName,
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
bundleInfo, activeAccountId);
@ -270,12 +263,11 @@ bool BundleManagerInternal::CheckIfRemoteCanInstall(const AAFwk::Want& want, int
AAFwk::Want newWant;
newWant.SetElementName(deviceId, bundleName, abilityName, moduleName);
std::vector<int32_t> ids;
ErrCode result = OsAccountManager::QueryActiveOsAccountIds(ids);
if (result != ERR_OK || ids.empty()) {
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return false;
}
int32_t activeAccountId = ids[0];
bool ret = bms->CheckAbilityEnableInstall(newWant, missionId, activeAccountId, new DmsBundleManagerCallbackStub());
if (ret != true) {
HILOGE("CheckAbilityEnableInstall from bms failed");
@ -319,12 +311,11 @@ int32_t BundleManagerInternal::GetUidFromBms(const std::string& bundleName)
HILOGE("failed to get bms");
return -1;
}
std::vector<int32_t> ids;
ErrCode result = OsAccountManager::QueryActiveOsAccountIds(ids);
if (result != ERR_OK || ids.empty()) {
return -1;
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
int32_t activeAccountId = ids[0];
return bundleMgr->GetUidByBundleName(bundleName, activeAccountId);
}
@ -335,17 +326,15 @@ int32_t BundleManagerInternal::GetBundleIdFromBms(const std::string& bundleName,
HILOGE("failed to get bms");
return INVALID_PARAMETERS_ERR;
}
std::vector<int32_t> ids;
ErrCode result = OsAccountManager::QueryActiveOsAccountIds(ids);
if (result != ERR_OK || ids.empty()) {
HILOGE("fild to get userId");
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = 0;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
int32_t activeAccountId = ids[0];
AppExecFwk::ApplicationInfo appInfo;
int32_t flag = static_cast<int32_t>(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT);
result = bundleMgr->GetApplicationInfoV9(bundleName, flag, activeAccountId, appInfo);
if (result != ERR_OK) {
ErrCode ret = bundleMgr->GetApplicationInfoV9(bundleName, flag, activeAccountId, appInfo);
if (ret != ERR_OK) {
HILOGE("failed to get appInfo from bms");
return CAN_NOT_FOUND_ABILITY_ERR;
}
@ -382,5 +371,19 @@ int32_t BundleManagerInternal::GetApplicationInfoFromBms(const std::string& bund
IPCSkeleton::SetCallingIdentity(identity);
return ERR_OK;
}
ErrCode BundleManagerInternal::QueryOsAccount(int32_t& activeAccountId)
{
#ifdef OS_ACCOUNT_PART
std::vector<int32_t> ids;
ErrCode err = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (err != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds passing param invalid or return error!, err : %{public}d", err);
return INVALID_PARAMETERS_ERR;
}
activeAccountId = ids[0];
#endif
return ERR_OK;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -73,14 +73,18 @@ int32_t DistributedSchedAdapter::ConnectAbility(const OHOS::AAFwk::Want& want,
EventErrorType::GET_ABILITY_MGR_FAILED);
return errCode;
}
int32_t activeAccountId = -1;
#ifdef OS_ACCOUNT_PART
std::vector<int> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
errCode = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (errCode != ERR_OK || ids.empty()) {
return INVALID_PARAMETERS_ERR;
}
ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want,
iface_cast<AAFwk::IAbilityConnection>(connect), callerToken, ids[0]);
return ret;
activeAccountId = ids[0];
#endif
errCode = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want,
iface_cast<AAFwk::IAbilityConnection>(connect), callerToken, activeAccountId);
return errCode;
}
int32_t DistributedSchedAdapter::DisconnectAbility(const sptr<IRemoteObject>& connect)

View File

@ -343,13 +343,17 @@ void DistributedSchedPermission::MarkUriPermission(OHOS::AAFwk::Want& want, uint
std::string authority = uri.GetAuthority();
HILOGI("uri authority is %{public}s.", authority.c_str());
AppExecFwk::BundleInfo bundleInfo;
int32_t activeAccountId = 0;
#ifdef OS_ACCOUNT_PART
std::vector<int32_t> ids;
int32_t errCode = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (errCode != ERR_OK || ids.empty()) {
return;
}
activeAccountId = ids[0];
#endif
if (!bms->GetBundleInfo(authority,
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, ids[0])) {
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, activeAccountId)) {
HILOGW("To fail to get bundle info according to uri.");
continue;
}

View File

@ -1747,6 +1747,20 @@ void DistributedSchedService::RemoveConnectAbilityInfo(const std::string& device
}
}
ErrCode DistributedSchedService::QueryOsAccount(int32_t& activeAccountId)
{
#ifdef OS_ACCOUNT_PART
std::vector<int32_t> ids;
ErrCode err = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (err != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds passing param invalid or return error!, err : %{public}d", err);
return INVALID_PARAMETERS_ERR;
}
activeAccountId = ids[0];
#endif
return ERR_OK;
}
void DistributedSchedService::ProcessDeviceOffline(const std::string& deviceId)
{
HILOGI("ProcessDeviceOffline called");
@ -2119,16 +2133,15 @@ int32_t DistributedSchedService::StartFreeInstallFromRemote(const FreeInstallInf
HILOGE("connect ability server failed %{public}d", err);
return err;
}
std::vector<int32_t> ids;
err = OsAccountManager::QueryActiveOsAccountIds(ids);
if (err != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds passing param invalid or return error!, err : %{public}d", err);
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = -1;
err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
sptr<DmsFreeInstallCallback> callback = new DmsFreeInstallCallback(taskId, info);
err = AAFwk::AbilityManagerClient::GetInstance()->FreeInstallAbilityFromRemote(
info.want, callback, ids[0], info.requestCode);
info.want, callback, activeAccountId, info.requestCode);
if (err != ERR_OK) {
HILOGE("FreeInstallAbilityFromRemote failed %{public}d", err);
}
@ -2176,18 +2189,19 @@ int32_t DistributedSchedService::StartAbility(const OHOS::AAFwk::Want& want, int
HILOGE("connect ability server failed %{public}d", err);
return err;
}
std::vector<int> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = -1;
err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
if (want.GetBoolParam(Want::PARAM_RESV_FOR_RESULT, false)) {
HILOGI("StartAbilityForResult start");
sptr<IRemoteObject> dmsTokenCallback = new DmsTokenCallback();
err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, dmsTokenCallback, requestCode, ids[0]);
err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, dmsTokenCallback, requestCode,
activeAccountId);
} else {
HILOGI("StartAbility start");
err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, requestCode, ids[0]);
err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, requestCode, activeAccountId);
}
if (err != ERR_OK) {
HILOGE("StartAbility failed %{public}d", err);
@ -2527,15 +2541,14 @@ int32_t DistributedSchedService::StopExtensionAbilityFromRemote(const OHOS::AAFw
want.RemoveParam(DMS_SRC_NETWORK_ID);
sptr<IRemoteObject> callerToken = new DmsTokenCallback();
std::vector<int> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds failed!!");
return INVALID_PARAMETERS_ERR;
int32_t activeAccountId = -1;
ErrCode err = QueryOsAccount(activeAccountId);
if (err != ERR_OK) {
return err;
}
return AAFwk::AbilityManagerClient::GetInstance()->StopExtensionAbility(
want, callerToken, ids[0], static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
want, callerToken, activeAccountId, static_cast<AppExecFwk::ExtensionAbilityType>(extensionType));
}
void DistributedSchedService::SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId)

View File

@ -61,10 +61,12 @@ dsched_external_deps = [
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (os_account_part) {
dsched_external_deps += [ "os_account:os_account_innerkits" ]
}
if (dmsfwk_report_memmgr) {
dsched_external_deps += [ "memmgr:memmgrclient" ]

View File

@ -56,10 +56,12 @@ dtbabilitymgr_external_deps = [
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (os_account_part) {
dtbabilitymgr_external_deps += [ "os_account:os_account_innerkits" ]
}
##############################fuzztest##########################################
ohos_fuzztest("ContinuationManagerFuzzTest") {