1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_BACKGROUND_TASK_MGR_STUB_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_BACKGROUND_TASK_MGR_STUB_H
18 
19 #include <map>
20 
21 #include <iremote_stub.h>
22 #include <nocopyable.h>
23 
24 #include "ibackground_task_mgr.h"
25 
26 namespace OHOS {
27 namespace BackgroundTaskMgr {
28 class BackgroundTaskMgrStub : public IRemoteStub<IBackgroundTaskMgr> {
29 public:
30     BackgroundTaskMgrStub() = default;
31     ~BackgroundTaskMgrStub() override = default;
32     DISALLOW_COPY_AND_MOVE(BackgroundTaskMgrStub);
33 
34     /**
35      * @brief Request service code and service data.
36      *
37      * @param code Service request code.
38      * @param data MessageParcel object.
39      * @param reply Local service response.
40      * @param option Point out async or sync.
41      * @return ERR_OK if success, else fail.
42      */
43     int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
44 
45 private:
46     static const std::map<uint32_t,
47         std::function<ErrCode(BackgroundTaskMgrStub *, MessageParcel &, MessageParcel &)>> interfaces_;
48     ErrCode HandleOnRemoteResquestFunc(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option);
49     ErrCode HandleRequestSuspendDelay(MessageParcel& data, MessageParcel& reply);
50     ErrCode HandleCancelSuspendDelay(MessageParcel& data, MessageParcel& reply);
51     ErrCode HandleGetRemainingDelayTime(MessageParcel& data, MessageParcel& reply);
52     ErrCode HandleStartBackgroundRunning(MessageParcel &data, MessageParcel &reply);
53     ErrCode HandleUpdateBackgroundRunning(MessageParcel &data, MessageParcel &reply);
54     ErrCode HandleStopBackgroundRunning(MessageParcel &data, MessageParcel &reply);
55     ErrCode HandleBackgroundRunningForInner(MessageParcel &data, MessageParcel &reply);
56     ErrCode HandleSubscribeBackgroundTask(MessageParcel& data, MessageParcel& reply);
57     ErrCode HandleUnsubscribeBackgroundTask(MessageParcel& data, MessageParcel& reply);
58     ErrCode HandleGetTransientTaskApps(MessageParcel& data, MessageParcel& reply);
59     ErrCode HandlePauseTransientTaskTimeForInner(MessageParcel& data, MessageParcel& reply);
60     ErrCode HandleStartTransientTaskTimeForInner(MessageParcel& data, MessageParcel& reply);
61     ErrCode HandleGetContinuousTaskApps(MessageParcel& data, MessageParcel& reply);
62     ErrCode HandleApplyEfficiencyResources(MessageParcel& data, MessageParcel& reply);
63     ErrCode HandleResetAllEfficiencyResources(MessageParcel& data, MessageParcel& reply);
64     ErrCode HandleGetEfficiencyResourcesInfos(MessageParcel& data, MessageParcel& reply);
65     ErrCode HandleStopContinuousTask(MessageParcel& data, MessageParcel& reply);
66     void HandleContinuousTask(uint32_t code, MessageParcel& data, MessageParcel& reply);
67     void HandleTransientTask(uint32_t code, MessageParcel& data, MessageParcel& reply);
68     ErrCode HandleSetBgTaskConfig(MessageParcel& data, MessageParcel& reply);
69     ErrCode WriteInfoToParcel(const std::vector<std::shared_ptr<ResourceCallbackInfo>>& infoMap, MessageParcel& reply);
70 };
71 }  // namespace BackgroundTaskMgr
72 }  // namespace OHOS
73 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_BACKGROUND_TASK_MGR_STUB_H