Signed-off-by: MisterE <smart_e@126.com>
This commit is contained in:
MisterE 2024-08-28 18:58:50 +08:00
commit 4c98d5caa9
15 changed files with 98 additions and 67 deletions

View File

@ -27,7 +27,8 @@
"ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT",
"ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT",
"ohos.permission.RUNNING_STATE_OBSERVER",
"ohos.permission.START_INVISIBLE_ABILITY"
"ohos.permission.START_INVISIBLE_ABILITY",
"ohos.permission.MANAGE_LOCAL_ACCOUNTS"
],
"permission_acls" : [
"ohos.permission.INPUT_MONITORING",

View File

@ -52,6 +52,7 @@ public:
std::string destBundleName_ = "";
std::string destModuleName_ = "";
std::string destAbilityName_ = "";
std::string developerId_ = "";
DSchedEventType dSchedEventType_ = DMS_UNKNOW;
DSchedEventState state_ = DMS_DSCHED_EVENT_INIT;
};

View File

@ -80,6 +80,7 @@ void DSchedEventListenerStub::DSchedEventNotifyInner(MessageParcel &data, Messag
eventNotify.destBundleName_ = data.ReadString();
eventNotify.destModuleName_ = data.ReadString();
eventNotify.destAbilityName_ = data.ReadString();
eventNotify.developerId_ = data.ReadString();
eventNotify.dSchedEventType_ = static_cast<DSchedEventType>(data.ReadInt32());
eventNotify.state_ = static_cast<DSchedEventState>(data.ReadInt32());
DSchedEventNotify(eventNotify);

View File

@ -82,6 +82,7 @@ void Business::GetDSchedEventInfo(DSchedEventType type)
cout << "destBundleName: " << notify.destBundleName_ << endl;
cout << "destModuleName: " << notify.destModuleName_ << endl;
cout << "destAbilityName: " << notify.destAbilityName_ << endl;
cout << "developerId: " << notify.developerId_ << endl;
cout << "dSchedEventType: " << notify.dSchedEventType_ << endl;
cout << "state: " << notify.state_ << endl << endl;
}
@ -101,6 +102,7 @@ void Business::DSchedEventNotify(EventNotify& notify)
cout << "destBundleName: " << notify.destBundleName_ << endl;
cout << "destModuleName: " << notify.destModuleName_ << endl;
cout << "destAbilityName: " << notify.destAbilityName_ << endl;
cout << "developerId: " << notify.developerId_ << endl;
cout << "dSchedEventType: " << notify.dSchedEventType_ << endl;
cout << "state: " << notify.state_ << endl;
cout << "DSchedEventNotify Success." << endl;

View File

@ -44,7 +44,7 @@ public:
AppExecFwk::AbilityInfo &abilityInfo);
static bool IsSameAppId(const std::string& callerAppId, const std::string& targetBundleName);
static bool IsSameDeveloperId(const std::string &callerDeveloperId,
const std::string &targetBundleName);
const std::string &targetBundleName);
static int32_t GetLocalBundleInfo(const std::string& bundleName, AppExecFwk::BundleInfo &localBundleInfo);
static int32_t GetLocalBundleInfoV9(const std::string& bundleName, AppExecFwk::BundleInfo &bundleInfo);
static bool GetContinueBundle4Src(const std::string& srcBundleName,

View File

@ -152,7 +152,6 @@ private:
int32_t ExecuteContinueReq(std::shared_ptr<DistributedWantParams> wantParams);
int32_t ExecuteContinueAbility(int32_t appVersion);
int32_t ExecuteContinueReply();
bool MakeCallerInfo(std::shared_ptr<ContinueAbilityData> data, CallerInfo &callerInfo);
int32_t ExecuteContinueSend(std::shared_ptr<ContinueAbilityData> data);
int32_t ExecuteContinueData(std::shared_ptr<DSchedContinueDataCmd> cmd);

View File

@ -45,6 +45,7 @@ struct ContinueEventInfo {
std::string bundleName;
std::string moduleName;
std::string abilityName;
std::string developerId;
};
class DmsBmStorage {
@ -82,8 +83,8 @@ private:
void AddBundleNameId(const uint16_t &bundleNameId, const std::string &bundleName);
void DelBundleNameId(const std::string &bundleName);
DmsBundleInfo ConvertToDistributedBundleInfo(const AppExecFwk::BundleInfo &bundleInfo,
AppExecFwk::AppProvisionInfo appProvisionInfo,
bool isPackageChange = false);
AppExecFwk::AppProvisionInfo appProvisionInfo,
bool isPackageChange = false);
bool InnerSaveStorageDistributeInfo(const DmsBundleInfo &distributedBundleInfo, const std::string &localUdid);
std::map<std::string, DmsBundleInfo> GetAllOldDistributionBundleInfo(
const std::vector<std::string> &bundleNames);

View File

@ -22,9 +22,9 @@
#include "mission/dsched_sync_e2e.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "mock_form_mgr_service.h"
#include "os_account_manager.h"
#include "system_ability_definition.h"
#include "os_account_manager.h"
namespace OHOS {
namespace DistributedSchedule {
@ -186,11 +186,11 @@ bool BundleManagerInternal::IsSameAppId(const std::string& callerAppId, const st
}
bool BundleManagerInternal::IsSameDeveloperId(const std::string &callerDeveloperId,
const std::string &targetBundleName)
const std::string &targetBundleName)
{
if (targetBundleName.empty() || callerDeveloperId.empty()) {
HILOGE("targetBundleName:%{public}s or callerDeveloperId:%{public}s is empty",
targetBundleName.c_str(), GetAnonymStr(callerDeveloperId).c_str());
HILOGE("targetBundleName: %{public}s or callerDeveloperId: %{public}s is empty",
targetBundleName.c_str(), GetAnonymStr(callerDeveloperId).c_str());
return false;
}
@ -263,9 +263,16 @@ bool BundleManagerInternal::GetContinueBundle4Src(const std::string &srcBundleNa
HILOGE("get bundle manager failed");
return false;
}
bundleMgr->GetContinueBundleNames(srcBundleName, bundleNameList);
if (bundleNameList.empty()) {
HILOGW("No APP with specified bundle name(%{public}s) configured in continue Bundle ", srcBundleName.c_str());
int32_t activeAccountId = 0;
ErrCode ret = QueryOsAccount(activeAccountId);
if(ret != ERR_OK) {
HILOGE("get os account id failed");
return false;
}
ret = bundleMgr->GetContinueBundleNames(srcBundleName, bundleNameList);
if (ret != ERR_OK || bundleNameList.empty()) {
HILOGW("No APP with specified bundle name(%{public}s) configured in continue Bundle; ret: %{public}d", srcBundleName.c_str(), ret);
return false;
}
return true;

View File

@ -192,6 +192,7 @@ void DSchedContinue::SetEventData()
eventData_.destBundleName_ = dstContinueInfo.bundleName;
eventData_.destModuleName_ = dstContinueInfo.moduleName;
eventData_.destAbilityName_ = dstContinueInfo.abilityName;
eventData_.developerId_ = srcContinueInfo.developerId;
eventData_.dSchedEventType_ = DMS_CONTINUE;
eventData_.state_ = DMS_DSCHED_EVENT_START;
}
@ -768,7 +769,11 @@ bool DSchedContinue::MakeCallerInfo(std::shared_ptr<ContinueAbilityData> data, C
HILOGE("Get userId from active Os AccountIds fail, ret : %{public}d", ret);
return false;
}
bundleMgr->GetAppProvisionInfo(continueInfo_.sinkBundleName_, ids[0], appProvisionInfo);
uint32_t result = bundleMgr->GetAppProvisionInfo(continueInfo_.sinkBundleName_, ids[0], appProvisionInfo);
if(result != ERR_OK) {
HILOGE("get app provision info failed for bundle name:%{public}s", continueInfo_.sinkBundleName_.c_str());
return false;
}
callerInfo.callerDeveloperId = appProvisionInfo.developerId;
return true;
}
@ -807,10 +812,9 @@ int32_t DSchedContinue::ExecuteContinueSend(std::shared_ptr<ContinueAbilityData>
HILOGE("GetBundleNameListFromBms failed");
return INVALID_PARAMETERS_ERR;
}
AccountInfo accountInfo;
int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(continueInfo_.sinkDeviceId_, callerInfo,
accountInfo);
accountInfo);
if (ret != ERR_OK) {
HILOGE("GetAccountInfo failed");
return ret;

View File

@ -264,6 +264,8 @@ bool DSchedContinueManager::getFirstBundleName(DSchedContinueInfo &info, std::st
}
}
}
HILOGE("caon not get abilicy info or continue bundle names is empty for continue type:%{public}s",
info.continueType_.c_str());
return false;
}
@ -295,9 +297,10 @@ void DSchedContinueManager::CompleteBundleName(DSchedContinueInfo &info, int32_t
std::string bundleName = info.sinkBundleName_;
std::string deviceId = info.sinkDeviceId_;
if (getFirstBundleName(info, firstBundleNamme, bundleName, deviceId)) {
info.sourceBundleName_ = firstBundleNamme;
sourceBundleName = firstBundleNamme;
}
}
info.sourceBundleName_ = sourceBundleName;
}
}
@ -334,7 +337,7 @@ void DSchedContinueManager::HandleContinueMissionWithBundleName(DSchedContinueIn
}
WaitAllConnectDecision(direction, info, CONTINUE_TIMEOUT);
HILOGI("end, subType: %{public}d dirction: %{public}d, continue info: %{public}s",
subType, direction, info.toString().c_str());
subType, direction, info.toString().c_str());
}
void DSchedContinueManager::WaitAllConnectDecision(int32_t direction, const DSchedContinueInfo &info, int32_t timeout)
@ -427,7 +430,8 @@ void DSchedContinueManager::HandleStartContinuation(const OHOS::AAFwk::Want& wan
}
std::shared_ptr<DSchedContinue> DSchedContinueManager::GetDSchedContinueByWant(
const OHOS::AAFwk::Want &want, int32_t missionId) {
const OHOS::AAFwk::Want& want, int32_t missionId)
{
std::string srcDeviceId;
if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId)) {
DmsRadar::GetInstance().SaveDataDmsRemoteWant("GetDSchedContinueByWant", GET_LOCAL_DEVICE_ERR);
@ -438,7 +442,8 @@ std::shared_ptr<DSchedContinue> DSchedContinueManager::GetDSchedContinueByWant(
std::string bundleName = want.GetElement().GetBundleName();
auto info = DSchedContinueInfo(srcDeviceId, bundleName, dstDeviceId, bundleName, "");
HILOGI("continue info: %{public}s.", info.toString().c_str()); {
HILOGI("continue info: %{public}s.", info.toString().c_str());
{
std::lock_guard<std::mutex> continueLock(continueMutex_);
if (continues_.empty()) {
HILOGE("continue info doesn't match an existing continuation.");
@ -453,7 +458,7 @@ std::shared_ptr<DSchedContinue> DSchedContinueManager::GetDSchedContinueByWant(
}
}
HILOGE("missionId doesn't match the existing continuation, continueInfo: %{public}s.",
info.toString().c_str());
info.toString().c_str());
return nullptr;
}

View File

@ -69,7 +69,8 @@ int32_t DSchedContinueDataState::DoContinueDataTask(std::shared_ptr<DSchedContin
HILOGE("dContinue or event is null");
return INVALID_PARAMETERS_ERR;
}
auto syncContinueData = event->GetSharedObject<DSchedContinueDataCmd>();
std::shard_ptr<DSchedContinueDataCmd> syncContinueData = event->GetSharedObject<DSchedContinueDataCmd>();
syncContinueData->want_.SetBundle(syncContinueData->dstBundleName_);
int32_t ret = dContinue->ExecuteContinueData(syncContinueData);
if (ret != ERR_OK) {
HILOGE("DSchedContinueAbilityState ExecuteContinueSend failed, ret: %{public}d", ret);

View File

@ -281,6 +281,7 @@ int32_t DSchedContinuation::NotifyDSchedEventForOneCB(const sptr<IRemoteObject>
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destBundleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destModuleName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.destAbilityName_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, String, continueEvent_.developerId_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.dSchedEventType_, SEND_REQUEST_DEF_FAIL);
PARCEL_WRITE_HELPER_RET(data, Int32, continueEvent_.state_, SEND_REQUEST_DEF_FAIL);

View File

@ -338,14 +338,14 @@ bool DistributedSchedPermission::GetTargetAbility(const AAFwk::Want& want,
bool DistributedSchedPermission::isSameAppIdOrDeveloperId(const CallerInfo &callerInfo,
const AppExecFwk::AbilityInfo &targetAbility) const
{
HILOGI("check appId target bundle name: %{public}s, caller bundle name: %{public}s",
targetAbility.bundleName.c_str(), callerInfo.callerBundleName.c_str());
if (targetAbility.bundleName == callerInfo.callerBundleName &&
!BundleManagerInternal::IsSameAppId(callerInfo.callerAppId, targetAbility.bundleName)) {
HILOGE("the appId is different, check permission denied!");
BundleManagerInternal::IsSameAppId(callerInfo.callerAppId, targetAbility.bundleName)) {
return true;
}
if (targetAbility.bundleName != callerInfo.callerBundleName &&
!BundleManagerInternal::IsSameDeveloperId(callerInfo.callerDeveloperId, targetAbility.bundleName)) {
HILOGE("the DeveloperId is different, check permission denied!");
BundleManagerInternal::IsSameDeveloperId(callerInfo.callerDeveloperId, targetAbility.bundleName)) {
return true;
}
return false;
@ -360,7 +360,7 @@ int32_t DistributedSchedPermission::CheckGetCallerPermission(const AAFwk::Want&
return DMS_ACCOUNT_ACCESS_PERMISSION_DENIED;
}
// 2. check call with same appid
if (isSameAppIdOrDeveloperId(callerInfo, targetAbility)) {
if (!isSameAppIdOrDeveloperId(callerInfo, targetAbility)) {
return CALL_PERMISSION_DENIED;
}

View File

@ -23,6 +23,7 @@
#include "distributed_sched_utils.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "mock_form_mgr_service.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/dsched_sync_e2e.h"
@ -109,20 +110,19 @@ bool DmsBmStorage::SaveStorageDistributeInfo(const std::string &bundleName, bool
}
AppExecFwk::AppProvisionInfo appProvisionInfo;
std::vector<int32_t> ids;
ErrCode result = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (result != ERR_OK || ids.empty()) {
HILOGE("Get userId from active Os AccountIds fail, ret : %{public}d", result);
return false;
}
ret = bundleMgr->GetAppProvisionInfo(bundleName, ids[0], appProvisionInfo);
if (!ret) {
HILOGW("GetAppProvisioninfo (developerId) of %{public}s failed: %{public}d", bundleName.c_str(), ret);
DeleteStorageDistributeInfo(bundleName);
return false;
std::vector<AccountSA::OsAccountInfo> accounts;
uint32_t result = AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(accounts);
if(result == ERR_OK && !accounts.empty()) {
for(auto &account: accounts) {
result = bundleMgr->GetAppprovisionInfo(bundleName, account.GetLocalId(), appProvisionInfo);
if(result == ERR_OK && !appProvisionInfo.developerId.empty()) {
break;
}
}
}
ret = InnerSaveStorageDistributeInfo(ConvertToDistributedBundleInfo(bundleInfo, appProvisionInfo), localUdid);
ret = InnerSaveStorageDistributeInfo(
ConvertToDistributedBundleInfo(bundleInfo, appProvisionInfo), localUdid);
if (!ret) {
HILOGW("InnerSaveStorageDistributeInfo:%{public}s failed", bundleName.c_str());
return false;
@ -435,17 +435,20 @@ bool DmsBmStorage::GetDistributedBundleInfo(const std::string &networkId,
continue;
}
DmsBundleInfo distributedBundleInfoTmp;
bool parseResult = distributedBundleInfoTmp.FromJsonString(value);
if (parseResult && distributedBundleInfoTmp.bundleNameId == bundleNameId) {
if (distributedBundleInfoTmp.FromJsonString(value)
&& distributedBundleInfoTmp.bundleNameId == bundleNameId) {
distributeBundleInfo = distributedBundleInfoTmp;
reduRiskEntries.push_back(entry);
}
}
if (reduRiskEntries.size() != 1) {
if (reduRiskEntries.size() > 1) {
HILOGE("Redundant data needs to be deleted.");
DelReduData(networkId, reduRiskEntries);
return false;
}
if(remoteEntries.empty()) {
HILOGE("get distributedBundleInfo failed.")
}
HILOGI("end.");
return true;
}
@ -699,7 +702,7 @@ DmsBundleInfo DmsBmStorage::ConvertToDistributedBundleInfo(const AppExecFwk::Bun
dmsAbilityInfo.continueTypeId.push_back(pos++);
}
dmsAbilityInfo.moduleName = abilityInfo.moduleName;
dmsAbilityInfo.continueBundleName = abilityInfo.continueBundleName;
dmsAbilityInfo.continueBundleName = abilityInfo.continueBundleNames;
distributedBundleInfo.dmsAbilityInfos.push_back(dmsAbilityInfo);
}
return distributedBundleInfo;
@ -760,22 +763,26 @@ void DmsBmStorage::UpdateDistributedData()
HILOGI("bundleInfos size: %{public}zu", bundleInfos.size());
std::vector<std::string> bundleNames;
for (const auto &bundleInfo: bundleInfos) {
for (const auto &bundleInfo : bundleInfos) {
bundleNames.push_back(bundleInfo.name);
}
std::map<std::string, DmsBundleInfo> oldDistributedBundleInfos =
GetAllOldDistributionBundleInfo(bundleNames);
GetAllOldDistributionBundleInfo(bundleNames);
AppExecFwk::AppProvisionInfo appProvisionInfo;
std::vector<AccountSA::OsAccountInfo> accounts;
uint32_t result = AccountSA::OsAccountManager::QoeryAllCreatedOsAccounts(accounts);
std::vector<DmsBundleInfo> dmsBundleInfos;
std::vector<int32_t> ids;
ErrCode ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
HILOGE("Get userId from active Os AccountIds fail, ret : %{public}d", ret);
return;
}
for (const auto &bundleInfo: bundleInfos) {
AppExecFwk::AppProvisionInfo appProvisionInfo;
bundleMgr->GetAppProvisionInfo(bundleInfo.name, ids[0], appProvisionInfo);
for (const auto &bundleInfo : bundleInfos) {
if(result == ERR_OK && !accounts.empty()) {
for(auto &account : accounts) {
result = bundleMgr->GetAppProvisionInfo(bundleInfo.name, account.GetLocalId(), appProvisionInfo);
if(result == ERR_OK && !appProvisionInfo.developerId.empty()) {
break;
}
}
}
if (oldDistributedBundleInfos.find(bundleInfo.name) != oldDistributedBundleInfos.end()) {
int64_t updateTime = oldDistributedBundleInfos[bundleInfo.name].updateTime;
if (updateTime != bundleInfo.updateTime) {

View File

@ -266,6 +266,7 @@ bool DMSContinueRecvMgr::GetFinalBundleName(const std::string &senderNetworkId,
finalBundleName = bundleName;
return true;
}
HILOGE("continue type is empty and can not get local bundle info for bundle name: %{public}s", bundleName.c_str());
return false;
}
@ -296,28 +297,27 @@ bool DMSContinueRecvMgr::GetFinalBundleName(const std::string &senderNetworkId,
continue;
}
AppExecFwk::AppProvisionInfo appProvisionInfo;
if (bundleMgr->GetAppProvisionInfo(bundleNameItem, ids[0], appProvisionInfo)
if (bundleMgr->GetAppProvisionInfo(bundleNameItem, ids[0], appProvisionInfo) == ERR_OK
&& appProvisionInfo.developerId == distributedBundleInfo.developerId) {
finalBundleName = bundleNameItem;
return true;
}
}
}
HILOGE("continue type is not empty and can not get local bundle info and continue nundle for "
"bundle name: %{public}s", bundleName.c_str());
return false;
}
int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string &senderNetworkId,
uint16_t bundleNameId, uint8_t continueTypeId, const int32_t state,
const int32_t retry)
int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string& senderNetworkId,
uint16_t bundleNameId, uint8_t continueTypeId, const int32_t state, const int32_t retry)
{
HILOGI("DealOnBroadcastBusiness start, senderNetworkId: %{public}s, bundleNameId: %{public}u, state: %{public}d.",
GetAnonymStr(senderNetworkId).c_str(), bundleNameId, state);
GetAnonymStr(senderNetworkId).c_str(), bundleNameId, state);
DmsBundleInfo distributedBundleInfo;
bool result = DmsBmStorage::GetInstance()->GetDistributedBundleInfo(senderNetworkId, bundleNameId,
distributedBundleInfo);
if (!result) {
HILOGW("get bundleName failed, ret: %{public}d, try = %{public}d", result, retry);
if (!DmsBmStorage::GetInstance()->GetDistributedBundleInfo(senderNetworkId, bundleNameId,
distributedBundleInfo)) {
HILOGW("get distributedBundleInfo failed, try = %{public}d", retry);
return RetryPostBroadcast(senderNetworkId, bundleNameId, continueTypeId, state, retry);
}
@ -327,7 +327,7 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string &senderNet
return REMOTE_DEVICE_BIND_ABILITY_ERR;
}
HILOGI("get bundleName, bundleName: %{public}s", bundleName.c_str());
HILOGI("get distributedBundleInfo success, bundleName: %{public}s", bundleName.c_str());
std::string finalBundleName;
AppExecFwk::BundleInfo localBundleInfo;
std::string continueType;
@ -336,6 +336,7 @@ int32_t DMSContinueRecvMgr::DealOnBroadcastBusiness(const std::string &senderNet
HILOGE("The app is not installed on the local device.");
return INVALID_PARAMETERS_ERR;
}
HILOGI("got finalBundleName: %{public}s", finalBundleName.c_str());
currentIconInfo lastRecvInfo = currentIconInfo(senderNetworkId, bundleName, finalBundleName);
pushLatRecvCache(lastRecvInfo);
@ -366,14 +367,14 @@ bool DMSContinueRecvMgr::continueTypeCheck(const DmsBundleInfo &distributedBundl
const std::string &continueType)
{
std::vector<DmsAbilityInfo> dmsAbilityInfos = distributedBundleInfo.dmsAbilityInfos;
bool continueTyoeGot = false;
bool continueTypeGot = false;
for (const auto &abilityInfo: dmsAbilityInfos) {
std::vector<std::string> continueTypeConfig = abilityInfo.continueType;
for (const auto &continueTypeConfigItem: continueTypeConfig) {
continueTyoeGot = continueTyoeGot || (continueType == continueTypeConfigItem);
continueTypeGot = continueTypeGot || (continueType == continueTypeConfigItem);
}
}
return continueTyoeGot;
return continueTypeGot;
}
void DMSContinueRecvMgr::pushLatRecvCache(currentIconInfo &lastRecvInfo)