回退逻辑

Signed-off-by: lipengfei <lipengfei53@huawei.com>
This commit is contained in:
lipengfei 2024-01-14 12:52:32 +08:00
parent c8a0c571b2
commit f92dbf2c6d
9 changed files with 2 additions and 66 deletions

View File

@ -61,10 +61,7 @@ private:
#define BGTASK_PRINT_LOG(LEVEL, Level, fmt, ...) \
if (BackgroundTaskMgr::BgTaskMgrLogWrapper::JudgeLevel(BackgroundTaskMgr::BgTaskMgrLogLevel::LEVEL)) \
OHOS::HiviewDFX::HiLog::Level(BackgroundTaskMgr::BGTASK_MGR_LABEL, \
"[%{public}s(%{public}s):%{public}d] " fmt, \
OHOS::BackgroundTaskMgr::BgTaskMgrLogWrapper::GetBriefFileName(__FILE__).c_str(), \
__FUNCTION__, \
__LINE__, \
fmt, \
##__VA_ARGS__)
#define BGTASK_LOGD(fmt, ...) BGTASK_PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__)

View File

@ -76,7 +76,6 @@ public:
int32_t GetBgTaskUid();
void StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType);
void OnConfigurationChanged(const AppExecFwk::Configuration &configuration);
bool IsReady();
private:
ErrCode StartBackgroundRunningInner(std::shared_ptr<ContinuousTaskRecord> &continuousTaskRecordPtr);

View File

@ -115,11 +115,6 @@ bool BgContinuousTaskMgr::Init(const std::shared_ptr<AppExecFwk::EventRunner>& r
return true;
}
bool BgContinuousTaskMgr::IsReady()
{
return isSysReady_.load();
}
void BgContinuousTaskMgr::Clear()
{
#ifdef DISTRIBUTED_NOTIFICATION_ENABLE

View File

@ -81,12 +81,10 @@ private:
bool CheckCallingToken();
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
void PublishIfReady();
private:
ServiceRunningState state_ {ServiceRunningState::STATE_NOT_START};
std::shared_ptr<AppExecFwk::EventRunner> runner_ {nullptr};
std::shared_ptr<AppExecFwk::EventHandler> handler_ {nullptr};
};
} // namespace BackgroundTaskMgr
} // namespace OHOS

View File

@ -34,7 +34,6 @@ namespace OHOS {
namespace BackgroundTaskMgr {
namespace {
static constexpr int32_t NO_DUMP_PARAM_NUMS = 0;
const int32_t DELAY_TIME = 2000;
const int32_t ENG_MODE = OHOS::system::GetIntParameter("const.debuggable", 0);
const std::string BGTASK_SERVICE_NAME = "BgtaskMgrService";
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
@ -55,28 +54,6 @@ void BackgroundTaskMgrService::OnStart()
Init();
AddSystemAbilityListener(APP_MGR_SERVICE_ID);
AddSystemAbilityListener(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
PublishIfReady();
}
void BackgroundTaskMgrService::PublishIfReady()
{
if (!DelayedSingleton<BgEfficiencyResourcesMgr>::GetInstance()->IsReady() ||
!DelayedSingleton<BgTransientTaskMgr>::GetInstance()->IsReady() ||
!BgContinuousTaskMgr::GetInstance()->IsReady()) {
BGTASK_LOGE("inner service is not ready");
auto task = [weak = weak_from_this()]() {
auto self = weak.lock();
if (!self) {
BGTASK_LOGE("weak.lock return null");
return;
}
self->PublishIfReady();
};
if (handler_) {
handler_->PostTask(task, DELAY_TIME);
}
return;
}
if (!Publish(DelayedSingleton<BackgroundTaskMgrService>::GetInstance().get())) {
BGTASK_LOGE("Service start failed!");
return;
@ -98,11 +75,6 @@ void BackgroundTaskMgrService::OnRemoveSystemAbility(int32_t systemAbilityId, co
void BackgroundTaskMgrService::Init()
{
runner_ = AppExecFwk::EventRunner::Create(BGTASK_SERVICE_NAME);
handler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner_);
if (handler_ == nullptr) {
BGTASK_LOGE("BackgroundTaskMgrService handler create failed!");
return;
}
DelayedSingleton<BgTransientTaskMgr>::GetInstance()->Init(runner_);
DelayedSingleton<BgEfficiencyResourcesMgr>::GetInstance()->Init(runner_);
BgContinuousTaskMgr::GetInstance()->Init(runner_);
@ -184,11 +156,6 @@ ErrCode BackgroundTaskMgrService::GetContinuousTaskApps(std::vector<std::shared_
ErrCode BackgroundTaskMgrService::SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber)
{
if (state_ != ServiceRunningState::STATE_RUNNING) {
BGTASK_LOGE("service is not publish");
return ERR_BGTASK_SYS_NOT_READY;
}
if (!CheckCallingToken()) {
BGTASK_LOGW("SubscribeBackgroundTask not allowed");
return ERR_BGTASK_PERMISSION_DENIED;
@ -206,10 +173,6 @@ ErrCode BackgroundTaskMgrService::SubscribeBackgroundTask(const sptr<IBackground
ErrCode BackgroundTaskMgrService::UnsubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber)
{
if (state_ != ServiceRunningState::STATE_RUNNING) {
BGTASK_LOGE("service is not publish");
return ERR_BGTASK_SYS_NOT_READY;
}
if (!CheckCallingToken()) {
BGTASK_LOGW("UnsubscribeBackgroundTask not allowed");
return ERR_BGTASK_PERMISSION_DENIED;

View File

@ -60,7 +60,6 @@ public:
ErrCode RemoveAppRecord(int32_t uid, const std::string &bundleName, bool resetAll);
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId);
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId);
bool IsReady();
private:
void ApplyEfficiencyResourcesInner(std::shared_ptr<ResourceCallbackInfo> callbackInfo,

View File

@ -128,11 +128,6 @@ void BgEfficiencyResourcesMgr::OnRemoveSystemAbility(int32_t systemAbilityId, co
}
}
bool BgEfficiencyResourcesMgr::IsReady()
{
return isSysReady_.load();
}
__attribute__((no_sanitize("cfi"))) void BgEfficiencyResourcesMgr::RegisterAppStateObserver()
{
appStateObserver_ = DelayedSingleton<AppStateObserver>::GetInstance();
@ -732,7 +727,7 @@ bool BgEfficiencyResourcesMgr::RemoveTargetResourceRecord(std::unordered_map<int
auto callbackInfo = std::make_shared<ResourceCallbackInfo>(iter->second->GetUid(),
iter->second->GetPid(), eraseBit, iter->second->GetBundleName());
BGTASK_LOGI("remove record from info map, mapkey %{public}d, uid: %{public}d, bundle name: %{public}s"
" erasebit %{public}d", mapKey, callbackInfo->GetUid(), callbackInfo->GetBundleName().c_str(), eraseBit);
"erasebit %{public}d", mapKey, callbackInfo->GetUid(), callbackInfo->GetBundleName().c_str(), eraseBit);
subscriberMgr_->OnResourceChanged(callbackInfo, type);
if (iter->second->resourceNumber_ == 0) {
infoMap.erase(iter);
@ -758,10 +753,6 @@ void BgEfficiencyResourcesMgr::RemoveListRecord(std::list<PersistTime> &resource
ErrCode BgEfficiencyResourcesMgr::GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<
ResourceCallbackInfo>> &appList, std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList)
{
if (!isSysReady_.load()) {
BGTASK_LOGW("Efficiency resources manager is not ready, GetEfficiencyResourcesInfos failed");
return ERR_BGTASK_SYS_NOT_READY;
}
handler_->PostSyncTask([this, &appList, &procList]() {
this->GetEfficiencyResourcesInfosInner(appResourceApplyMap_, appList);
this->GetEfficiencyResourcesInfosInner(procResourceApplyMap_, procList);

View File

@ -71,7 +71,6 @@ public:
void HandleRequestExpired(const int32_t requestId);
void HandleTransientTaskSuscriberTask(const shared_ptr<TransientTaskAppInfo>& appInfo,
const TransientTaskEventType type);
bool IsReady();
private:
ErrCode IsCallingInfoLegal(int32_t uid, int32_t pid, std::string &name,

View File

@ -70,11 +70,6 @@ void BgTransientTaskMgr::Init(const std::shared_ptr<AppExecFwk::EventRunner>& ru
InitNecessaryState(runner);
}
bool BgTransientTaskMgr::IsReady()
{
return isReady_.load();
}
void BgTransientTaskMgr::InitNecessaryState(const std::shared_ptr<AppExecFwk::EventRunner>& runner)
{
sptr<ISystemAbilityManager> systemAbilityManager