Signed-off-by: wangdongdong <wangdongdong14@huawei.com>

Change-Id: Ia2ed82b7fd6da7cbe9de8a6938d6412c40d4e288

Signed-off-by: wangdongdong <wangdongdong14@huawei.com>
Change-Id: I5a82a8a962cbe8d9d7e542d66e62210a75c61a55
Signed-off-by: wangdongdong <wangdongdong14@huawei.com>
This commit is contained in:
wangdongdong 2022-04-20 14:40:14 +08:00
parent 04994fcd65
commit e13f8a89d3
5 changed files with 128 additions and 21 deletions

View File

@ -34,6 +34,9 @@ public:
static bool GetBundleNameListFromBms(int32_t callingUid, std::vector<std::u16string>& u16BundleNameList);
static bool QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo);
static bool IsSameAppId(const std::string& callerAppId, const std::string& targetBundleName);
static int32_t GetLocalBundleInfo(const std::string& bundleName, AppExecFwk::BundleInfo &localBundleInfo);
static int32_t CheckRemoteBundleInfoForContinuation(const std::string& dstDeviceId,
const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo);
static sptr<AppExecFwk::IBundleMgr> GetBundleManager();
};
} // namespace DistributedSchedule

View File

@ -152,11 +152,12 @@ private:
int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want,
const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo);
sptr<IRemoteObject> GetAbilityManagerProxy();
int32_t ContinueToAbilityManager(const std::string& deviceId, int32_t missionId);
int32_t NotifyResultToAbilityManager(int32_t missionId, int32_t isSuccess);
int32_t StartToContinueAbility(const std::string& deviceId, int32_t missionId, uint32_t versionCode);
int32_t StartToNotifyResult(int32_t missionId, int32_t isSuccess);
int32_t CleanMission(int32_t missionId);
int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId);
int32_t ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback);
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
int32_t ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
int32_t TryStartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,

View File

@ -345,6 +345,18 @@ enum {
* Result(29360201) for continue get content failed.
*/
CALL_PERMISSION_DENIED = 29360201,
/*
* Result(29360202) for continue remote not install and support free install.
*/
CONTINUE_REMOTE_UNINSTALLED_SUPPORT_FREEINSTALL = 29360202,
/*
* Result(29360203) for continue remote not install and not support free install.
*/
CONTINUE_REMOTE_UNINSTALLED_UNSUPPORT_FREEINSTALL = 29360203,
/*
* Result(29360204) for continue remote version not match.
*/
CONTINUE_REMOTE_VERSION_MISMATCH = 29360204,
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -128,6 +128,62 @@ bool BundleManagerInternal::IsSameAppId(const std::string& callerAppId, const st
return callerAppId == calleeAppId;
}
int32_t BundleManagerInternal::GetLocalBundleInfo(const std::string& bundleName,
AppExecFwk::BundleInfo &localBundleInfo)
{
auto bms = GetBundleManager();
if (bms == nullptr) {
HILOGE("get bundle manager failed");
return INVALID_PARAMETERS_ERR;
}
std::vector<int> ids;
ErrCode ret = OsAccountManager::QueryActiveOsAccountIds(ids);
if (ret != ERR_OK || ids.empty()) {
HILOGE("QueryActiveOsAccountIds failed");
return INVALID_PARAMETERS_ERR;
}
if (!bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT,
localBundleInfo, ids[0])) {
HILOGE("get local bundle info failed");
return INVALID_PARAMETERS_ERR;
}
return ERR_OK;
}
int32_t BundleManagerInternal::CheckRemoteBundleInfoForContinuation(const std::string& dstDeviceId,
const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo)
{
if (bundleName.empty()) {
HILOGE("bundle name empty");
return INVALID_PARAMETERS_ERR;
}
HILOGI("bundleName: %{public}s", bundleName.c_str());
auto bms = GetBundleManager();
if (bms == nullptr) {
HILOGE("get bundle manager failed");
return INVALID_PARAMETERS_ERR;
}
bool isInstalled = bms->GetDistributedBundleInfo(dstDeviceId, bundleName, remoteBundleInfo);
if (isInstalled) {
return ERR_OK;
}
AppExecFwk::BundleInfo localBundleInfo;
if (GetLocalBundleInfo(bundleName, localBundleInfo) != ERR_OK) {
HILOGE("get local bundle info failed");
return INVALID_PARAMETERS_ERR;
}
if (localBundleInfo.entryInstallationFree) {
HILOGE("remote not installed and support free install");
return CONTINUE_REMOTE_UNINSTALLED_SUPPORT_FREEINSTALL;
}
HILOGE("remote not installed and not support free install");
return CONTINUE_REMOTE_UNINSTALLED_UNSUPPORT_FREEINSTALL;
}
sptr<AppExecFwk::IBundleMgr> BundleManagerInternal::GetBundleManager()
{
sptr<ISystemAbilityManager> samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();

View File

@ -52,6 +52,8 @@ namespace {
const std::string TAG = "DistributedSchedService";
const std::u16string CONNECTION_CALLBACK_INTERFACE_TOKEN = u"ohos.abilityshell.DistributedConnection";
const std::u16string ABILITY_MANAGER_SERVICE_TOKEN = u"ohos.aafwk.AbilityManager";
const std::string BUNDLE_NAME_KEY = "bundleName";
const std::string VERSION_CODE_KEY = "version";
constexpr int32_t ABILITY_MANAGER_CONTINUE_ABILITY = 1104;
constexpr int32_t ABILITY_MANAGER_NOTIFY_CONTINUATION_RESULT = 1102;
constexpr int32_t ABILITY_MANAGER_CLEAN_MISSION = 45;
@ -188,7 +190,8 @@ int32_t DistributedSchedService::StartAbilityFromRemote(const OHOS::AAFwk::Want&
return err;
}
int32_t DistributedSchedService::ContinueToAbilityManager(const std::string& deviceId, int32_t missionId)
int32_t DistributedSchedService::StartToContinueAbility(const std::string& deviceId,
int32_t missionId, uint32_t versionCode)
{
MessageParcel data;
MessageParcel reply;
@ -204,6 +207,10 @@ int32_t DistributedSchedService::ContinueToAbilityManager(const std::string& dev
HILOGE("missionId write failed.");
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteUint32(versionCode)) {
HILOGE("versionCode write failed.");
return INVALID_PARAMETERS_ERR;
}
sptr<IRemoteObject> abilityManager = GetAbilityManagerProxy();
if (abilityManager == nullptr) {
@ -219,7 +226,7 @@ int32_t DistributedSchedService::ContinueToAbilityManager(const std::string& dev
}
int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
const sptr<IRemoteObject>& callback)
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
{
if (dschedContinuation_ == nullptr) {
HILOGE("continuation object null!");
@ -230,7 +237,19 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
return INVALID_PARAMETERS_ERR;
}
dschedContinuation_->PushCallback(missionId, callback);
int32_t result = ContinueToAbilityManager(dstDeviceId, missionId);
OHOS::AAFwk::Want want;
want.SetParams(wantParams);
std::string bundleName = want.GetStringParam(BUNDLE_NAME_KEY);
DistributedBundleInfo remoteBundleInfo;
int32_t result = BundleManagerInternal::CheckRemoteBundleInfoForContinuation(dstDeviceId,
bundleName, remoteBundleInfo);
if (result != ERR_OK) {
return result;
}
uint32_t remoteBundleVersion = remoteBundleInfo.versionCode;
result = StartToContinueAbility(dstDeviceId, missionId, remoteBundleVersion);
HILOGI("ContinueLocalMission result: %{public}d!", result);
return result;
}
@ -262,7 +281,7 @@ int32_t DistributedSchedService::ContinueMission(const std::string& srcDeviceId,
}
if (srcDeviceId == localDevId) {
return ContinueLocalMission(dstDeviceId, missionId, callback);
return ContinueLocalMission(dstDeviceId, missionId, callback, wantParams);
} else if (dstDeviceId == localDevId) {
return ContinueRemoteMission(srcDeviceId, dstDeviceId, missionId, callback, wantParams);
} else {
@ -271,6 +290,26 @@ int32_t DistributedSchedService::ContinueMission(const std::string& srcDeviceId,
}
}
int32_t DistributedSchedService::SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId)
{
std::string devId;
if (!GetLocalDeviceId(devId)) {
HILOGE("StartContinuation get local deviceId failed!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
newWant.SetParam("sessionId", missionId);
newWant.SetParam("deviceId", devId);
BundleInfo localBundleInfo;
if (BundleManagerInternal::GetLocalBundleInfo(newWant.GetBundle(), localBundleInfo) != ERR_OK) {
HILOGE("get local bundle info failed");
return INVALID_PARAMETERS_ERR;
}
newWant.SetParam(VERSION_CODE_KEY, static_cast<int32_t>(localBundleInfo.versionCode));
HILOGD("local version = %{public}u!", localBundleInfo.versionCode);
return ERR_OK;
}
int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId,
int32_t callerUid, int32_t status, uint32_t accessToken)
{
@ -289,11 +328,6 @@ int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want
want.GetElement().GetDeviceID().c_str(),
want.GetElement().GetBundleName().c_str(),
want.GetElement().GetAbilityName().c_str());
std::string devId;
if (!GetLocalDeviceId(devId)) {
HILOGE("StartContinuation get local deviceId failed!");
return INVALID_REMOTE_PARAMETERS_ERR;
}
if (dschedContinuation_ == nullptr) {
HILOGE("StartContinuation continuation object null!");
@ -303,11 +337,12 @@ int32_t DistributedSchedService::StartContinuation(const OHOS::AAFwk::Want& want
dschedContinuation_->SetTimeOut(missionId);
}
int32_t sessionId = missionId;
AAFwk::Want newWant = want;
newWant.SetParam("sessionId", sessionId);
newWant.SetParam("deviceId", devId);
int32_t result = ERR_OK;
int result = SetWantForContinuation(newWant, missionId);
if (result != ERR_OK) {
HILOGE("set new want failed");
return result;
}
result = StartRemoteAbility(newWant, callerUid, 0, accessToken);
if (result != ERR_OK) {
HILOGE("continue ability failed, errorCode = %{public}d", result);
@ -366,7 +401,7 @@ sptr<IRemoteObject> DistributedSchedService::GetAbilityManagerProxy()
return abilityManagerProxy_;
}
int32_t DistributedSchedService::NotifyResultToAbilityManager(int32_t missionId, int32_t isSuccess)
int32_t DistributedSchedService::StartToNotifyResult(int32_t missionId, int32_t isSuccess)
{
MessageParcel data;
MessageParcel reply;
@ -375,11 +410,11 @@ int32_t DistributedSchedService::NotifyResultToAbilityManager(int32_t missionId,
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(missionId)) {
HILOGE("NotifyResultToAbilityManager missionId write failed.");
HILOGE("missionId write failed.");
return INVALID_PARAMETERS_ERR;
}
if (!data.WriteInt32(isSuccess)) {
HILOGE("NotifyResultToAbilityManager result write failed.");
HILOGE("result write failed.");
return INVALID_PARAMETERS_ERR;
}
@ -391,7 +426,7 @@ int32_t DistributedSchedService::NotifyResultToAbilityManager(int32_t missionId,
auto error = abilityManager->SendRequest(ABILITY_MANAGER_NOTIFY_CONTINUATION_RESULT,
data, reply, option);
if (error != NO_ERROR) {
HILOGE("NotifyResultToAbilityManager Send request error: %{public}d", error);
HILOGE("Send request error: %{public}d", error);
return INVALID_PARAMETERS_ERR;
}
return reply.ReadInt32();
@ -441,7 +476,7 @@ void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId
}
result = dschedContinuation_->NotifyMissionCenterResult(missionId, isSuccess);
} else {
result = NotifyResultToAbilityManager(missionId, isSuccess);
result = StartToNotifyResult(missionId, isSuccess);
dschedContinuation_->RemoveTimeOut(missionId);
}
HILOGD("NotifyContinuationCallbackResult result:%{public}d", result);