1 /* 2 * Copyright (c) 2025 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 APP_MANAGER_UTILS_H 17 #define APP_MANAGER_UTILS_H 18 19 #define API __attribute__((visibility("default"))) 20 21 #include "running_process_info.h" 22 #include "app_mgr_client.h" 23 24 namespace OHOS { 25 namespace PowerMgr { 26 class API AppManagerUtils { 27 public: 28 enum { 29 KILL_FG_PROCESS_APP = 1, 30 KILL_BG_PROCESS_APP = 2, 31 KILL_ALL_PROCESS_APP = 3, 32 }; 33 GetInstance()34 static AppManagerUtils& GetInstance() 35 { 36 static AppManagerUtils appManagerUtils; 37 return appManagerUtils; 38 } 39 40 ErrCode KillApplicationAction(const std::string& bundleName); 41 ErrCode GetRunningProcessInfo(std::vector<AppExecFwk::RunningProcessInfo>& info); 42 AppExecFwk::RunningProcessInfo GetAppProcessInfoByName(const std::string& processName); 43 ErrCode KillProcess(const pid_t pid); 44 void GetAllRunnningAppProcess(); 45 void KillFgAppProcess(); 46 void KillBgAppProcess(); 47 void KillAllAppProcess(); 48 void ProcessAppActionRequest(const uint32_t& value); 49 50 private: 51 AppManagerUtils(); 52 virtual ~AppManagerUtils() = default; 53 std::unique_ptr<AppExecFwk::AppMgrClient> appMgrClient_; 54 std::vector<AppExecFwk::RunningProcessInfo> bgAppProcessInfos_; 55 std::vector<AppExecFwk::RunningProcessInfo> fgAppProcessInfos_; 56 std::vector<AppExecFwk::RunningProcessInfo> allAppProcessInfos_; 57 }; 58 59 extern "C" API ErrCode KillApplicationAction(const std::string& bundleName); 60 extern "C" API void ProcessAppActionRequest(const uint32_t& value); 61 } // namespace PowerMgr 62 } // namespace OHOS 63 #endif // APP_MANAGER_UTILS_H