mirror of
https://github.com/openharmony/distributedschedule_samgr.git
synced 2026-07-20 22:47:20 -04:00
Signed-off-by: wangdongdong <wangdongdong14@huawei.com>
Change-Id: I481989778026799be2da473faf2170b55bf35e5a
This commit is contained in:
@@ -38,7 +38,7 @@ public:
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(DmsBundleManagerCallbackStub);
|
||||
int32_t OnQueryInstallationFinishedInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t OnQueryInstallationFinished(int32_t resultCode, std::string deviceId, int32_t missionId, int versionCode);
|
||||
int32_t OnQueryInstallationFinished(int32_t resultCode, int32_t missionId, int versionCode);
|
||||
using DmsBundleManagerCallbackFunc = int32_t (DmsBundleManagerCallbackStub::*)(
|
||||
MessageParcel& data, MessageParcel& reply);
|
||||
std::map<uint32_t, DmsBundleManagerCallbackFunc> memberFuncMap_;
|
||||
|
||||
@@ -37,10 +37,12 @@ public:
|
||||
bool IsInContinuationProgress(int32_t missionId);
|
||||
void SetTimeOut(int32_t missionId, int32_t timeout);
|
||||
void RemoveTimeOut(int32_t missionId);
|
||||
bool PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback, bool isFreeInstall = false);
|
||||
bool PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback,
|
||||
std::string deviceId, bool isFreeInstall);
|
||||
sptr<IRemoteObject> PopCallback(int32_t missionId);
|
||||
int32_t NotifyMissionCenterResult(int32_t missionId, int32_t isSuccess);
|
||||
bool IsFreeInstall(int32_t missionId);
|
||||
std::string GetTargetDevice(int32_t missionId);
|
||||
|
||||
private:
|
||||
class ContinuationHandler : public AppExecFwk::EventHandler {
|
||||
@@ -63,6 +65,7 @@ private:
|
||||
std::map<int32_t, sptr<IRemoteObject>> continuationMap_;
|
||||
std::map<int32_t, sptr<IRemoteObject>> callbackMap_;
|
||||
std::map<int32_t, bool> freeInstall_;
|
||||
std::map<int32_t, std::string> continuationDevices_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -132,6 +132,7 @@ public:
|
||||
int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) override;
|
||||
void SetContinuationTimeout(int32_t missionId, int32_t timeout);
|
||||
void RemoveContinuationTimeout(int32_t missionId);
|
||||
std::string GetContinuaitonDevice(int32_t missionId);
|
||||
|
||||
int32_t ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
|
||||
|
||||
@@ -38,27 +38,27 @@ int32_t DmsBundleManagerCallbackStub::OnQueryInstallationFinishedInner(MessagePa
|
||||
{
|
||||
int32_t resultCode = data.ReadInt32();
|
||||
uint32_t versionCode = data.ReadUint32();
|
||||
std::string deviceId = data.ReadString();
|
||||
int32_t missionId = data.ReadInt32();
|
||||
|
||||
int32_t result = OnQueryInstallationFinished(resultCode, deviceId, missionId, versionCode);
|
||||
int32_t result = OnQueryInstallationFinished(resultCode, missionId, versionCode);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t DmsBundleManagerCallbackStub::OnQueryInstallationFinished(int32_t resultCode,
|
||||
std::string deviceId, int32_t missionId, int versionCode)
|
||||
int32_t missionId, int versionCode)
|
||||
{
|
||||
HILOGI("bms callback received, missionId: %{public}d", missionId);
|
||||
int32_t result = 0;
|
||||
if (resultCode != ERR_OK) {
|
||||
HILOGE("remote not installed and cannot install on remote device");
|
||||
HILOGE("remote not installed and cannot install on remote device, resultCode = %{public}d", resultCode);
|
||||
result = CONTINUE_REMOTE_UNINSTALLED_CANNOT_FREEINSTALL;
|
||||
DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
|
||||
|
||||
HILOGI("able to install on target device, start continue ability with freeInstall");
|
||||
std::string deviceId = DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
|
||||
DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, CONTINUATION_FREE_INSTALL_TIMEOUT);
|
||||
result = AAFwk::AbilityManagerClient::GetInstance()->ContinueAbility(deviceId, missionId, versionCode);
|
||||
return result;
|
||||
|
||||
@@ -241,8 +241,12 @@ bool BundleManagerInternal::CheckIfRemoteCanInstall(const AAFwk::Want& want, int
|
||||
|
||||
AAFwk::Want newWant;
|
||||
newWant.SetElementName(deviceId, bundleName, abilityName, moduleName);
|
||||
auto callback = new DmsBundleManagerCallbackStub();
|
||||
bool ret = bms->CheckAbilityEnableInstall(newWant, missionId, callback);
|
||||
std::vector<int> ids;
|
||||
ErrCode result = OsAccountManager::QueryActiveOsAccountIds(ids);
|
||||
if (result != ERR_OK || ids.empty()) {
|
||||
return false;
|
||||
}
|
||||
bool ret = bms->CheckAbilityEnableInstall(newWant, missionId, ids[0], new DmsBundleManagerCallbackStub());
|
||||
if (ret != true) {
|
||||
HILOGE("CheckAbilityEnableInstall from bms failed");
|
||||
}
|
||||
|
||||
@@ -139,26 +139,39 @@ bool DSchedContinuation::IsInContinuationProgress(int32_t missionId)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DSchedContinuation::PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback, bool isFreeInstall)
|
||||
std::string DSchedContinuation::GetTargetDevice(int32_t missionId)
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(continuationLock_);
|
||||
auto iter = continuationDevices_.find(missionId);
|
||||
if (iter != continuationDevices_.end()) {
|
||||
HILOGD("missionId:%{public}d exist!", missionId);
|
||||
return iter->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool DSchedContinuation::PushCallback(int32_t missionId, const sptr<IRemoteObject>& callback,
|
||||
std::string deviceId, bool isFreeInstall)
|
||||
{
|
||||
HILOGI("DSchedContinuation PushCallback start!");
|
||||
if (callback == nullptr) {
|
||||
HILOGE("PushCallback callback null!");
|
||||
HILOGE("callback null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (continuationHandler_ == nullptr) {
|
||||
HILOGE("PushCallback not initialized!");
|
||||
HILOGE("not initialized!");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> autoLock(continuationLock_);
|
||||
auto iterSession = callbackMap_.find(missionId);
|
||||
if (iterSession != callbackMap_.end()) {
|
||||
HILOGE("PushCallback missionId:%{public}d exist!", missionId);
|
||||
HILOGE("missionId:%{public}d exist!", missionId);
|
||||
return false;
|
||||
}
|
||||
(void)callbackMap_.emplace(missionId, callback);
|
||||
(void)continuationDevices_.emplace(missionId, deviceId);
|
||||
if (isFreeInstall) {
|
||||
freeInstall_[missionId] = isFreeInstall;
|
||||
}
|
||||
@@ -174,6 +187,13 @@ sptr<IRemoteObject> DSchedContinuation::PopCallback(int32_t missionId)
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> callback = iter->second;
|
||||
|
||||
auto iteration = continuationDevices_.find(missionId);
|
||||
if (iteration != continuationDevices_.end()) {
|
||||
HILOGD("%{public}d need pop from continuationDevices_", missionId);
|
||||
(void)continuationDevices_.erase(iteration);
|
||||
}
|
||||
|
||||
auto it = freeInstall_.find(missionId);
|
||||
if (it != freeInstall_.end()) {
|
||||
HILOGD("%{public}d need pop from freeInstall_", missionId);
|
||||
|
||||
@@ -81,7 +81,8 @@ constexpr int32_t DISTRIBUTED_COMPONENT_ADD = 1;
|
||||
constexpr int32_t DISTRIBUTED_COMPONENT_REMOVE = 2;
|
||||
constexpr int32_t REPORT_DISTRIBUTED_COMPONENT_CHANGE_CODE = 1;
|
||||
constexpr int64_t CONTINUATION_TIMEOUT = 20000; // 20s
|
||||
constexpr int64_t CHECK_REMOTE_INSTALL_ABILITY = 300000; // 30s
|
||||
// BundleDistributedManager set timeout to 3s, so we set 1s longer
|
||||
constexpr int64_t CHECK_REMOTE_INSTALL_ABILITY = 40000;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -284,6 +285,15 @@ void DistributedSchedService::SetContinuationTimeout(int32_t missionId, int32_t
|
||||
dschedContinuation_->SetTimeOut(missionId, timeout);
|
||||
}
|
||||
|
||||
std::string DistributedSchedService::GetContinuaitonDevice(int32_t missionId)
|
||||
{
|
||||
if (dschedContinuation_ == nullptr) {
|
||||
HILOGE("continuation object null!");
|
||||
return "";
|
||||
}
|
||||
return dschedContinuation_->GetTargetDevice(missionId);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
|
||||
const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams)
|
||||
{
|
||||
@@ -309,7 +319,7 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
|
||||
result = BundleManagerInternal::CheckRemoteBundleInfoForContinuation(dstDeviceId,
|
||||
bundleName, remoteBundleInfo);
|
||||
if (result == ERR_OK) {
|
||||
dschedContinuation_->PushCallback(missionId, callback, false);
|
||||
dschedContinuation_->PushCallback(missionId, callback, dstDeviceId, false);
|
||||
SetContinuationTimeout(missionId, CONTINUATION_TIMEOUT);
|
||||
uint32_t remoteBundleVersion = remoteBundleInfo.versionCode;
|
||||
result = AbilityManagerClient::GetInstance()->ContinueAbility(dstDeviceId, missionId, remoteBundleVersion);
|
||||
@@ -327,7 +337,7 @@ int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDevi
|
||||
return CONTINUE_REMOTE_UNINSTALLED_SUPPORT_FREEINSTALL;
|
||||
}
|
||||
|
||||
dschedContinuation_->PushCallback(missionId, callback, true);
|
||||
dschedContinuation_->PushCallback(missionId, callback, dstDeviceId, true);
|
||||
SetContinuationTimeout(missionId, CHECK_REMOTE_INSTALL_ABILITY);
|
||||
|
||||
missionInfo.want.SetDeviceId(dstDeviceId);
|
||||
|
||||
@@ -205,6 +205,26 @@ HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_007, TestSize.Leve
|
||||
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_007 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: BundleManagerInternalTest_008
|
||||
* @tc.desc: test CheckIfRemoteCanInstall with unexist bundle
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BundleManagerInternalTest, BundleManagerInternalTest_008, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_008 begin" << std::endl;
|
||||
string deviceId = "123456";
|
||||
string bundleName = "ohos.samples.testApp";
|
||||
string moduleName = "entry";
|
||||
string abilityName = "MainAbility";
|
||||
AAFwk::Want want;
|
||||
want.SetElementName(deviceId, bundleName, abilityName, moduleName);
|
||||
int32_t missionId = 0;
|
||||
bool ret = BundleManagerInternal::CheckIfRemoteCanInstall(want, missionId);
|
||||
EXPECT_TRUE(false == ret);
|
||||
DTEST_LOG << "BundleManagerInternalTest BundleManagerInternalTest_008 end "<< std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: BundleManagerCallBackTest_001
|
||||
* @tc.desc: test OnQueryInstallationFinished with failed result
|
||||
@@ -214,11 +234,10 @@ HWTEST_F(BundleManagerInternalTest, BundleManagerCallBackTest_001, TestSize.Leve
|
||||
{
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_001 begin" << std::endl;
|
||||
int32_t resultCode = -1;
|
||||
string deviceId = "123456";
|
||||
int32_t missionId = 0;
|
||||
int32_t versionCode = 10000;
|
||||
auto callback = new DmsBundleManagerCallbackStub();
|
||||
int32_t ret = callback->OnQueryInstallationFinished(resultCode, deviceId, missionId, versionCode);
|
||||
int32_t ret = callback->OnQueryInstallationFinished(resultCode, missionId, versionCode);
|
||||
EXPECT_TRUE(CONTINUE_REMOTE_UNINSTALLED_CANNOT_FREEINSTALL == ret);
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_001 end "<< std::endl;
|
||||
}
|
||||
@@ -232,11 +251,10 @@ HWTEST_F(BundleManagerInternalTest, BundleManagerCallBackTest_002, TestSize.Leve
|
||||
{
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_002 begin" << std::endl;
|
||||
int32_t resultCode = 0;
|
||||
string deviceId = "123456";
|
||||
int32_t missionId = 0;
|
||||
int32_t versionCode = 10000;
|
||||
auto callback = new DmsBundleManagerCallbackStub();
|
||||
int32_t ret = callback->OnQueryInstallationFinished(resultCode, deviceId, missionId, versionCode);
|
||||
int32_t ret = callback->OnQueryInstallationFinished(resultCode, missionId, versionCode);
|
||||
EXPECT_TRUE(ERR_OK != ret);
|
||||
DTEST_LOG << "BundleManagerCallBackTest BundleManagerCallBackTest_002 end "<< std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user