diff --git a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h index 1e3e5839..3a76ba08 100644 --- a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h +++ b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h @@ -84,6 +84,7 @@ public: int32_t RegisterOffListener(const std::string& type, const sptr& obj); void NotifyDied(const sptr& obj); void NotifyDeviceOffline(const std::string& networkId); + void NotifyPackageRemoved(const std::string& sinkBundleName); void OnDeviceScreenOff(); void OnContinueSwitchOff(); std::string GetContinueType(const std::string& bundleName); diff --git a/services/dtbschedmgr/src/common_event_listener.cpp b/services/dtbschedmgr/src/common_event_listener.cpp index b69150b6..c8344a6a 100644 --- a/services/dtbschedmgr/src/common_event_listener.cpp +++ b/services/dtbschedmgr/src/common_event_listener.cpp @@ -81,8 +81,9 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventD DmsBmStorage::GetInstance()->SaveStorageDistributeInfo(want.GetElement().GetBundleName(), true); break; case PACKAGE_REMOVED : - HILOGI("PACKAGE_REMOVED"); + HILOGI("PACKAGE_REMOVED: %{public}s", want.GetElement().GetBundleName().c_str()); DmsBmStorage::GetInstance()->DeleteStorageDistributeInfo(want.GetElement().GetBundleName()); + DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(want.GetElement().GetBundleName()); break; default: HILOGW("OnReceiveEvent undefined action"); diff --git a/services/dtbschedmgr/src/continue/dsched_continue.cpp b/services/dtbschedmgr/src/continue/dsched_continue.cpp index 41de0a7e..3a777678 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue.cpp @@ -898,7 +898,7 @@ int32_t DSchedContinue::PackDataCmd(std::shared_ptr& cmd, int32_t DSchedContinue::CheckStartPermission(std::shared_ptr cmd) { if (cmd->srcBundleName_ == cmd->dstBundleName_) { - return DistributedSchedService::GetInstance().CheckTargetPermission4DiffBundle(cmd->want_, cmd->callerInfo_, + return DistributedSchedService::GetInstance().CheckTargetPermission(cmd->want_, cmd->callerInfo_, cmd->accountInfo_, START_PERMISSION, true); } else { if (!BundleManagerInternal::IsSameDeveloperId(cmd->dstBundleName_, cmd->srcDeveloperId_)) { diff --git a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp index 4022db22..5c4db5c5 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp @@ -575,6 +575,48 @@ void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId) HILOGI("NotifyDeviceOffline end"); } +void DMSContinueRecvMgr::NotifyPackageRemoved(const std::string& sinkBundleName) +{ + if (sinkBundleName.empty()) { + HILOGE("NotifyPackageRemoved sinkBundleName empty"); + return; + } + if (iconInfo_.bundleName != sinkBundleName) { + HILOGI("NotifyPackageRemoved current sinkBundleName: %{public}s; removed package: %{public}s.", + iconInfo_.bundleName.c_str(), sinkBundleName.c_str()); + return; + } + HILOGI("NotifyPackageRemoved begin. sinkBundleName: %{public}s.", sinkBundleName.c_str()); + std::string senderNetworkId; + std::string bundleName; + std::string continueType; + { + std::lock_guard currentIconLock(iconMutex_); + senderNetworkId = iconInfo_.senderNetworkId; + bundleName = iconInfo_.bundleName; + continueType = iconInfo_.continueType; + iconInfo_.senderNetworkId = ""; + iconInfo_.bundleName = ""; + iconInfo_.continueType = ""; + } + HILOGI("Saved iconInfo cleared, sinkBundleName: %{public}s.", bundleName.c_str()); + { + std::lock_guard registerOnListenerMapLock(eventMutex_); + auto iterItem = registerOnListener_.find(onType_); + if (iterItem == registerOnListener_.end()) { + HILOGI("Get iterItem failed from registerOnListener_, nobody registed"); + return; + } + std::vector> objs = iterItem->second; + for (auto iter : objs) { + NotifyRecvBroadcast(iter, + currentIconInfo(senderNetworkId, iconInfo_.sourceBundleName, bundleName, continueType), + INACTIVE); + } + } + HILOGI("NotifyPackageRemoved end"); +} + std::string DMSContinueRecvMgr::GetContinueType(const std::string& bundleName) { std::lock_guard currentIconLock(iconMutex_); diff --git a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp index 1d0a71e3..2634b779 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -686,6 +686,55 @@ HWTEST_F(DMSContinueManagerTest, testNotifyDeviceOffline003, TestSize.Level1) DTEST_LOG << "DMSContinueManagerTest testNotifyDeviceOffline003 end" << std::endl; } +/** + * @tc.name: NotifyPackageRemoved001 + * @tc.desc: test NotifyPackageRemoved normal + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved001, TestSize.Level1) +{ + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 start" << std::endl; + sptr obj01(new RemoteOnListenerStubTest()); + DMSContinueRecvMgr::GetInstance().RegisterOnListener(TYPE, obj01); + EXPECT_NE(DMSContinueRecvMgr::GetInstance().registerOnListener_.size(), 0); + + DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01; + DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(BUNDLENAME_01); + EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, ""); + + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved001 end" << std::endl; +} + +/** + * @tc.name: NotifyPackageRemoved002 + * @tc.desc: test NotifyPackageRemoved bundleName empty + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved002, TestSize.Level1) +{ + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 start" << std::endl; + DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01; + DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(""); + EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, BUNDLENAME_01); + + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved002 end" << std::endl; +} + +/** + * @tc.name: NotifyPackageRemoved003 + * @tc.desc: test NotifyPackageRemoved bundleName not match + * @tc.type: FUNC + */ +HWTEST_F(DMSContinueManagerTest, notifyPackageRemoved003, TestSize.Level1) +{ + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 start" << std::endl; + DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName = BUNDLENAME_01; + DMSContinueRecvMgr::GetInstance().NotifyPackageRemoved(BUNDLENAME_02); + EXPECT_EQ(DMSContinueRecvMgr::GetInstance().iconInfo_.bundleName, BUNDLENAME_01); + + DTEST_LOG << "DMSContinueManagerTest notifyPackageRemoved003 end" << std::endl; +} + /** * @tc.name: testNotifyDataRecv001 * @tc.desc: NotifyDataRecv