• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef ACTION_APPLICATION_PROCESS_H
17 #define ACTION_APPLICATION_PROCESS_H
18 
19 #include "ithermal_action.h"
20 
21 #include "delayed_sp_singleton.h"
22 #include "running_process_info.h"
23 #include "app_mgr_client.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 class ActionApplicationProcess : public IThermalAction {
28 public:
29     ActionApplicationProcess(const std::string& actionName);
30     ~ActionApplicationProcess() = default;
31     enum {
32         KILL_FG_PROCESS_APP = 1,
33         KILL_BG_PROCESS_APP = 2,
34         KILL_ALL_PROCESS_APP = 3,
35     };
36 
37     void InitParams(const std::string& params) override;
38     void SetStrict(bool enable) override;
39     void SetEnableEvent(bool enable) override;
40     void AddActionValue(std::string value) override;
41     void Execute() override;
42     bool Init();
43     ErrCode KillApplicationAction(const std::string& bundleName);
44     ErrCode GetRunningProcessInfo(std::vector<AppExecFwk::RunningProcessInfo>& info);
45     AppExecFwk::RunningProcessInfo GetAppProcessInfoByName(const std::string& processName);
46     ErrCode KillProcess(const pid_t pid);
47     void GetAllRunnningAppProcess();
48     void KillFgAppProcess();
49     void KillBgAppProcess();
50     void KillAllAppProcess();
51     void ProcessAppActionRequest(const uint32_t& value);
52 
53     /* The api is used to UT, MT, ST */
54     void ProcessAppActionExecution(const uint32_t& value);
55 private:
56     uint32_t GetActionValue();
57     std::vector<uint32_t> valueList_;
58     std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_;
59     std::vector<AppExecFwk::RunningProcessInfo> bgAppProcessInfos_;
60     std::vector<AppExecFwk::RunningProcessInfo> fgAppProcessInfos_;
61     std::vector<AppExecFwk::RunningProcessInfo> allAppProcessInfos_;
62     uint32_t lastValue_ {0};
63 };
64 } // namespace PowerMgr
65 } // namespace OHOS
66 #endif // ACTION_APPLICATION_PROCESS_H
67