mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-22 22:09:58 +00:00
添加开机启动dms进程,创建数据库后退出的功能
Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
parent
9e52983fb3
commit
12d62fa5ab
@ -14,6 +14,11 @@
|
||||
"name": "deviceonline",
|
||||
"value": "on"
|
||||
}
|
||||
],
|
||||
"commonevent":[
|
||||
{
|
||||
"name":"usual.event.BOOT_COMPLETED"
|
||||
}
|
||||
]
|
||||
},
|
||||
"stop-on-demand": {
|
||||
|
@ -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<std::u16string>& args) override;
|
||||
void DeviceOnlineNotify(const std::string& deviceId);
|
||||
void DeviceOfflineNotify(const std::string& deviceId);
|
||||
|
@ -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<DistributedHardware::DmDeviceInfo> 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<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> argsInStr8;
|
||||
|
@ -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<Entry> 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;
|
||||
|
@ -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<DmsBundleInfo> dmsBundleInfos;
|
||||
dmsBmStorage_->GetInstance()->UpdatePublicRecords("");
|
||||
}
|
||||
DTEST_LOG << "DistributedBmStorageTest UpdatePublicRecordsTest_001 end" << std::endl;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user