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