mirror of
https://gitee.com/openharmony/resourceschedule_background_task_mgr
synced 2024-11-27 09:01:19 +00:00
Merge branch 'master' of gitee.com:openharmony/resourceschedule_background_task_mgr into 728
This commit is contained in:
commit
4155869f82
@ -103,6 +103,13 @@ public:
|
||||
*/
|
||||
ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list);
|
||||
|
||||
/**
|
||||
* @brief Get all continuous task running infos
|
||||
* @param list continuous task infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list);
|
||||
|
||||
private:
|
||||
bool GetBackgroundTaskManagerProxy();
|
||||
|
||||
|
@ -97,6 +97,13 @@ public:
|
||||
*/
|
||||
ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) override;
|
||||
|
||||
/**
|
||||
* @brief Get all continuous task running infos.
|
||||
* @param list continuous task infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) override;
|
||||
|
||||
private:
|
||||
ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
ErrCode HandleSubscribeBackgroundTask(MessageParcel& data, MessageParcel& reply);
|
||||
ErrCode HandleUnsubscribeBackgroundTask(MessageParcel& data, MessageParcel& reply);
|
||||
ErrCode HandleGetTransientTaskApps(MessageParcel& data, MessageParcel& reply);
|
||||
ErrCode HandleGetContinuousTaskApps(MessageParcel& data, MessageParcel& reply);
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
||||
|
@ -82,6 +82,13 @@ public:
|
||||
*/
|
||||
void OnContinuousTaskStop(
|
||||
const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override;
|
||||
|
||||
/**
|
||||
* Called back when the app does not have continuous task.
|
||||
*
|
||||
* @param uid App uid.
|
||||
**/
|
||||
void OnAppContinuousTaskStop(int32_t uid) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<BackgroundTaskSubscriberProxy> delegator_;
|
||||
|
@ -49,6 +49,7 @@ private:
|
||||
ErrCode HandleOnAppTransientTaskEnd(MessageParcel& data);
|
||||
ErrCode HandleOnContinuousTaskStart(MessageParcel &data);
|
||||
ErrCode HandleOnContinuousTaskCancel(MessageParcel &data);
|
||||
ErrCode HandleOnAppContinuousTaskStop(MessageParcel &data);
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
||||
|
@ -104,6 +104,13 @@ public:
|
||||
*/
|
||||
virtual ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get all continuous task running infos.
|
||||
* @param list continuous task infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) = 0;
|
||||
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IBackgroundTaskMgr");
|
||||
|
||||
@ -117,6 +124,7 @@ protected:
|
||||
SUBSCRIBE_BACKGROUND_TASK,
|
||||
UNSUBSCRIBE_BACKGROUND_TASK,
|
||||
GET_TRANSIENT_TASK_APPS,
|
||||
GET_CONTINUOUS_TASK_APPS,
|
||||
};
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
|
@ -87,6 +87,14 @@ public:
|
||||
*/
|
||||
virtual void OnContinuousTaskStop(
|
||||
const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) = 0;
|
||||
|
||||
/**
|
||||
* Called back when the app does not have continuous task.
|
||||
*
|
||||
* @param uid App uid.
|
||||
**/
|
||||
virtual void OnAppContinuousTaskStop(int32_t uid) = 0;
|
||||
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IBackgroundTaskSubscriber");
|
||||
|
||||
@ -100,6 +108,7 @@ protected:
|
||||
ON_APP_TRANSIENT_TASK_END,
|
||||
ON_CONTINUOUS_TASK_START,
|
||||
ON_CONTINUOUS_TASK_STOP,
|
||||
ON_APP_CONTINUOUS_TASK_STOP,
|
||||
};
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
|
@ -168,6 +168,15 @@ bool BackgroundTaskManager::GetBackgroundTaskManagerProxy()
|
||||
return true;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskManager::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
if (!GetBackgroundTaskManagerProxy()) {
|
||||
BGTASK_LOGE("GetBackgroundTaskManagerProxy failed.");
|
||||
return ERR_BGTASK_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return backgroundTaskMgrProxy_->GetContinuousTaskApps(list);
|
||||
}
|
||||
|
||||
void BackgroundTaskManager::ResetBackgroundTaskManagerProxy()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
@ -283,6 +283,44 @@ ErrCode BackgroundTaskMgrProxy::GetTransientTaskApps(std::vector<std::shared_ptr
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrProxy::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_SYNC};
|
||||
if (!data.WriteInterfaceToken(BackgroundTaskMgrProxy::GetDescriptor())) {
|
||||
BGTASK_LOGE("GetContinuousTaskApps write descriptor failed");
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
ErrCode result = InnerTransact(GET_CONTINUOUS_TASK_APPS, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
BGTASK_LOGE("GetContinuousTaskApps fail: transact ErrCode=%{public}d", result);
|
||||
return ERR_BGTASK_TRANSACT_FAILED;
|
||||
}
|
||||
if (!reply.ReadInt32(result)) {
|
||||
BGTASK_LOGE("GetContinuousTaskApps fail: read result failed.");
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
if (result != ERR_OK) {
|
||||
BGTASK_LOGE("GetContinuousTaskApps failed.");
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t infoSize = reply.ReadInt32();
|
||||
for (int32_t i = 0; i < infoSize; i++) {
|
||||
auto info = ContinuousTaskCallbackInfo::Unmarshalling(reply);
|
||||
if (!info) {
|
||||
BGTASK_LOGE("GetContinuousTaskApps Read Parcelable infos failed.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
list.emplace_back(info);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrProxy::InnerTransact(uint32_t code, MessageOption &flags,
|
||||
MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
|
@ -53,6 +53,9 @@ const std::map<uint32_t, std::function<ErrCode(BackgroundTaskMgrStub *, MessageP
|
||||
{BackgroundTaskMgrStub::GET_TRANSIENT_TASK_APPS,
|
||||
std::bind(&BackgroundTaskMgrStub::HandleGetTransientTaskApps,
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
|
||||
{BackgroundTaskMgrStub::GET_CONTINUOUS_TASK_APPS,
|
||||
std::bind(&BackgroundTaskMgrStub::HandleGetContinuousTaskApps,
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
|
||||
};
|
||||
|
||||
ErrCode BackgroundTaskMgrStub::OnRemoteRequest(uint32_t code,
|
||||
@ -221,5 +224,24 @@ ErrCode BackgroundTaskMgrStub::HandleGetTransientTaskApps(MessageParcel& data, M
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrStub::HandleGetContinuousTaskApps(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> appInfos;
|
||||
ErrCode result = GetContinuousTaskApps(appInfos);
|
||||
if (!reply.WriteInt32(result)) {
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
reply.WriteInt32(appInfos.size());
|
||||
for (auto &info : appInfos) {
|
||||
if (info == nullptr) {
|
||||
return ERR_BGTASK_INVALID_PARAM;
|
||||
}
|
||||
if (!info->Marshalling(reply)) {
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
@ -250,5 +250,32 @@ void BackgroundTaskSubscriberProxy::OnContinuousTaskStop(
|
||||
BGTASK_LOGE("OnContinuousTaskStop SendRequest error");
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundTaskSubscriberProxy::OnAppContinuousTaskStop(int32_t uid)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
BGTASK_LOGE("OnAppContinuousTaskStop remote is dead.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(BackgroundTaskSubscriberProxy::GetDescriptor())) {
|
||||
BGTASK_LOGE("OnAppContinuousTaskStop write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(uid)) {
|
||||
BGTASK_LOGE("OnAppContinuousTaskStop write uid failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
int32_t result = remote->SendRequest(ON_APP_CONTINUOUS_TASK_STOP, data, reply, option);
|
||||
if (result != ERR_OK) {
|
||||
BGTASK_LOGE("OnAppContinuousTaskStop SendRequest error");
|
||||
}
|
||||
}
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
@ -71,6 +71,9 @@ ErrCode BackgroundTaskSubscriberStub::OnRemoteRequest(uint32_t code,
|
||||
case ON_CONTINUOUS_TASK_STOP: {
|
||||
return HandleOnContinuousTaskCancel(data);
|
||||
}
|
||||
case ON_APP_CONTINUOUS_TASK_STOP: {
|
||||
return HandleOnAppContinuousTaskStop(data);
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
@ -157,5 +160,17 @@ ErrCode BackgroundTaskSubscriberStub::HandleOnContinuousTaskCancel(MessageParcel
|
||||
OnContinuousTaskStop(continuousTaskCallbackInfo);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskSubscriberStub::HandleOnAppContinuousTaskStop(MessageParcel &data)
|
||||
{
|
||||
int32_t uid;
|
||||
if (!data.ReadInt32(uid)) {
|
||||
BGTASK_LOGE("HandleOnAppContinuousTaskStop read uid failed");
|
||||
return ERR_BGTASK_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
OnAppContinuousTaskStop(uid);
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
@ -62,6 +62,13 @@ public:
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
static ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list);
|
||||
|
||||
/**
|
||||
* @brief Get all continuous task running infos.
|
||||
* @param list continuous task infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
static ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list);
|
||||
};
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
||||
|
@ -87,6 +87,13 @@ public:
|
||||
**/
|
||||
virtual void OnContinuousTaskStop(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo);
|
||||
|
||||
/**
|
||||
* Called back when the app does not have continuous task.
|
||||
*
|
||||
* @param uid App uid.
|
||||
**/
|
||||
virtual void OnAppContinuousTaskStop(int32_t uid);
|
||||
|
||||
/**
|
||||
* Called back when the Background Task Manager Service has died.
|
||||
*/
|
||||
@ -169,6 +176,14 @@ private:
|
||||
*/
|
||||
void OnContinuousTaskStop(
|
||||
const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override;
|
||||
|
||||
/**
|
||||
* Called back when the app does not have continuous task.
|
||||
*
|
||||
* @param uid App uid.
|
||||
*/
|
||||
void OnAppContinuousTaskStop(int32_t uid) override;
|
||||
|
||||
/**
|
||||
* @brief Get managed proxy of background tasks.
|
||||
*
|
||||
|
@ -47,5 +47,10 @@ ErrCode BackgroundTaskMgrHelper::GetTransientTaskApps(std::vector<std::shared_pt
|
||||
{
|
||||
return DelayedSingleton<BackgroundTaskManager>::GetInstance()->GetTransientTaskApps(list);
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrHelper::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
return DelayedSingleton<BackgroundTaskManager>::GetInstance()->GetContinuousTaskApps(list);
|
||||
}
|
||||
} // namespace BackgroundTaskMgr
|
||||
} // namespace OHOS
|
@ -45,6 +45,8 @@ void BackgroundTaskSubscriber::OnContinuousTaskStart(
|
||||
void BackgroundTaskSubscriber::OnContinuousTaskStop(
|
||||
const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) {}
|
||||
|
||||
void BackgroundTaskSubscriber::OnAppContinuousTaskStop(int32_t uid) {}
|
||||
|
||||
void BackgroundTaskSubscriber::OnRemoteDied(const wptr<IRemoteObject> &object) {}
|
||||
|
||||
const sptr<BackgroundTaskSubscriber::BackgroundTaskSubscriberImpl> BackgroundTaskSubscriber::GetImpl() const
|
||||
@ -110,6 +112,11 @@ void BackgroundTaskSubscriber::BackgroundTaskSubscriberImpl::OnContinuousTaskSto
|
||||
subscriber_.OnContinuousTaskStop(continuousTaskCallbackInfo);
|
||||
}
|
||||
|
||||
void BackgroundTaskSubscriber::BackgroundTaskSubscriberImpl::OnAppContinuousTaskStop(int32_t uid)
|
||||
{
|
||||
subscriber_.OnAppContinuousTaskStop(uid);
|
||||
}
|
||||
|
||||
bool BackgroundTaskSubscriber::BackgroundTaskSubscriberImpl::GetBackgroundTaskMgrProxy()
|
||||
{
|
||||
if (proxy_) {
|
||||
|
@ -137,7 +137,6 @@ std::string GetMainAbilityLabel(const std::string &bundleName)
|
||||
|
||||
void StartBackgroundRunningExecuteCB(napi_env env, void *data)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data;
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("asyncCallbackInfo is nullptr");
|
||||
@ -188,13 +187,10 @@ void StartBackgroundRunningExecuteCB(napi_env env, void *data)
|
||||
std::make_shared<AbilityRuntime::WantAgent::WantAgent>(*asyncCallbackInfo->wantAgent),
|
||||
info->name, token, appName);
|
||||
asyncCallbackInfo->errCode = BackgroundTaskMgrHelper::RequestStartBackgroundRunning(taskParam);
|
||||
|
||||
BGTASK_LOGI("end");
|
||||
}
|
||||
|
||||
void CallbackCompletedCB(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
std::unique_ptr<AsyncCallbackInfo> callbackPtr {asyncCallbackInfo};
|
||||
napi_value callback = 0;
|
||||
@ -213,13 +209,10 @@ void CallbackCompletedCB(napi_env env, napi_status status, void *data)
|
||||
NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, asyncCallbackInfo->callback, &callback));
|
||||
NAPI_CALL_RETURN_VOID(env,
|
||||
napi_call_function(env, undefined, callback, CALLBACK_RESULT_PARAMS_NUM, result, &callResult));
|
||||
|
||||
BGTASK_LOGI("end");
|
||||
}
|
||||
|
||||
void PromiseCompletedCB(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
std::unique_ptr<AsyncCallbackInfo> callbackPtr {asyncCallbackInfo};
|
||||
napi_value result = 0;
|
||||
@ -230,14 +223,11 @@ void PromiseCompletedCB(napi_env env, napi_status status, void *data)
|
||||
result = GetCallbackErrorValue(env, asyncCallbackInfo->errCode);
|
||||
NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, asyncCallbackInfo->deferred, result));
|
||||
}
|
||||
|
||||
BGTASK_LOGI("end");
|
||||
}
|
||||
|
||||
napi_value StartBackgroundRunningAsync(
|
||||
napi_env env, napi_value *argv, const uint32_t argCallback, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
if (argv == nullptr || asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("param is nullptr");
|
||||
return nullptr;
|
||||
@ -259,13 +249,11 @@ napi_value StartBackgroundRunningAsync(
|
||||
&asyncCallbackInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
|
||||
BGTASK_LOGI("end");
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
|
||||
napi_value StartBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("param is nullptr");
|
||||
return nullptr;
|
||||
@ -285,14 +273,11 @@ napi_value StartBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncC
|
||||
(void *)asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
BGTASK_LOGI("end");
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value GetBackgroundMode(const napi_env &env, const napi_value &value, uint32_t &bgMode)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, value, &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected.");
|
||||
@ -304,19 +289,16 @@ napi_value GetBackgroundMode(const napi_env &env, const napi_value &value, uint3
|
||||
|
||||
napi_value GetWantAgent(const napi_env &env, const napi_value &value, AbilityRuntime::WantAgent::WantAgent *&wantAgent)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
NAPI_CALL(env, napi_typeof(env, value, &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected.");
|
||||
napi_unwrap(env, value, (void **)&wantAgent);
|
||||
|
||||
BGTASK_LOGI("end");
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
|
||||
napi_value StartBackgroundRunning(napi_env env, napi_callback_info info)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfo(env);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("asyncCallbackInfo == nullpter");
|
||||
@ -366,14 +348,12 @@ napi_value StartBackgroundRunning(napi_env env, napi_callback_info info)
|
||||
}
|
||||
ret = WrapVoidToJS(env);
|
||||
}
|
||||
BGTASK_LOGI("end");
|
||||
callbackPtr.release();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void StopBackgroundRunningExecuteCB(napi_env env, void *data)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("asyncCallbackInfo is nullptr");
|
||||
@ -403,7 +383,6 @@ void StopBackgroundRunningExecuteCB(napi_env env, void *data)
|
||||
napi_value StopBackgroundRunningAsync(napi_env env, napi_value *argv,
|
||||
const uint32_t argCallback, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
if (argv == nullptr || asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("param is nullptr");
|
||||
return nullptr;
|
||||
@ -425,13 +404,11 @@ napi_value StopBackgroundRunningAsync(napi_env env, napi_value *argv,
|
||||
(void *)asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork));
|
||||
BGTASK_LOGI("end");
|
||||
return WrapVoidToJS(env);
|
||||
}
|
||||
|
||||
napi_value StopBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("param is nullptr");
|
||||
return nullptr;
|
||||
@ -453,13 +430,11 @@ napi_value StopBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCa
|
||||
(void *)asyncCallbackInfo,
|
||||
&asyncCallbackInfo->asyncWork);
|
||||
napi_queue_async_work(env, asyncCallbackInfo->asyncWork);
|
||||
BGTASK_LOGI("end");
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value StopBackgroundRunning(napi_env env, napi_callback_info info)
|
||||
{
|
||||
BGTASK_LOGI("begin");
|
||||
AsyncCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfo(env);
|
||||
if (asyncCallbackInfo == nullptr) {
|
||||
BGTASK_LOGE("asyncCallbackInfo is nullpter");
|
||||
@ -497,7 +472,6 @@ napi_value StopBackgroundRunning(napi_env env, napi_callback_info info)
|
||||
}
|
||||
ret = WrapVoidToJS(env);
|
||||
}
|
||||
BGTASK_LOGI("end");
|
||||
callbackPtr.release();
|
||||
return ret;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
"services" : [{
|
||||
"name" : "bgtaskmgr_service",
|
||||
"path" : ["/system/bin/sa_main", "/system/profile/bgtaskmgr_service.xml"],
|
||||
"permission" : ["ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"],
|
||||
"uid" : "bgtask",
|
||||
"gid" : ["bgtask", "shell"],
|
||||
"secon" : "u:r:bgtaskmgr_service:s0"
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
ErrCode AddSubscriber(const sptr<IBackgroundTaskSubscriber> &subscriber);
|
||||
ErrCode RemoveSubscriber(const sptr<IBackgroundTaskSubscriber> &subscriber);
|
||||
ErrCode ShellDump(const std::vector<std::string> &dumpOption, std::vector<std::string> &dumpInfo);
|
||||
ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list);
|
||||
bool StopContinuousTaskByUser(const std::string &mapKey);
|
||||
void OnAccountsStateChanged(int32_t id);
|
||||
void OnBundleInfoChanged(const std::string &action, const std::string &bundleName, int32_t uid);
|
||||
@ -77,6 +78,7 @@ private:
|
||||
ErrCode RemoveSubscriberInner(const sptr<IBackgroundTaskSubscriber> &subscriber);
|
||||
ErrCode ShellDumpInner(const std::vector<std::string> &dumpOption, std::vector<std::string> &dumpInfo);
|
||||
ErrCode SendContinuousTaskNotification(std::shared_ptr<ContinuousTaskRecord> &ContinuousTaskRecordPtr);
|
||||
ErrCode GetContinuousTaskAppsInner(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list);
|
||||
void HandlePersistenceData();
|
||||
void CheckPersistenceData(const std::vector<AppExecFwk::RunningProcessInfo> &allProcesses,
|
||||
const std::vector<sptr<Notification::Notification>> &allNotifications);
|
||||
@ -98,6 +100,7 @@ private:
|
||||
ContinuousTaskEventTriggerType changeEventType);
|
||||
bool checkBgmodeType(uint32_t configuredBgMode, uint32_t requestedBgModeId, bool isNewApi, int32_t uid);
|
||||
int32_t RefreshTaskRecord();
|
||||
void HandleAppContinuousTaskStop(int32_t uid);
|
||||
|
||||
private:
|
||||
std::atomic<bool> isSysReady_ {false};
|
||||
|
@ -721,6 +721,36 @@ ErrCode BgContinuousTaskMgr::RemoveSubscriberInner(const sptr<IBackgroundTaskSub
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BgContinuousTaskMgr::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
if (!isSysReady_.load()) {
|
||||
BGTASK_LOGW("manager is not ready");
|
||||
return ERR_BGTASK_SYS_NOT_READY;
|
||||
}
|
||||
|
||||
ErrCode result = ERR_OK;
|
||||
|
||||
handler_->PostSyncTask([this, &list, &result]() {
|
||||
result = this->GetContinuousTaskAppsInner(list);
|
||||
}, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode BgContinuousTaskMgr::GetContinuousTaskAppsInner(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
if (continuousTaskInfosMap_.empty()) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
for (auto record : continuousTaskInfosMap_) {
|
||||
auto appInfo = std::make_shared<ContinuousTaskCallbackInfo>(record.second->bgModeId_, record.second->uid_,
|
||||
record.second->pid_, record.second->abilityName_);
|
||||
list.push_back(appInfo);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BgContinuousTaskMgr::ShellDump(const std::vector<std::string> &dumpOption, std::vector<std::string> &dumpInfo)
|
||||
{
|
||||
if (!isSysReady_.load()) {
|
||||
@ -788,13 +818,18 @@ void BgContinuousTaskMgr::DumpAllTaskInfo(std::vector<std::string> &dumpInfo)
|
||||
void BgContinuousTaskMgr::DumpCancelTask(const std::vector<std::string> &dumpOption, bool cleanAll)
|
||||
{
|
||||
if (cleanAll) {
|
||||
std::set<int32_t> uids;
|
||||
for (auto item : continuousTaskInfosMap_) {
|
||||
Notification::NotificationHelper::CancelContinuousTaskNotification(item.second->GetNotificationLabel(),
|
||||
DEFAULT_NOTIFICATION_ID);
|
||||
OnContinuousTaskChanged(item.second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
uids.insert(item.second->uid_);
|
||||
}
|
||||
continuousTaskInfosMap_.clear();
|
||||
RefreshTaskRecord();
|
||||
for (int32_t uid : uids) {
|
||||
HandleAppContinuousTaskStop(uid);
|
||||
}
|
||||
} else {
|
||||
if (dumpOption.size() < MAX_DUMP_PARAM_NUMS) {
|
||||
BGTASK_LOGW("invalid dump param");
|
||||
@ -818,8 +853,10 @@ bool BgContinuousTaskMgr::RemoveContinuousTaskRecord(const std::string &mapKey)
|
||||
BGTASK_LOGW("remove TaskInfo failure, no matched task: %{public}s", mapKey.c_str());
|
||||
return false;
|
||||
}
|
||||
OnContinuousTaskChanged(continuousTaskInfosMap_.at(mapKey), ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
auto record = continuousTaskInfosMap_.at(mapKey);
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
continuousTaskInfosMap_.erase(mapKey);
|
||||
HandleAppContinuousTaskStop(record->uid_);
|
||||
RefreshTaskRecord();
|
||||
return true;
|
||||
}
|
||||
@ -878,10 +915,12 @@ void BgContinuousTaskMgr::OnAbilityStateChanged(int32_t uid, const std::string &
|
||||
auto iter = continuousTaskInfosMap_.begin();
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
if (iter->second->uid_ == uid && iter->second->abilityName_ == abilityName) {
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
auto record = iter->second;
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
Notification::NotificationHelper::CancelContinuousTaskNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
record->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
HandleAppContinuousTaskStop(record->uid_);
|
||||
RefreshTaskRecord();
|
||||
} else {
|
||||
iter++;
|
||||
@ -899,10 +938,12 @@ void BgContinuousTaskMgr::OnProcessDied(int32_t pid)
|
||||
auto iter = continuousTaskInfosMap_.begin();
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
if (iter->second->GetPid() == pid) {
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
auto record = iter->second;
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
Notification::NotificationHelper::CancelContinuousTaskNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
record->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
HandleAppContinuousTaskStop(record->uid_);
|
||||
RefreshTaskRecord();
|
||||
} else {
|
||||
iter++;
|
||||
@ -961,10 +1002,12 @@ void BgContinuousTaskMgr::OnBundleInfoChanged(const std::string &action, const s
|
||||
auto iter = continuousTaskInfosMap_.begin();
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
if (iter->second->GetUid() == uid) {
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
auto record = iter->second;
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
Notification::NotificationHelper::CancelContinuousTaskNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
record->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
HandleAppContinuousTaskStop(uid);
|
||||
RefreshTaskRecord();
|
||||
} else {
|
||||
iter++;
|
||||
@ -992,10 +1035,12 @@ void BgContinuousTaskMgr::OnAccountsStateChanged(int32_t id)
|
||||
while (iter != continuousTaskInfosMap_.end()) {
|
||||
auto idIter = find(activatedOsAccountIds.begin(), activatedOsAccountIds.end(), iter->second->GetUserId());
|
||||
if (idIter == activatedOsAccountIds.end()) {
|
||||
OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
auto record = iter->second;
|
||||
OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_CANCEL);
|
||||
Notification::NotificationHelper::CancelContinuousTaskNotification(
|
||||
iter->second->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
record->GetNotificationLabel(), DEFAULT_NOTIFICATION_ID);
|
||||
iter = continuousTaskInfosMap_.erase(iter);
|
||||
HandleAppContinuousTaskStop(record->uid_);
|
||||
RefreshTaskRecord();
|
||||
} else {
|
||||
iter++;
|
||||
@ -1003,6 +1048,21 @@ void BgContinuousTaskMgr::OnAccountsStateChanged(int32_t id)
|
||||
}
|
||||
}
|
||||
|
||||
void BgContinuousTaskMgr::HandleAppContinuousTaskStop(int32_t uid)
|
||||
{
|
||||
auto findUid = [uid](const auto &target) {
|
||||
return uid == target.second->GetUid();
|
||||
};
|
||||
auto findUidIter = find_if(continuousTaskInfosMap_.begin(), continuousTaskInfosMap_.end(), findUid);
|
||||
if (findUidIter != continuousTaskInfosMap_.end()) {
|
||||
return;
|
||||
}
|
||||
BGTASK_LOGI("All continuous task has stopped of uid: %{public}d, so notify related subsystem", uid);
|
||||
for (auto iter = bgTaskSubscribers_.begin(); iter != bgTaskSubscribers_.end(); iter++) {
|
||||
(*iter)->OnAppContinuousTaskStop(uid);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t BgContinuousTaskMgr::RefreshTaskRecord()
|
||||
{
|
||||
if (dataStorage_ == nullptr) {
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
ErrCode SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber) override;
|
||||
ErrCode UnsubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber) override;
|
||||
ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) override;
|
||||
ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) override;
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
|
||||
|
||||
void ForceCancelSuspendDelay(int32_t requestId);
|
||||
|
@ -107,6 +107,11 @@ ErrCode BackgroundTaskMgrService::GetTransientTaskApps(std::vector<std::shared_p
|
||||
return DelayedSingleton<BgTransientTaskMgr>::GetInstance()->GetTransientTaskApps(list);
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrService::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
|
||||
{
|
||||
return BgContinuousTaskMgr::GetInstance()->GetContinuousTaskApps(list);
|
||||
}
|
||||
|
||||
ErrCode BackgroundTaskMgrService::SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber)
|
||||
{
|
||||
if (DelayedSingleton<BgTransientTaskMgr>::GetInstance()->SubscribeBackgroundTask(subscriber) == ERR_OK
|
||||
|
@ -223,6 +223,16 @@ RState ResourceManagerImpl::CloseRawFileDescriptor(const std::string &name)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetMediaBase64ByIdData(uint32_t id, uint32_t density, std::string &base64Data)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
RState ResourceManagerImpl::GetMediaBase64ByNameData(const char *name, uint32_t density, std::string &base64Data)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
} // namespace Resource
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -48,11 +48,11 @@ ohos_fuzztest("BgTaskOnRemoteRequestFuzzTest") {
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"resource_management:global_resmgr",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
||||
|
@ -57,12 +57,12 @@ ohos_systemtest("BgtaskDumpTest") {
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"relational_store:native_rdb",
|
||||
"resource_management:global_resmgr",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
"utils_base:utils",
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user