1 /*
2 * Copyright (c) 2023 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 #include "timed_task.h"
17 #include "ability_manager_helper.h"
18 #include "app_mgr_helper.h"
19 #include "bundle_manager_helper.h"
20 #include "common_event_observer.h"
21 #include "background_task_helper.h"
22
23 namespace {
24 static constexpr char TEST_DEFAULT_BUNDLE[] = "bundleName";
25 bool g_mockGetAllRunningProcesses = true;
26 bool g_mockGetRunningSystemProcess = true;
27 bool g_mockGetBackgroundTask = true;
28 bool g_mockSubscribeObserver = true;
29 }
30
MockGetAllRunningProcesses(bool mockRet)31 void MockGetAllRunningProcesses(bool mockRet)
32 {
33 g_mockGetAllRunningProcesses = mockRet;
34 }
35
MockGetRunningSystemProcess(bool mockRet)36 void MockGetRunningSystemProcess(bool mockRet)
37 {
38 g_mockGetRunningSystemProcess = mockRet;
39 }
40
MockGetBackgroundTask(bool mockRet)41 void MockGetBackgroundTask(bool mockRet)
42 {
43 g_mockGetBackgroundTask = mockRet;
44 }
45
MockSubscribeObserver(bool mockRet)46 void MockSubscribeObserver(bool mockRet)
47 {
48 g_mockSubscribeObserver = mockRet;
49 }
50
51 namespace OHOS {
52 namespace DevStandbyMgr {
CreateTimer(bool repeat,uint64_t interval,bool isExact,bool isIdle,const std::function<void ()> & callBack)53 uint64_t TimedTask::CreateTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle,
54 const std::function<void()>& callBack)
55 {
56 return 1;
57 }
58
StartDayNightSwitchTimer(uint64_t & timeId)59 bool TimedTask::StartDayNightSwitchTimer(uint64_t& timeId)
60 {
61 return true;
62 }
63
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)64 bool AbilityManagerHelper::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
65 {
66 systemProcessInfos.emplace_back(SystemProcessInfo{});
67 return g_mockGetRunningSystemProcess;
68 }
69
GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo> & allAppProcessInfos)70 bool AppMgrHelper::GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo>& allAppProcessInfos)
71 {
72 allAppProcessInfos.emplace_back(AppExecFwk::RunningProcessInfo{});
73 return g_mockGetAllRunningProcesses;
74 }
75
Connect()76 bool AppMgrHelper::Connect()
77 {
78 return true;
79 }
80
GetAppRunningStateByBundleName(const std::string & bundleName,bool & isRunning)81 bool AppMgrHelper::GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning)
82 {
83 isRunning = true;
84 return true;
85 }
86
GetClientBundleName(int32_t uid)87 std::string BundleManagerHelper::GetClientBundleName(int32_t uid)
88 {
89 return TEST_DEFAULT_BUNDLE;
90 }
91
GetApplicationInfo(const std::string & appName,const AppExecFwk::ApplicationFlag flag,const int userId,AppExecFwk::ApplicationInfo & appInfo)92 bool BundleManagerHelper::GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag,
93 const int userId, AppExecFwk::ApplicationInfo &appInfo)
94 {
95 appInfo.runningResourcesApply = true;
96 return true;
97 }
98
Connect()99 bool BundleManagerHelper::Connect()
100 {
101 return true;
102 }
103
Subscribe()104 bool CommonEventObserver::Subscribe()
105 {
106 return true;
107 }
108
Unsubscribe()109 bool CommonEventObserver::Unsubscribe()
110 {
111 return true;
112 }
113
GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> & list)114 bool BackgroundTaskHelper::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
115 {
116 return g_mockGetBackgroundTask;
117 }
118
GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> & list)119 bool BackgroundTaskHelper::GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list)
120 {
121 return g_mockGetBackgroundTask;
122 }
123
SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)124 bool AppMgrHelper::SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer)
125 {
126 return g_mockSubscribeObserver;
127 }
128
UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)129 bool AppMgrHelper::UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer)
130 {
131 return g_mockSubscribeObserver;
132 }
133 } // namespace DevStandbyMgr
134 } // namespace OHOS