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 "single_instance.h" 29 30 namespace OHOS { 31 namespace DevStandbyMgr { 32 class AppMgrHelper { 33 DECLARE_SINGLE_INSTANCE(AppMgrHelper); 34 public: 35 /** 36 * @brief Get the All Running Processes info. 37 * 38 * @param allAppProcessInfos process info of applications. 39 * @return true if subscribe successfully. 40 */ 41 bool GetAllRunningProcesses(std::vector<AppExecFwk::RunningProcessInfo>& allAppProcessInfos); 42 43 /** 44 * @brief Get the App Running State By Bundle Name object. 45 */ 46 bool GetAppRunningStateByBundleName(const std::string &bundleName, bool& isRunning); 47 48 /** 49 * Get Foreground Applications. 50 */ 51 bool GetForegroundApplications(std::vector<AppExecFwk::AppStateData> &fgApps); 52 53 /** 54 * @brief Subscribe AppStateObserver. 55 * 56 * @param observer app state observer. 57 * @return true if subscribe successfully. 58 */ 59 bool SubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer); 60 61 /** 62 * @brief Unubscribe AppStateObserver. 63 * 64 * @param observer app state observer. 65 * @return true if unsubscribe successfully. 66 */ 67 bool UnsubscribeObserver(const sptr<AppExecFwk::IApplicationStateObserver> &observer); 68 69 private: 70 bool Connect(); 71 72 private: 73 sptr<AppExecFwk::IAppMgr> appMgrProxy_ {nullptr}; 74 std::mutex connectMutex_ {}; 75 }; 76 } // namespace DevStandbyMgr 77 } // namespace OHOS 78 79 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACES_INNERKITS_INCLUDE_APP_MGR_HELPER_H