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