• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "include/ibundle_manager_helper.h"
23 
24 namespace {
25     static constexpr char TEST_DEFAULT_BUNDLE[]  = "bundleName";
26     static constexpr int32_t EXEMPT_ALL_RESOURCES = 100;
27     bool g_mockGetAllRunningProcesses = true;
28     bool g_mockGetRunningSystemProcess = true;
29     bool g_mockGetBackgroundTask = true;
30     bool g_mockSubscribeObserver = true;
31 }
32 
MockGetAllRunningProcesses(bool mockRet)33 void MockGetAllRunningProcesses(bool mockRet)
34 {
35     g_mockGetAllRunningProcesses = mockRet;
36 }
37 
MockGetRunningSystemProcess(bool mockRet)38 void MockGetRunningSystemProcess(bool mockRet)
39 {
40     g_mockGetRunningSystemProcess = mockRet;
41 }
42 
MockGetBackgroundTask(bool mockRet)43 void MockGetBackgroundTask(bool mockRet)
44 {
45     g_mockGetBackgroundTask = mockRet;
46 }
47 
MockSubscribeObserver(bool mockRet)48 void MockSubscribeObserver(bool mockRet)
49 {
50     g_mockSubscribeObserver = mockRet;
51 }
52 
53 namespace OHOS {
54 namespace DevStandbyMgr {
55 namespace {
56     std::shared_ptr<IBundleManagerHelper> bundleManagerHelperMock;
57 }
58 
SetBundleManagerHelper(std::shared_ptr<IBundleManagerHelper> mock)59 void SetBundleManagerHelper(std::shared_ptr<IBundleManagerHelper> mock)
60 {
61     bundleManagerHelperMock = mock;
62 }
63 
CleanBundleManagerHelper()64 void CleanBundleManagerHelper()
65 {
66     bundleManagerHelperMock.reset();
67 }
68 
GetApplicationInfo(const std::string & appName,const AppExecFwk::ApplicationFlag flag,const int userId,AppExecFwk::ApplicationInfo & appInfo)69 bool BundleManagerHelper::GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag,
70     const int userId, AppExecFwk::ApplicationInfo &appInfo)
71 {
72     bool ret {true};
73     if (bundleManagerHelperMock) {
74         ret = bundleManagerHelperMock->GetApplicationInfo(appName, flag, userId, appInfo);
75     } else {
76         appInfo.resourcesApply = { EXEMPT_ALL_RESOURCES };
77     }
78     return ret;
79 }
80 
CreateTimer(bool repeat,uint64_t interval,bool isExact,bool isIdle,const std::function<void ()> & callBack)81 uint64_t TimedTask::CreateTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle,
82     const std::function<void()>& callBack)
83 {
84     return 1;
85 }
86 
StartDayNightSwitchTimer(uint64_t & timeId)87 bool TimedTask::StartDayNightSwitchTimer(uint64_t& timeId)
88 {
89     return true;
90 }
91 
GetRunningSystemProcess(std::list<SystemProcessInfo> & systemProcessInfos)92 bool AbilityManagerHelper::GetRunningSystemProcess(std::list<SystemProcessInfo>& systemProcessInfos)
93 {
94     systemProcessInfos.emplace_back(SystemProcessInfo{});
95     return g_mockGetRunningSystemProcess;
96 }
97 
GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo> & allAppProcessInfos)98 bool AppMgrHelper::GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo>& allAppProcessInfos)
99 {
100     allAppProcessInfos.emplace_back(AppExecFwk::RunningProcessInfo{});
101     return g_mockGetAllRunningProcesses;
102 }
103 
Connect()104 bool AppMgrHelper::Connect()
105 {
106     return true;
107 }
108 
GetAppRunningStateByBundleName(const std::string & bundleName,bool & isRunning)109 bool AppMgrHelper::GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning)
110 {
111     isRunning = true;
112     return true;
113 }
114 
GetClientBundleName(int32_t uid)115 std::string BundleManagerHelper::GetClientBundleName(int32_t uid)
116 {
117     return TEST_DEFAULT_BUNDLE;
118 }
119 
Connect()120 bool BundleManagerHelper::Connect()
121 {
122     return true;
123 }
124 
Subscribe()125 bool CommonEventObserver::Subscribe()
126 {
127     return true;
128 }
129 
Unsubscribe()130 bool CommonEventObserver::Unsubscribe()
131 {
132     return true;
133 }
134 
GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> & list)135 bool BackgroundTaskHelper::GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list)
136 {
137     return g_mockGetBackgroundTask;
138 }
139 
GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> & list)140 bool BackgroundTaskHelper::GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list)
141 {
142     return g_mockGetBackgroundTask;
143 }
144 
SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)145 bool AppMgrHelper::SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer)
146 {
147     return g_mockSubscribeObserver;
148 }
149 
UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)150 bool AppMgrHelper::UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer)
151 {
152     return g_mockSubscribeObserver;
153 }
154 }  // namespace DevStandbyMgr
155 }  // namespace OHOS