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 16 #ifndef OHOS_APP_STATE_OBSERVER_H 17 #define OHOS_APP_STATE_OBSERVER_H 18 19 #include "nocopyable.h" 20 #include "singleton.h" 21 22 #include "app_mgr_interface.h" 23 #include "application_state_observer_stub.h" 24 #include "if_system_ability_manager.h" 25 #include "iservice_registry.h" 26 #include "mmi_log.h" 27 #include "running_process_info.h" 28 #include "system_ability.h" 29 #include "system_ability_definition.h" 30 31 namespace OHOS { 32 namespace MMI { 33 class ApplicationStateObserver : public AppExecFwk::ApplicationStateObserverStub { 34 public: ApplicationStateObserver()35 ApplicationStateObserver() {}; 36 ~ApplicationStateObserver() = default; 37 void OnProcessStateChanged(const AppExecFwk::ProcessData &processData) override; 38 std::vector<AppExecFwk::AppStateData> GetForegroundAppData(); 39 private: 40 sptr<AppExecFwk::IAppMgr> appManager_ = nullptr; 41 OHOS::sptr<OHOS::AppExecFwk::IAppMgr> GetAppMgr(); 42 int32_t GetForegroundApplicationInfo(std::vector<AppExecFwk::AppStateData> &list); 43 }; 44 45 class AppObserverManager final { 46 DECLARE_DELAYED_SINGLETON(AppObserverManager); 47 public: 48 DISALLOW_COPY_AND_MOVE(AppObserverManager); 49 void InitAppStateObserver(); 50 void SetForegroundAppData(std::vector<AppExecFwk::AppStateData> list); 51 std::vector<AppExecFwk::AppStateData> GetForegroundAppData(); 52 private: 53 bool hasInit_ { false }; 54 std::vector<AppExecFwk::AppStateData> foregroundAppData_ {}; 55 }; 56 57 #define APP_OBSERVER_MGR ::OHOS::DelayedSingleton<AppObserverManager>::GetInstance() 58 } // namespace MMI 59 } // namespace OHOS 60 #endif // OHOS_APP_STATE_OBSERVER_H 61