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 ErrCode KillApplicationAction(const std::string& bundleName); 43 ErrCode GetRunningProcessInfo(std::vector<AppExecFwk::RunningProcessInfo>& info); 44 AppExecFwk::RunningProcessInfo GetAppProcessInfoByName(const std::string& processName); 45 ErrCode KillProcess(const pid_t pid); 46 void GetAllRunnningAppProcess(); 47 void KillFgAppProcess(); 48 void KillBgAppProcess(); 49 void KillAllAppProcess(); 50 void ProcessAppActionRequest(const uint32_t& value); 51 52 /* The api is used to UT, MT, ST */ 53 void ProcessAppActionExecution(const uint32_t& value); 54 private: 55 uint32_t GetActionValue(); 56 std::vector<uint32_t> valueList_; 57 std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_; 58 std::vector<AppExecFwk::RunningProcessInfo> bgAppProcessInfos_; 59 std::vector<AppExecFwk::RunningProcessInfo> fgAppProcessInfos_; 60 std::vector<AppExecFwk::RunningProcessInfo> allAppProcessInfos_; 61 uint32_t lastValue_ {0}; 62 }; 63 } // namespace PowerMgr 64 } // namespace OHOS 65 #endif // ACTION_APPLICATION_PROCESS_H 66