/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_APP_STATE_OBSERVER_MANAGER_H #define OHOS_ABILITY_RUNTIME_APP_STATE_OBSERVER_MANAGER_H #include #include #include #include #include "app_running_record.h" #include "app_state_data.h" #include "iapp_state_callback.h" #include "iapplication_state_observer.h" #include "permission_constants.h" #include "permission_verification.h" #include "singleton.h" #include "uri_permission_manager_client.h" namespace OHOS { namespace AppExecFwk { class AppStateObserverManager : public std::enable_shared_from_this { DECLARE_DELAYED_SINGLETON(AppStateObserverManager) public: void Init(); int32_t RegisterApplicationStateObserver(const sptr &observer, const std::vector &bundleNameList = {}); int32_t UnregisterApplicationStateObserver(const sptr &observer); void StateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility); void OnAppStateChanged(const std::shared_ptr &appRecord, const ApplicationState state, bool needNotifyApp); void OnProcessCreated(const std::shared_ptr &appRecord); void OnProcessStateChanged(const std::shared_ptr &appRecord); void OnRenderProcessCreated(const std::shared_ptr &RenderRecord); void OnProcessDied(const std::shared_ptr &appRecord); void OnRenderProcessDied(const std::shared_ptr &renderRecord); void OnProcessReused(const std::shared_ptr &appRecord); private: void HandleAppStateChanged(const std::shared_ptr &appRecord, const ApplicationState state, bool needNotifyApp); void HandleStateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility); void HandleOnAppProcessCreated(const std::shared_ptr &appRecord); void HandleOnRenderProcessCreated(const std::shared_ptr &RenderRecord); void HandleOnAppProcessDied(const std::shared_ptr &appRecord); void HandleOnRenderProcessDied(const std::shared_ptr &RenderRecord); bool ObserverExist(const sptr &observer); void AddObserverDeathRecipient(const sptr &observer); void RemoveObserverDeathRecipient(const sptr &observer); ProcessData WrapProcessData(const std::shared_ptr &appRecord); ProcessData WrapRenderProcessData(const std::shared_ptr &renderRecord); void OnObserverDied(const wptr &remote); AppStateData WrapAppStateData(const std::shared_ptr &appRecord, const ApplicationState state); void HandleOnProcessCreated(const ProcessData &data); void HandleOnProcessStateChanged(const std::shared_ptr &appRecord); void HandleOnProcessDied(const ProcessData &data); void HandleOnProcessResued(const std::shared_ptr &appRecord); private: std::shared_ptr handler_; std::recursive_mutex observerLock_; std::map, sptr> recipientMap_; std::map, std::vector> appStateObserverMap_; }; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_APP_STATE_OBSERVER_MANAGER_H