From 12d62fa5ab9aeb893870292578b0470172792c79 Mon Sep 17 00:00:00 2001 From: m30043719 Date: Thu, 4 Jul 2024 15:09:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E6=9C=BA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8dms=E8=BF=9B=E7=A8=8B=EF=BC=8C=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=90=8E=E9=80=80=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: m30043719 --- sa_profile/1401.json | 5 +++ .../include/distributed_sched_service.h | 6 ++- .../src/distributed_sched_service.cpp | 40 +++++++++++++++++-- .../src/mission/distributed_bm_storage.cpp | 4 +- .../mission/distributed_bm_storage_test.cpp | 17 ++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/sa_profile/1401.json b/sa_profile/1401.json index 65bc100d..86e5c361 100644 --- a/sa_profile/1401.json +++ b/sa_profile/1401.json @@ -14,6 +14,11 @@ "name": "deviceonline", "value": "on" } + ], + "commonevent":[ + { + "name":"usual.event.BOOT_COMPLETED" + } ] }, "stop-on-demand": { diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h index fde5c780..487fdcdb 100644 --- a/services/dtbschedmgr/include/distributed_sched_service.h +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -88,8 +88,10 @@ class DistributedSchedService : public SystemAbility, public DistributedSchedStu public: ~DistributedSchedService() = default; - void OnStart() override; - void OnStop() override; + void OnStart(const SystemAbilityOnDemandReason &startReason) override; + void OnStop(const SystemAbilityOnDemandReason &stopReason) override; + void OnActive(const SystemAbilityOnDemandReason &activeReason) override; + void HandleBootStart(const SystemAbilityOnDemandReason &startReason); int32_t Dump(int32_t fd, const std::vector& args) override; void DeviceOnlineNotify(const std::string& deviceId); void DeviceOfflineNotify(const std::string& deviceId); diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index 402a28bd..6b0927c1 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -82,6 +82,7 @@ using namespace AAFwk; using namespace AccountSA; using namespace AppExecFwk; using namespace Constants; +using namespace DistributedHardware; namespace { const std::string TAG = "DistributedSchedService"; @@ -110,6 +111,8 @@ const std::string DSCHED_EVENT_KEY = "IDSchedEventListener"; const std::string DMSDURATION_SAVETIME = "ohos.dschedule.SaveDataTime"; const std::string DMS_CONTINUE_SESSION_ID = "ohos.dms.continueSessionId"; const std::string DMS_PERSISTENT_ID = "ohos.dms.persistentId"; +const std::string PKG_NAME = "DBinderBus_Dms_" + std::to_string(getprocpid()); +const std::string BOOT_COMPLETED_EVENT = "usual.event.BOOT_COMPLETED"; constexpr int32_t DEFAULT_DMS_MISSION_ID = -1; constexpr int32_t DEFAULT_DMS_CONNECT_TOKEN = -1; constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3; @@ -144,8 +147,9 @@ DistributedSchedService::DistributedSchedService() : SystemAbility(DISTRIBUTED_S { } -void DistributedSchedService::OnStart() +void DistributedSchedService::OnStart(const SystemAbilityOnDemandReason &startReason) { + HILOGI("OnStart reason %{public}s, reasonId_:%{public}d", startReason.GetName().c_str(), startReason.GetId()); #ifdef DMS_SERVICE_DISABLE HILOGI("DMS service disabled, exiting."); _exit(0); @@ -181,11 +185,12 @@ void DistributedSchedService::OnStart() HILOGI("OnStart dms service success."); Publish(this); + HandleBootStart(startReason); } -void DistributedSchedService::OnStop() +void DistributedSchedService::OnStop(const SystemAbilityOnDemandReason &stopReason) { - HILOGI("OnStop dms service enter."); + HILOGI("OnStart reason %{public}s, reasonId_:%{public}d", stopReason.GetName().c_str(), stopReason.GetId()); #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER DMSContinueSendMgr::GetInstance().UnInit(); DMSContinueRecvMgr::GetInstance().UnInit(); @@ -198,6 +203,35 @@ void DistributedSchedService::OnStop() HILOGD("begin"); } +void DistributedSchedService::OnActive(const SystemAbilityOnDemandReason &activeReason) +{ + HILOGI("OnStart reason %{public}s, reasonId_:%{public}d", activeReason.GetName().c_str(), activeReason.GetId()); + OnStart(activeReason); +} + +void DistributedSchedService::HandleBootStart(const SystemAbilityOnDemandReason &startReason) +{ + std::vector dmDeviceInfoList; + int32_t errCode = DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", dmDeviceInfoList); + if (errCode != ERR_OK) { + HILOGE("Get device manager trusted device list fail, errCode %{public}d", errCode); + } + if (startReason.GetName() == BOOT_COMPLETED_EVENT && dmDeviceInfoList.empty()) { + HILOGI("UnloadSystemAbility dms"); + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + HILOGE("get samgr failed"); + return; + } + int32_t ret = samgrProxy->UnloadSystemAbility(DISTRIBUTED_SCHED_SA_ID); + if (ret != ERR_OK) { + HILOGE("remove system ability failed"); + return; + } + HILOGI("UnloadSystemAbility dms ok"); + } +} + int32_t DistributedSchedService::Dump(int32_t fd, const std::vector& args) { std::vector argsInStr8; diff --git a/services/dtbschedmgr/src/mission/distributed_bm_storage.cpp b/services/dtbschedmgr/src/mission/distributed_bm_storage.cpp index 0496d18a..c90a5068 100644 --- a/services/dtbschedmgr/src/mission/distributed_bm_storage.cpp +++ b/services/dtbschedmgr/src/mission/distributed_bm_storage.cpp @@ -357,7 +357,7 @@ bool DmsBmStorage::CheckSyncData(const std::string &networkId) HILOGE("can not get udid or uuid by networkId"); return false; } - HILOGE("uuid: %{public}s", GetAnonymStr(uuid).c_str()); + HILOGI("uuid: %{public}s", GetAnonymStr(uuid).c_str()); std::vector newEntries; Status status = kvStorePtr_->GetDeviceEntries(uuid, newEntries); if (newEntries.empty() || status != Status::SUCCESS) { @@ -529,7 +529,7 @@ bool DmsBmStorage::GetLastBundleNameId(uint16_t &bundleNameId) Value value; Status status = kvStorePtr_->Get(publicKey, value); if (status != Status::SUCCESS) { - HILOGE("This information not be found in the database,Get error: %{public}d", status); + HILOGW("This information not be found in the database, Get error: %{public}d", status); return false; } PublicRecordsInfo publicRecordsInfo; diff --git a/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp b/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp index b6c0c307..fb4d948c 100644 --- a/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/distributed_bm_storage_test.cpp @@ -367,5 +367,22 @@ HWTEST_F(DistributedBmStorageTest, DmsPutBatchTest_001, TestSize.Level1) } DTEST_LOG << "DistributedBmStorageTest DmsPutBatchTest_001 end" << std::endl; } + +/** + * @tc.name: UpdatePublicRecordsTest_001 + * @tc.desc: test delete DistributedBmStorage + * @tc.type: FUNC + */ +HWTEST_F(DistributedBmStorageTest, UpdatePublicRecordsTest_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedBmStorageTest UpdatePublicRecordsTest_001 start" << std::endl; + auto distributedDataStorage = GetDmsBmStorage(); + EXPECT_NE(distributedDataStorage, nullptr); + if (distributedDataStorage != nullptr) { + std::vector dmsBundleInfos; + dmsBmStorage_->GetInstance()->UpdatePublicRecords(""); + } + DTEST_LOG << "DistributedBmStorageTest UpdatePublicRecordsTest_001 end" << std::endl; +} } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file