1 /* 2 * Copyright (c) 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 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_INCLUDE_APP_MGR_HELPER_H 16 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_INCLUDE_APP_MGR_HELPER_H 17 18 #ifdef STANDBY_SERVICE_UNIT_TEST 19 #define WEAK_FUNC __attribute__((weak)) 20 #else 21 #define WEAK_FUNC 22 #endif 23 24 #include "app_mgr_interface.h" 25 #include "app_mgr_proxy.h" 26 #include "ipc_skeleton.h" 27 #include "iremote_object.h" 28 #include "singleton.h" 29 30 namespace OHOS { 31 namespace DevStandbyMgr { 32 class AppMgrHelper { 33 DECLARE_DELAYED_SINGLETON(AppMgrHelper); 34 public: 35 static std::shared_ptr<AppMgrHelper> GetInstance(); 36 /** 37 * @brief Get the All Running Processes info. 38 * 39 * @param allAppProcessInfos process info of applications. 40 * @return true if subscribe successfully. 41 */ 42 bool GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo>& allAppProcessInfos); 43 44 /** 45 * @brief Get the App Running State By Bundle Name object. 46 */ 47 bool GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning); 48 49 /** 50 * Get Foreground Applications. 51 */ 52 bool GetForegroundApplications(std::vector<AppExecFwk::AppStateData> &fgApps); 53 54 /** 55 * @brief Subscribe AppStateObserver. 56 * 57 * @param observer app state observer. 58 * @return true if subscribe successfully. 59 */ 60 bool SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer); 61 62 /** 63 * @brief Unubscribe AppStateObserver. 64 * 65 * @param observer app state observer. 66 * @return true if unsubscribe successfully. 67 */ 68 bool UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer); 69 70 private: 71 AppMgrHelper(const AppMgrHelper&) = delete; 72 AppMgrHelper& operator= (const AppMgrHelper&) = delete; 73 AppMgrHelper(AppMgrHelper&&) = delete; 74 AppMgrHelper& operator= (AppMgrHelper&&) = delete; 75 bool Connect(); 76 77 private: 78 sptr<AppExecFwk::IAppMgr> appMgrProxy_ {nullptr}; 79 std::mutex connectMutex_ {}; 80 }; 81 } // namespace DevStandbyMgr 82 } // namespace OHOS 83 84 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_INCLUDE_APP_MGR_HELPER_H