mirror of
https://gitee.com/openharmony/resourceschedule_background_task_mgr
synced 2024-11-23 15:00:03 +00:00
commit
55cd7c017c
@ -158,9 +158,10 @@ public:
|
||||
* @param uid app uid.
|
||||
* @param pid app pid.
|
||||
* @param taskType continuous task type.
|
||||
* @param key continuous task key.
|
||||
* @return Returns ERR_OK if success, else failure.
|
||||
*/
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType);
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key);
|
||||
|
||||
private:
|
||||
bool GetBackgroundTaskManagerProxy();
|
||||
|
@ -152,9 +152,10 @@ public:
|
||||
* @param uid app uid.
|
||||
* @param pid app pid.
|
||||
* @param taskType continuous task type.
|
||||
* @param key continuous task key.
|
||||
* @return Returns ERR_OK if success, else failure.
|
||||
*/
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType) override;
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key) override;
|
||||
|
||||
private:
|
||||
ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply);
|
||||
|
@ -159,9 +159,10 @@ public:
|
||||
* @param uid app uid.
|
||||
* @param pid app pid.
|
||||
* @param taskType continuous task type.
|
||||
* @param key continuous task key.
|
||||
* @return Returns ERR_OK if success, else failure.
|
||||
*/
|
||||
virtual ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType) = 0;
|
||||
virtual ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key) = 0;
|
||||
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IBackgroundTaskMgr");
|
||||
|
@ -233,12 +233,12 @@ ErrCode BackgroundTaskManager::GetContinuousTaskApps(std::vector<std::shared_ptr
|
||||
return proxy_->GetContinuousTaskApps(list);
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskManager::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
ErrCode BackgroundTaskManager::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN
|
||||
|
||||
return proxy_->StopContinuousTask(uid, pid, taskType);
|
||||
return proxy_->StopContinuousTask(uid, pid, taskType, key);
|
||||
}
|
||||
|
||||
void BackgroundTaskManager::ResetBackgroundTaskManagerProxy()
|
||||
|
@ -398,7 +398,7 @@ ErrCode BackgroundTaskMgrProxy::GetContinuousTaskApps(std::vector<std::shared_pt
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrProxy::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
ErrCode BackgroundTaskMgrProxy::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(BackgroundTaskMgrProxy::GetDescriptor())) {
|
||||
@ -420,6 +420,11 @@ ErrCode BackgroundTaskMgrProxy::StopContinuousTask(int32_t uid, int32_t pid, uin
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(key)) {
|
||||
BGTASK_LOGE("StopContinuousTask parcel key failed");
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_SYNC};
|
||||
|
||||
|
@ -379,7 +379,8 @@ ErrCode BackgroundTaskMgrStub::HandleStopContinuousTask(MessageParcel& data, Mes
|
||||
int32_t uid = data.ReadInt32();
|
||||
int32_t pid = data.ReadInt32();
|
||||
uint32_t taskType = data.ReadUint32();
|
||||
ErrCode result = StopContinuousTask(uid, pid, taskType);
|
||||
std::string key = data.ReadString();
|
||||
ErrCode result = StopContinuousTask(uid, pid, taskType, key);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
BGTASK_LOGE("HandleStopContinuousTask write result failed, ErrCode=%{public}d", result);
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
|
@ -378,23 +378,23 @@ HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_010
|
||||
BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr);
|
||||
|
||||
BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
|
||||
BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true);
|
||||
BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
|
||||
BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true);
|
||||
BgTaskFwkAbnormalSetWriteUint32Flag(false);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PARCELABLE_FAILED);
|
||||
|
||||
BgTaskFwkAbnormalSetWriteUint32Flag(true);
|
||||
BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_TRANSACT_FAILED);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_TRANSACT_FAILED);
|
||||
|
||||
BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1);
|
||||
BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1), ERR_BGTASK_TRANSACT_FAILED);
|
||||
EXPECT_EQ(backgroundTaskMgrProxy.StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_TRANSACT_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,12 +221,6 @@ HWTEST_F(BgTaskFrameworkUnitTest, BgTaskFrameworkUnitTest_006, TestSize.Level1)
|
||||
ERR_BGTASK_SERVICE_NOT_CONNECTED);
|
||||
|
||||
SystemAbilityManagerClient::GetInstance().action_ = "";
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->SubscribeBackgroundTask(taskSubscriber),
|
||||
ERR_BGTASK_PARCELABLE_FAILED);
|
||||
SleepForFC();
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->UnsubscribeBackgroundTask(taskSubscriber),
|
||||
ERR_BGTASK_PARCELABLE_FAILED);
|
||||
SleepForFC();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,11 +331,11 @@ HWTEST_F(BgTaskFrameworkUnitTest, BgTaskFrameworkUnitTest_012, TestSize.Level1)
|
||||
DelayedSingleton<BackgroundTaskManager>::GetInstance()->proxy_ = nullptr;
|
||||
|
||||
SystemAbilityManagerClient::GetInstance().action_ = "set_null";
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(1, 1, 1),
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(1, 1, 1, ""),
|
||||
ERR_BGTASK_SERVICE_NOT_CONNECTED);
|
||||
|
||||
SystemAbilityManagerClient::GetInstance().action_ = "";
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(1, 1, 1), ERR_OK);
|
||||
EXPECT_EQ(DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(1, 1, 1, ""), ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +119,7 @@ public:
|
||||
* @param taskType continuous task type.
|
||||
* @return Returns ERR_OK if success, else failure.
|
||||
*/
|
||||
static ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType);
|
||||
static ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key);
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
||||
|
@ -81,9 +81,9 @@ ErrCode BackgroundTaskMgrHelper::ResetAllEfficiencyResources()
|
||||
return DelayedSingleton<BackgroundTaskManager>::GetInstance()->ResetAllEfficiencyResources();
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrHelper::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
ErrCode BackgroundTaskMgrHelper::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key)
|
||||
{
|
||||
return DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(uid, pid, taskType);
|
||||
return DelayedSingleton<BackgroundTaskManager>::GetInstance()->StopContinuousTask(uid, pid, taskType, key);
|
||||
}
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
@ -328,7 +328,7 @@ HWTEST_F(BgTaskClientUnitTest, ResetAllEfficiencyResources_001, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(BgTaskClientUnitTest, StopContinuousTask_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ((int32_t)BackgroundTaskMgrHelper::StopContinuousTask(1, 1, 1), (int32_t)ERR_OK);
|
||||
EXPECT_EQ((int32_t)BackgroundTaskMgrHelper::StopContinuousTask(1, 1, 1, ""), (int32_t)ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
void InitRequiredResourceInfo();
|
||||
void Clear();
|
||||
int32_t GetBgTaskUid();
|
||||
void StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType);
|
||||
void StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key);
|
||||
void OnConfigurationChanged(const AppExecFwk::Configuration &configuration);
|
||||
|
||||
private:
|
||||
@ -107,8 +107,7 @@ private:
|
||||
bool RegisterConfigurationObserver();
|
||||
bool GetNotificationPrompt();
|
||||
bool SetCachedBundleInfo(int32_t uid, int32_t userId, const std::string &bundleName, const std::string &appName);
|
||||
void HandleStopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType);
|
||||
void RemoveSpecifiedBgTask(uint32_t taskType);
|
||||
void HandleStopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key);
|
||||
void OnRemoteSubscriberDiedInner(const wptr<IRemoteObject> &object);
|
||||
void OnContinuousTaskChanged(const std::shared_ptr<ContinuousTaskRecord> continuousTaskInfo,
|
||||
ContinuousTaskEventTriggerType changeEventType);
|
||||
@ -120,14 +119,14 @@ private:
|
||||
bool checkNotificationCondition(const std::set<std::string> ¬ificationLabels, const std::string &label);
|
||||
std::shared_ptr<Global::Resource::ResourceManager> GetBundleResMgr(const AppExecFwk::BundleInfo &bundleInfo);
|
||||
std::string GetMainAbilityLabel(const std::string &bundleName, int32_t userId);
|
||||
|
||||
void RemoveContinuousTaskRecordByUidAndMode(int32_t uid, uint32_t mode);
|
||||
void RemoveContinuousTaskRecordByUid(int32_t uid);
|
||||
private:
|
||||
std::atomic<bool> isSysReady_ {false};
|
||||
std::string deviceType_ {""};
|
||||
int32_t bgTaskUid_ {-1};
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler_ {nullptr};
|
||||
std::unordered_map<std::string, std::shared_ptr<ContinuousTaskRecord>> continuousTaskInfosMap_ {};
|
||||
std::unordered_map<std::string, std::shared_ptr<ContinuousTaskRecord>> continuousTaskInfosMapForBatch_ {};
|
||||
#ifdef DISTRIBUTED_NOTIFICATION_ENABLE
|
||||
std::shared_ptr<TaskNotificationSubscriber> subscriber_ {nullptr};
|
||||
#endif
|
||||
|
@ -76,11 +76,11 @@ static constexpr uint32_t PC_BGMODE_TASK_KEEPING = 256;
|
||||
static constexpr int32_t DEFAULT_NOTIFICATION_ID = 0;
|
||||
static constexpr int32_t DELAY_TIME = 2000;
|
||||
static constexpr int32_t MAX_DUMP_PARAM_NUMS = 3;
|
||||
static constexpr int32_t UNSET_UID = -1;
|
||||
static constexpr uint32_t INVALID_BGMODE = 0;
|
||||
static constexpr uint32_t BG_MODE_INDEX_HEAD = 1;
|
||||
static constexpr uint32_t BGMODE_NUMS = 10;
|
||||
static constexpr uint32_t VOIP_SA_UID = 7022;
|
||||
static constexpr uint32_t ALL_MODES = 0xFF;
|
||||
|
||||
#ifndef HAS_OS_ACCOUNT_PART
|
||||
constexpr int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part
|
||||
@ -667,7 +667,7 @@ ErrCode BgContinuousTaskMgr::UpdateBackgroundRunningInner(const std::string &tas
|
||||
auto iter = continuousTaskInfosMap_.find(taskInfoMapKey);
|
||||
if (iter == continuousTaskInfosMap_.end()) {
|
||||
BGTASK_LOGW("continuous task is not exist: %{public}s, use start befor update", taskInfoMapKey.c_str());
|
||||
return ERR_BGTASK_OBJECT_EXISTS;
|
||||
return ERR_BGTASK_OBJECT_NOT_EXIST;
|
||||
}
|
||||
|
||||
auto continuousTaskRecord = iter->second;
|
||||
@ -854,83 +854,77 @@ ErrCode BgContinuousTaskMgr::StopBackgroundRunningInner(int32_t uid, const std::
|
||||
return result;
|
||||
}
|
||||
|
||||
void BgContinuousTaskMgr::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
void BgContinuousTaskMgr::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key)
|
||||
{
|
||||
BGTASK_LOGD("StopContinuousTask begin uid: %{public}d, pid: %{public}d, taskType: %{public}d",
|
||||
uid, pid, taskType);
|
||||
if (!isSysReady_.load()) {
|
||||
BGTASK_LOGW("manager is not ready");
|
||||
return;
|
||||
}
|
||||
auto task = [this, uid, pid, taskType]() { this->HandleStopContinuousTask(uid, pid, taskType); };
|
||||
auto self = shared_from_this();
|
||||
auto task = [self, uid, pid, taskType, key]() {
|
||||
if (self) {
|
||||
self->HandleStopContinuousTask(uid, pid, taskType, key);
|
||||
}
|
||||
};
|
||||
handler_->PostTask(task);
|
||||
}
|
||||
|
||||
void BgContinuousTaskMgr::HandleStopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
void BgContinuousTaskMgr::HandleStopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key)
|
||||
{
|
||||
// uid == -1 means target type continuoust task required condition is not met, so cancel all this kind of tasks;
|
||||
if (uid == UNSET_UID) {
|
||||
BGTASK_LOGI("SA die, StopContinuousTask begin uid: %{public}d, pid: %{public}d, taskType: %{public}d",
|
||||
uid, pid, taskType);
|
||||
RemoveSpecifiedBgTask(taskType);
|
||||
BGTASK_LOGI("StopContinuousTask taskType: %{public}d, key %{public}s", taskType, key.c_str());
|
||||
if (taskType == BackgroundMode::DATA_TRANSFER) {
|
||||
RemoveContinuousTaskRecordByUidAndMode(uid, taskType);
|
||||
return;
|
||||
}
|
||||
if (taskType == ALL_MODES) {
|
||||
RemoveContinuousTaskRecordByUid(uid);
|
||||
return;
|
||||
}
|
||||
if (continuousTaskInfosMap_.find(key) == continuousTaskInfosMap_.end()) {
|
||||
BGTASK_LOGW("remove TaskInfo failure, no matched task: %{public}s", key.c_str());
|
||||
return;
|
||||
}
|
||||
NotificationTools::GetInstance()->CancelNotification(continuousTaskInfosMap_[key]->GetNotificationLabel(),
|
||||
DEFAULT_NOTIFICATION_ID);
|
||||
RemoveContinuousTaskRecord(key);
|
||||
}
|
||||
|
||||
void BgContinuousTaskMgr::RemoveContinuousTaskRecordByUid(int32_t uid)
|
||||
{
|
||||
auto iter = continuousTaskInfosMap_.begin();
|
||||
int32_t uidNum = 0;
|
||||
bool uidExist = false;
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
int32_t recordUid = iter->second->GetUid();
|
||||
uint32_t bgmodeId = iter->second->GetBgModeId();
|
||||
if (recordUid != uid) {
|
||||
iter++;
|
||||
if (iter->second->GetUid() != uid) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
uidNum++;
|
||||
uidExist = true;
|
||||
if (bgmodeId == taskType) {
|
||||
BGTASK_LOGI("StopContinuousTask by suspend sa, uid: %{public}d, pid: %{public}d, taskType: %{public}d",
|
||||
uid, pid, taskType);
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
NotificationTools::GetInstance()->CancelNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
RefreshTaskRecord();
|
||||
uidNum--;
|
||||
} else {
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
if (uidExist && uidNum == 0) {
|
||||
HandleAppContinuousTaskStop(uid);
|
||||
BGTASK_LOGW("erase key %{public}s", iter->first.c_str());
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
NotificationTools::GetInstance()->CancelNotification(iter->second->GetNotificationLabel(),
|
||||
DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
RefreshTaskRecord();
|
||||
}
|
||||
}
|
||||
|
||||
void BgContinuousTaskMgr::RemoveSpecifiedBgTask(uint32_t taskType)
|
||||
void BgContinuousTaskMgr::RemoveContinuousTaskRecordByUidAndMode(int32_t uid, uint32_t mode)
|
||||
{
|
||||
std::map<int32_t, int32_t> appTaskNum;
|
||||
auto iter = continuousTaskInfosMap_.begin();
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
int32_t uid = iter->second->GetUid();
|
||||
if (appTaskNum.find(uid) != appTaskNum.end()) {
|
||||
appTaskNum[uid]++;
|
||||
} else {
|
||||
appTaskNum[uid] = 1;
|
||||
if (iter->second->GetUid() != uid) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
if (iter->second->GetBgModeId() == taskType) {
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
NotificationTools::GetInstance()->CancelNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
RefreshTaskRecord();
|
||||
appTaskNum[uid]--;
|
||||
} else {
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
for (auto var : appTaskNum) {
|
||||
if (var.second == 0) {
|
||||
HandleAppContinuousTaskStop(var.first);
|
||||
auto findModeIter = std::find(iter->second->bgModeIds_.begin(), iter->second->bgModeIds_.end(), mode);
|
||||
if (findModeIter == iter->second->bgModeIds_.end()) {
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
BGTASK_LOGW("erase key %{public}s", iter->first.c_str());
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
NotificationTools::GetInstance()->CancelNotification(iter->second->GetNotificationLabel(),
|
||||
DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
RefreshTaskRecord();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1155,11 +1149,11 @@ void BgContinuousTaskMgr::DumpCancelTask(const std::vector<std::string> &dumpOpt
|
||||
|
||||
bool BgContinuousTaskMgr::RemoveContinuousTaskRecord(const std::string &mapKey)
|
||||
{
|
||||
BGTASK_LOGD("task info: %{public}s", mapKey.c_str());
|
||||
if (continuousTaskInfosMap_.find(mapKey) == continuousTaskInfosMap_.end()) {
|
||||
BGTASK_LOGW("remove TaskInfo failure, no matched task: %{public}s", mapKey.c_str());
|
||||
return false;
|
||||
}
|
||||
BGTASK_LOGI("erase task info: %{public}s", mapKey.c_str());
|
||||
auto record = continuousTaskInfosMap_.at(mapKey);
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
continuousTaskInfosMap_.erase(mapKey);
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
ErrCode ResetAllEfficiencyResources() override;
|
||||
ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList,
|
||||
std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList) override;
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType) override;
|
||||
ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key) override;
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
|
||||
|
||||
void ForceCancelSuspendDelay(int32_t requestId);
|
||||
|
@ -226,13 +226,14 @@ ErrCode BackgroundTaskMgrService::GetEfficiencyResourcesInfos(
|
||||
return DelayedSingleton<BgEfficiencyResourcesMgr>::GetInstance()->GetEfficiencyResourcesInfos(appList, procList);
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrService::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType)
|
||||
ErrCode BackgroundTaskMgrService::StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType,
|
||||
const std::string &key)
|
||||
{
|
||||
if (!CheckCallingToken()) {
|
||||
BGTASK_LOGW("StopContinuousTask not allowed");
|
||||
return ERR_BGTASK_PERMISSION_DENIED;
|
||||
}
|
||||
BgContinuousTaskMgr::GetInstance()->StopContinuousTask(uid, pid, taskType);
|
||||
BgContinuousTaskMgr::GetInstance()->StopContinuousTask(uid, pid, taskType, key);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,7 @@ static constexpr uint32_t INVALID_BGMODE_ID = 11;
|
||||
static constexpr uint64_t NO_SYSTEM_APP_TOKEN_ID = -100;
|
||||
static constexpr int32_t DEFAULT_USERID = 100;
|
||||
static constexpr int32_t TEST_NUM_ONE = 1;
|
||||
static constexpr uint32_t TEST_NUM_UONE = 1;
|
||||
static constexpr int32_t TEST_NUM_TWO = 2;
|
||||
static constexpr uint32_t TEST_NUM_UTWO = 2;
|
||||
static constexpr int32_t TEST_NUM_THREE = 3;
|
||||
static constexpr uint32_t CONFIGURE_ALL_MODES = 0x1FF;
|
||||
}
|
||||
@ -262,7 +260,7 @@ HWTEST_F(BgContinuousTaskMgrTest, StartAndUpdateBackgroundRunning_001, TestSize.
|
||||
std::make_shared<AbilityRuntime::WantAgent::WantAgent>(),
|
||||
"ability1", nullptr, "Entry", true, {1, 2});
|
||||
EXPECT_NE(taskParam5, nullptr);
|
||||
EXPECT_EQ((int32_t)bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam5), (int32_t)ERR_BGTASK_OBJECT_EXISTS);
|
||||
EXPECT_EQ((int32_t)bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam5), (int32_t)ERR_BGTASK_OBJECT_NOT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,11 +451,11 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_005, TestSize.Level1)
|
||||
HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_006, TestSize.Level1)
|
||||
{
|
||||
bgContinuousTaskMgr_->isSysReady_.store(false);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1, "");
|
||||
bgContinuousTaskMgr_->isSysReady_.store(true);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(-1, 1, 1);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(-1, 1, 1, "");
|
||||
SleepForFC();
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1, "");
|
||||
SleepForFC();
|
||||
|
||||
std::shared_ptr<ContinuousTaskRecord> continuousTaskRecord1 = std::make_shared<ContinuousTaskRecord>();
|
||||
@ -477,7 +475,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_006, TestSize.Level1)
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key2"] = continuousTaskRecord2;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key3"] = continuousTaskRecord3;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key4"] = continuousTaskRecord4;
|
||||
bgContinuousTaskMgr_->StopContinuousTask(-1, 1, 1);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(-1, 1, 1, "");
|
||||
SleepForFC();
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_.clear();
|
||||
|
||||
@ -485,7 +483,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_006, TestSize.Level1)
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key2"] = continuousTaskRecord2;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key3"] = continuousTaskRecord3;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key4"] = continuousTaskRecord4;
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1);
|
||||
bgContinuousTaskMgr_->StopContinuousTask(1, 1, 1, "");
|
||||
SleepForFC();
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
@ -807,34 +805,40 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_034, TestSize.Level1)
|
||||
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord1;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key2"] = continuousTaskRecord2;
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(TEST_NUM_ONE, TEST_NUM_ONE, TEST_NUM_ONE);
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(TEST_NUM_ONE, TEST_NUM_ONE, TEST_NUM_ONE, "");
|
||||
EXPECT_NE((int32_t)bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: BgTaskManagerUnitTest_035
|
||||
* @tc.desc: test RemoveSpecifiedBgTask.
|
||||
* @tc.desc: test HandleStopContinuousTask.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5IRJK issueI4QT3W issueI4QU0V
|
||||
*/
|
||||
HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_035, TestSize.Level1)
|
||||
{
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_.clear();
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(0, 0, 0, "");
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
|
||||
std::shared_ptr<ContinuousTaskRecord> continuousTaskRecord1 = std::make_shared<ContinuousTaskRecord>();
|
||||
continuousTaskRecord1->uid_ = TEST_NUM_ONE;
|
||||
continuousTaskRecord1->bgModeId_ = TEST_NUM_UONE;
|
||||
std::shared_ptr<ContinuousTaskRecord> continuousTaskRecord2 = std::make_shared<ContinuousTaskRecord>();
|
||||
continuousTaskRecord1->uid_ = TEST_NUM_ONE;
|
||||
continuousTaskRecord1->bgModeId_ = TEST_NUM_UTWO;
|
||||
continuousTaskRecord1->uid_ = 1;
|
||||
continuousTaskRecord1->bgModeIds_ = {1};
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord1;
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 1);
|
||||
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(1, 0, 1, "");
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord1;
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key2"] = continuousTaskRecord2;
|
||||
bgContinuousTaskMgr_->RemoveSpecifiedBgTask(TEST_NUM_UONE);
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 1);
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(1, 0, 0xFF, "");
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_.clear();
|
||||
bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord1;
|
||||
bgContinuousTaskMgr_->RemoveSpecifiedBgTask(TEST_NUM_UONE);
|
||||
EXPECT_NE((int32_t)bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 1);
|
||||
bgContinuousTaskMgr_->HandleStopContinuousTask(1, 0, 0, "key1");
|
||||
EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ HWTEST_F(BgTaskManagerAbnormalUnitTest, BackgroundTaskMgrServiceAbnormalTest_002
|
||||
std::vector<std::shared_ptr<ResourceCallbackInfo>> list4;
|
||||
EXPECT_EQ(BackgroundTaskMgrService_->GetEfficiencyResourcesInfos(list3, list4), ERR_BGTASK_PERMISSION_DENIED);
|
||||
|
||||
EXPECT_EQ(BackgroundTaskMgrService_->StopContinuousTask(1, 1, 1), ERR_BGTASK_PERMISSION_DENIED);
|
||||
EXPECT_EQ(BackgroundTaskMgrService_->StopContinuousTask(1, 1, 1, ""), ERR_BGTASK_PERMISSION_DENIED);
|
||||
|
||||
EXPECT_EQ(BackgroundTaskMgrService_->SubscribeBackgroundTask(nullptr), ERR_BGTASK_PERMISSION_DENIED);
|
||||
EXPECT_EQ(BackgroundTaskMgrService_->UnsubscribeBackgroundTask(nullptr), ERR_BGTASK_PERMISSION_DENIED);
|
||||
|
Loading…
Reference in New Issue
Block a user