代码优化

Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
m30043719 2024-10-30 10:13:32 +08:00
parent a3d63c4683
commit 57f1e8a4cd
3 changed files with 42 additions and 29 deletions

View File

@ -99,6 +99,7 @@ public:
* @param startReason, The reason why SA was pulled up.
*/
void HandleBootStart(const SystemAbilityOnDemandReason &startReason);
bool DoStart();
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);

View File

@ -154,31 +154,10 @@ DistributedSchedService::DistributedSchedService() : SystemAbility(DISTRIBUTED_S
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);
#endif
HILOGI("Dms service OnStart enter.");
if (!Init()) {
HILOGE("failed to init DistributedSchedService");
if (!DoStart()) {
HILOGI("OnStart dms service failed.");
return;
}
FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
HILOGW("continuationCallback timeout.");
NotifyContinuationCallbackResult(missionId, CONTINUE_ABILITY_TIMEOUT_ERR);
};
DmsCallbackTaskInitCallbackFunc freeCallback = [this] (int64_t taskId) {
HILOGW("DmsCallbackTaskInitCallbackFunc timeout, taskId:%{public}" PRId64 ".", taskId);
NotifyCompleteFreeInstallFromRemote(taskId, AAFwk::FREE_INSTALL_TIMEOUT);
};
dschedContinuation_ = std::make_shared<DSchedContinuation>();
collaborateCbMgr_ = std::make_shared<DSchedCollaborationCallbackMgr>();
dmsCallbackTask_ = std::make_shared<DmsCallbackTask>();
dschedContinuation_->Init(continuationCallback);
collaborateCbMgr_->Init();
dmsCallbackTask_->Init(freeCallback);
HILOGI("OnStart dms service success.");
Publish(this);
HandleBootStart(startReason);
}
@ -198,7 +177,7 @@ void DistributedSchedService::OnStop(const SystemAbilityOnDemandReason &stopReas
void DistributedSchedService::OnActive(const SystemAbilityOnDemandReason &activeReason)
{
HILOGI("OnStart reason %{public}s, reasonId_:%{public}d", activeReason.GetName().c_str(), activeReason.GetId());
OnStart(activeReason);
DoStart();
}
void DistributedSchedService::HandleBootStart(const SystemAbilityOnDemandReason &startReason)
@ -224,6 +203,44 @@ void DistributedSchedService::HandleBootStart(const SystemAbilityOnDemandReason
}
}
bool DistributedSchedService::DoStart()
{
#ifdef DMS_SERVICE_DISABLE
HILOGI("DMS service disabled, exiting.");
_exit(0);
#endif
HILOGI("Dms service DoStart enter.");
if (!Init()) {
HILOGE("failed to init DistributedSchedService");
return false;
}
FuncContinuationCallback continuationCallback = [this] (int32_t missionId) {
HILOGW("continuationCallback timeout.");
NotifyContinuationCallbackResult(missionId, CONTINUE_ABILITY_TIMEOUT_ERR);
};
DmsCallbackTaskInitCallbackFunc freeCallback = [this] (int64_t taskId) {
HILOGW("DmsCallbackTaskInitCallbackFunc timeout, taskId:%{public}" PRId64 ".", taskId);
NotifyCompleteFreeInstallFromRemote(taskId, AAFwk::FREE_INSTALL_TIMEOUT);
};
dschedContinuation_ = std::make_shared<DSchedContinuation>();
collaborateCbMgr_ = std::make_shared<DSchedCollaborationCallbackMgr>();
dmsCallbackTask_ = std::make_shared<DmsCallbackTask>();
dschedContinuation_->Init(continuationCallback);
collaborateCbMgr_->Init();
dmsCallbackTask_->Init(freeCallback);
#ifdef DMSFWK_INTERACTIVE_ADAPTER
HILOGI("Get dms interactive adapter proxy enter.");
int32_t ret = GetDmsInteractiveAdapterProxy();
if (ret != ERR_OK) {
HILOGE("Get remote dms interactive adapter proxy fail, ret %{public}d.", ret);
}
#endif
HILOGI("OnStart dms service success.");
return true;
}
int32_t DistributedSchedService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::vector<std::string> argsInStr8;

View File

@ -34,11 +34,6 @@ void WifiStateListener::OnReceiveEvent(const EventFwk::CommonEventData &data)
switch (data.GetCode()) {
case int32_t(OHOS::Wifi::WifiState::DISABLED): {
HILOGI("on wifi disabled");
if (CheckWifiStateIsActived()) {
WifiStateAdapter::GetInstance().UpdateWifiState(true);
HILOGI("WifiState is STATE_SEMIACTIVE");
return;
}
WifiStateAdapter::GetInstance().UpdateWifiState(false);
DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff();
break;