From 8c5655ccb8c8560f4cbaca763f88c49ce573f3cb Mon Sep 17 00:00:00 2001 From: jsjzju Date: Fri, 5 May 2023 16:41:35 +0800 Subject: [PATCH] Provide an observer mechanism for AbilityRecord. Signed-off-by: jsjzju Change-Id: I6b95f1c1fdf7f2bc316ddb91ac5fbebefc767cd0 --- frameworks/abilitymgr_lite/BUILD.gn | 2 + .../include/slite/abilityms_slite_client.h | 4 ++ .../src/slite/ability_manager_client.cpp | 37 ++++++++++++ .../src/slite/ability_record_state_data.cpp | 54 +++++++++++++++++ .../src/slite/abilityms_slite_client.cpp | 26 ++++++++ .../ability_service_interface.h | 2 + .../slite/ability_manager_client.h | 36 +++++++++++ .../slite/ability_record_observer.h | 35 +++++++++++ .../slite/ability_record_state.h | 29 +++++++++ .../slite/ability_record_state_data.h | 54 +++++++++++++++++ services/abilitymgr_lite/BUILD.gn | 1 + .../include/slite/ability_record.h | 9 +-- .../include/slite/ability_record_manager.h | 4 ++ .../slite/ability_record_observer_manager.h | 47 +++++++++++++++ .../src/slite/ability_mgr_service_slite.cpp | 7 +++ .../src/slite/ability_record_manager.cpp | 16 +++++ .../slite/ability_record_observer_manager.cpp | 60 +++++++++++++++++++ 17 files changed, 415 insertions(+), 8 deletions(-) create mode 100644 frameworks/abilitymgr_lite/src/slite/ability_manager_client.cpp create mode 100644 frameworks/abilitymgr_lite/src/slite/ability_record_state_data.cpp create mode 100644 interfaces/inner_api/abilitymgr_lite/slite/ability_manager_client.h create mode 100644 interfaces/inner_api/abilitymgr_lite/slite/ability_record_observer.h create mode 100644 interfaces/inner_api/abilitymgr_lite/slite/ability_record_state.h create mode 100644 interfaces/inner_api/abilitymgr_lite/slite/ability_record_state_data.h create mode 100644 services/abilitymgr_lite/include/slite/ability_record_observer_manager.h create mode 100644 services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp diff --git a/frameworks/abilitymgr_lite/BUILD.gn b/frameworks/abilitymgr_lite/BUILD.gn index 97cce51..cd0aa46 100644 --- a/frameworks/abilitymgr_lite/BUILD.gn +++ b/frameworks/abilitymgr_lite/BUILD.gn @@ -21,7 +21,9 @@ lite_library("abilitymanager") { sources = [ "src/slite/ability_manager.cpp", + "src/slite/ability_manager_client.cpp", "src/slite/ability_manager_inner.cpp", + "src/slite/ability_record_state_data.cpp", "src/slite/abilityms_slite_client.cpp", ] diff --git a/frameworks/abilitymgr_lite/include/slite/abilityms_slite_client.h b/frameworks/abilitymgr_lite/include/slite/abilityms_slite_client.h index 4c959e8..9b94f33 100755 --- a/frameworks/abilitymgr_lite/include/slite/abilityms_slite_client.h +++ b/frameworks/abilitymgr_lite/include/slite/abilityms_slite_client.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_SLITE_ABILITYMS_SLITE_CLIENT_H #include "ability_service_interface.h" +#include "ability_record_observer.h" #include "nocopyable.h" #include "want.h" @@ -51,6 +52,9 @@ public: void SetServiceIdentity(const Identity *identity); + int32_t AddAbilityRecordObserver(AbilityRecordObserver *observer); + int32_t RemoveAbilityRecordObserver(AbilityRecordObserver *observer); + private: AbilityMsClient() = default; diff --git a/frameworks/abilitymgr_lite/src/slite/ability_manager_client.cpp b/frameworks/abilitymgr_lite/src/slite/ability_manager_client.cpp new file mode 100644 index 0000000..cd20587 --- /dev/null +++ b/frameworks/abilitymgr_lite/src/slite/ability_manager_client.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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. + */ + +#include "ability_manager_client.h" +#include "abilityms_slite_client.h" + +namespace OHOS { +namespace AbilitySlite { +AbilityManagerClient &AbilityManagerClient::GetInstance() { + static AbilityManagerClient instance; + return instance; +} + +void AbilityManagerClient::AddAbilityRecordObserver(AbilityRecordObserver *observer) +{ + AbilityMsClient::GetInstance().AddAbilityRecordObserver(observer); +} + +void AbilityManagerClient::RemoveAbilityRecordObserver(AbilityRecordObserver *observer) +{ + AbilityMsClient::GetInstance().RemoveAbilityRecordObserver(observer); +} + +} +} \ No newline at end of file diff --git a/frameworks/abilitymgr_lite/src/slite/ability_record_state_data.cpp b/frameworks/abilitymgr_lite/src/slite/ability_record_state_data.cpp new file mode 100644 index 0000000..8f6aa7e --- /dev/null +++ b/frameworks/abilitymgr_lite/src/slite/ability_record_state_data.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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. + */ + +#include "ability_record_state_data.h" + +#include "adapter.h" +#include "utils.h" + +namespace OHOS { +namespace AbilitySlite { +AbilityRecordStateData::AbilityRecordStateData(const char *appName, AbilityRecordState state) +{ + SetAppName(appName); + state_ = state; +} + +AbilityRecordStateData::AbilityRecordStateData(const AbilityRecordStateData &stateData) + : AbilityRecordStateData(stateData.GetAppName(), stateData.GetState()) +{ +} + +AbilityRecordStateData &AbilityRecordStateData::operator=(const AbilityRecordStateData &stateData) +{ + if (this != &stateData) { + SetAppName(stateData.GetAppName()); + state_ = stateData.GetState(); + } + return *this; +} + +AbilityRecordStateData::~AbilityRecordStateData() +{ + AdapterFree(appName_); +} + +void AbilityRecordStateData::SetAppName(const char *name) +{ + AdapterFree(appName_); + appName_ = Utils::Strdup(name); +} +} // namespace AbilitySlite +} // namespace OHOS diff --git a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp index 91cf50f..3298c0d 100644 --- a/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp +++ b/frameworks/abilitymgr_lite/src/slite/abilityms_slite_client.cpp @@ -161,6 +161,32 @@ int32_t AbilityMsClient::ForceStop(char *bundleName) const return SAMGR_SendRequest(identity_, &request, nullptr); } +int32_t AbilityMsClient::AddAbilityRecordObserver(AbilityRecordObserver *observer) +{ + if (identity_ == nullptr) { + return PARAM_CHECK_ERROR; + } + Request request = { + .msgId = ADD_ABILITY_RECORD_OBSERVER, + .msgValue = reinterpret_cast(observer), + }; + + return SAMGR_SendRequest(identity_, &request, nullptr); +} + +int32_t AbilityMsClient::RemoveAbilityRecordObserver(AbilityRecordObserver *observer) +{ + if (identity_ == nullptr) { + return PARAM_CHECK_ERROR; + } + Request request = { + .msgId = REMOVE_ABILITY_RECORD_OBSERVER, + .msgValue = reinterpret_cast(observer), + }; + + return SAMGR_SendRequest(identity_, &request, nullptr); +} + void AbilityMsClient::SetServiceIdentity(const Identity *identity) { identity_ = identity; diff --git a/interfaces/inner_api/abilitymgr_lite/ability_service_interface.h b/interfaces/inner_api/abilitymgr_lite/ability_service_interface.h index 6c3b38a..00e01f1 100755 --- a/interfaces/inner_api/abilitymgr_lite/ability_service_interface.h +++ b/interfaces/inner_api/abilitymgr_lite/ability_service_interface.h @@ -56,6 +56,8 @@ enum AmsCommand { TERMINATE_APP = INNER_BEGIN, DUMP_ABILITY, TERMINATE_APP_BY_BUNDLENAME, + ADD_ABILITY_RECORD_OBSERVER, + REMOVE_ABILITY_RECORD_OBSERVER, COMMAND_END, }; diff --git a/interfaces/inner_api/abilitymgr_lite/slite/ability_manager_client.h b/interfaces/inner_api/abilitymgr_lite/slite/ability_manager_client.h new file mode 100644 index 0000000..9e2f7a1 --- /dev/null +++ b/interfaces/inner_api/abilitymgr_lite/slite/ability_manager_client.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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_SLITE_ABILITY_MANAGER_CLIENT_H +#define OHOS_ABILITY_SLITE_ABILITY_MANAGER_CLIENT_H + +#include "ability_record_observer.h" + +namespace OHOS { +namespace AbilitySlite { +class AbilityManagerClient { +public: + static AbilityManagerClient &GetInstance(); + + void AddAbilityRecordObserver(AbilityRecordObserver *observer); + void RemoveAbilityRecordObserver(AbilityRecordObserver *observer); + +private: + AbilityManagerClient() = default; + ~AbilityManagerClient() = default; +}; +} // AbilitySlite +} // namespace OHOS +#endif // OHOS_ABILITY_SLITE_ABILITY_MANAGER_CLIENT_H diff --git a/interfaces/inner_api/abilitymgr_lite/slite/ability_record_observer.h b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_observer.h new file mode 100644 index 0000000..fd7b720 --- /dev/null +++ b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_observer.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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_SLITE_ABILITY_RECORD_OBSERVER_H +#define OHOS_ABILITY_SLITE_ABILITY_RECORD_OBSERVER_H + +#include "ability_record_state_data.h" + +namespace OHOS { +namespace AbilitySlite { +class AbilityRecordObserver { +public: + AbilityRecordObserver() = default; + + virtual ~AbilityRecordObserver() = default; + + virtual void OnAbilityRecordStateChanged(const AbilityRecordStateData &data) {} + + virtual void OnAbilityRecordCleanup(char *appName) {} +}; +} // AbilitySlite +} // namespace OHOS +#endif // OHOS_ABILITY_SLITE_ABILITY_RECORD_OBSERVER_H diff --git a/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state.h b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state.h new file mode 100644 index 0000000..12d31dc --- /dev/null +++ b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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_SLITE_ABILITY_RECORD_STATE_H +#define OHOS_ABILITY_SLITE_ABILITY_RECORD_STATE_H + +namespace OHOS { +namespace AbilitySlite { +enum AbilityRecordState { + SCHEDULE_INITED, + SCHEDULE_FOREGROUND, + SCHEDULE_BACKGROUND, + SCHEDULE_STOP +}; +} // AbilitySlite +} // namespace OHOS +#endif // OHOS_ABILITY_SLITE_ABILITY_RECORD_STATE_H diff --git a/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state_data.h b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state_data.h new file mode 100644 index 0000000..8618327 --- /dev/null +++ b/interfaces/inner_api/abilitymgr_lite/slite/ability_record_state_data.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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_SLITE_ABILITY_RECORD_STATE_DATA_H +#define OHOS_ABILITY_SLITE_ABILITY_RECORD_STATE_DATA_H + +#include "ability_record_state.h" + +namespace OHOS { +namespace AbilitySlite { +class AbilityRecordStateData { +public: + AbilityRecordStateData() = default; + AbilityRecordStateData(const char *appName, AbilityRecordState state); + AbilityRecordStateData(const AbilityRecordStateData &stateData); + AbilityRecordStateData &operator=(const AbilityRecordStateData &stateData); + ~AbilityRecordStateData(); + + void SetAppName(const char *name); + + const char *GetAppName() const + { + return appName_; + } + + void SetState(AbilityRecordState state) + { + state_ = state; + } + + AbilityRecordState GetState() const + { + return state_; + } + +private: + char *appName_ = nullptr; + AbilityRecordState state_ = SCHEDULE_STOP; +}; +} // AbilitySlite +} // namespace OHOS +#endif // OHOS_ABILITY_SLITE_ABILITY_RECORD_STATE_DATA_H diff --git a/services/abilitymgr_lite/BUILD.gn b/services/abilitymgr_lite/BUILD.gn index f9e8602..882fd56 100644 --- a/services/abilitymgr_lite/BUILD.gn +++ b/services/abilitymgr_lite/BUILD.gn @@ -29,6 +29,7 @@ lite_library("abilityms") { "src/slite/ability_mgr_service_slite.cpp", "src/slite/ability_record.cpp", "src/slite/ability_record_manager.cpp", + "src/slite/ability_record_observer_manager.cpp", "src/slite/ability_thread.cpp", "src/slite/ability_thread_loader.cpp", "src/slite/bms_helper.cpp", diff --git a/services/abilitymgr_lite/include/slite/ability_record.h b/services/abilitymgr_lite/include/slite/ability_record.h index d2f236c..1bafa2d 100755 --- a/services/abilitymgr_lite/include/slite/ability_record.h +++ b/services/abilitymgr_lite/include/slite/ability_record.h @@ -19,6 +19,7 @@ #include "ability_info.h" #include "cmsis_os.h" #include "ability_thread.h" +#include "ability_record_state.h" namespace OHOS { namespace AbilitySlite { @@ -26,14 +27,6 @@ class JsAppHost; constexpr int FAIL_CALLBACK_ERRORCODE = 200; -/* States-feedback from launcher to AMS */ -typedef enum { - SCHEDULE_INITED, - SCHEDULE_FOREGROUND, - SCHEDULE_BACKGROUND, - SCHEDULE_STOP -} AbilityState; - typedef enum { STATE_JS_RUNNING, STATE_NATIVE_RUNNING, diff --git a/services/abilitymgr_lite/include/slite/ability_record_manager.h b/services/abilitymgr_lite/include/slite/ability_record_manager.h index bbc575b..c3fca86 100644 --- a/services/abilitymgr_lite/include/slite/ability_record_manager.h +++ b/services/abilitymgr_lite/include/slite/ability_record_manager.h @@ -20,6 +20,7 @@ #include "ability_list.h" #include "ability_record.h" +#include "ability_record_observer.h" #include "adapter.h" #include "bms_helper.h" #include "js_ability_thread.h" @@ -63,6 +64,9 @@ public: void StartLauncher(); + int32_t AddAbilityRecordObserver(AbilityRecordObserver *observer); + int32_t RemoveAbilityRecordObserver(AbilityRecordObserver *observer); + uint32_t curTask_ = 0; private: diff --git a/services/abilitymgr_lite/include/slite/ability_record_observer_manager.h b/services/abilitymgr_lite/include/slite/ability_record_observer_manager.h new file mode 100644 index 0000000..7e45e04 --- /dev/null +++ b/services/abilitymgr_lite/include/slite/ability_record_observer_manager.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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_SLITE_ABILITY_RECORD_OBSERVER_MANAGER_H +#define OHOS_ABILITY_SLITE_ABILITY_RECORD_OBSERVER_MANAGER_H + +#include "ability_record_observer.h" +#include "nocopyable.h" +#include "stdint.h" +#include "utils_list.h" + +namespace OHOS { +namespace AbilitySlite { +class AbilityRecordObserverManager : public NoCopyable { +public: + static AbilityRecordObserverManager &GetInstance(); + + void AddObserver(AbilityRecordObserver *observer); + + void RemoveObserver(AbilityRecordObserver *observer); + + void NotifyAbilityRecordStateChanged(const AbilityRecordStateData &data); + + void NotifyAbilityRecordCleanup(char *appName); + +private: + AbilityRecordObserverManager() = default; + ~AbilityRecordObserverManager() = default; + + List observers_; +}; + +} // namespace AbilitySlite +} // namespace OHOS +#endif // OHOS_ABILITY_SLITE_ABILITY_RECORD_OBSERVER_MANAGER_H diff --git a/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp b/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp index 94054c5..10a0ab2 100755 --- a/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp +++ b/services/abilitymgr_lite/src/slite/ability_mgr_service_slite.cpp @@ -16,6 +16,7 @@ #include "ability_mgr_service_slite.h" #include "ability_errors.h" +#include "ability_record_observer.h" #include "ability_service_interface.h" #include "ability_thread_loader.h" #include "abilityms_slite_client.h" @@ -171,6 +172,12 @@ BOOL AbilityMgrServiceSlite::ServiceMessageHandle(Service *service, Request *req } else if (request->msgId == TERMINATE_APP_BY_BUNDLENAME) { char *bundleName = reinterpret_cast(request->data); ret = AbilityRecordManager::GetInstance().ForceStop(bundleName); + } else if (request->msgId == ADD_ABILITY_RECORD_OBSERVER) { + AbilityRecordObserver *observer = reinterpret_cast(request->msgValue); + ret = AbilityRecordManager::GetInstance().AddAbilityRecordObserver(observer); + } else if (request->msgId == REMOVE_ABILITY_RECORD_OBSERVER) { + AbilityRecordObserver *observer = reinterpret_cast(request->msgValue); + ret = AbilityRecordManager::GetInstance().RemoveAbilityRecordObserver(observer); } return ret == ERR_OK; } diff --git a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp index 5d3e0e8..b9c74f4 100644 --- a/services/abilitymgr_lite/src/slite/ability_record_manager.cpp +++ b/services/abilitymgr_lite/src/slite/ability_record_manager.cpp @@ -19,6 +19,7 @@ #include "ability_errors.h" #include "ability_inner_message.h" #include "ability_record.h" +#include "ability_record_observer_manager.h" #include "ability_thread_loader.h" #include "abilityms_log.h" #include "ability_manager_inner.h" @@ -592,6 +593,7 @@ void AbilityRecordManager::DeleteRecordInfo(uint16_t token) RecordAbiityInfoEvt(record->GetAppName()); } abilityList_.Erase(token); + AbilityRecordObserverManager::GetInstance().NotifyAbilityRecordCleanup(record->appName); delete record; } @@ -815,6 +817,8 @@ void AbilityRecordManager::SetAbilityState(uint64_t token, int32_t state) return; } record->state = state; + AbilityRecordObserverManager::GetInstance().NotifyAbilityRecordStateChanged( + AbilityRecordStateData(record->appName, static_cast(state))); } #ifndef _MINI_MULTI_TASKS_ @@ -979,6 +983,18 @@ void AbilityRecordManager::setNativeAbility(const SliteAbility *ability) { nativeAbility_ = const_cast(ability); } + +int32_t AbilityRecordManager::AddAbilityRecordObserver(AbilityRecordObserver *observer) +{ + AbilityRecordObserverManager::GetInstance().AddObserver(observer); + return ERR_OK; +} + +int32_t AbilityRecordManager::RemoveAbilityRecordObserver(AbilityRecordObserver *observer) +{ + AbilityRecordObserverManager::GetInstance().RemoveObserver(observer); + return ERR_OK; +} } // namespace AbilitySlite } // namespace OHOS diff --git a/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp b/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp new file mode 100644 index 0000000..245df1f --- /dev/null +++ b/services/abilitymgr_lite/src/slite/ability_record_observer_manager.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 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. + */ + +#include "ability_record_observer_manager.h" + +namespace OHOS { +namespace AbilitySlite { +AbilityRecordObserverManager &AbilityRecordObserverManager::GetInstance() +{ + static AbilityRecordObserverManager instance; + return instance; +} + +void AbilityRecordObserverManager::AddObserver(AbilityRecordObserver *observer) +{ + for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { + if (it->value_ == observer) { + return; + } + } + observers_.PushBack(observer); +} + +void AbilityRecordObserverManager::RemoveObserver(AbilityRecordObserver *observer) +{ + for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { + if (it->value_ == observer) { + observers_.Remove(it); + return; + } + } +} + +void AbilityRecordObserverManager::NotifyAbilityRecordStateChanged(const AbilityRecordStateData &data) +{ + for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { + it->value_->OnAbilityRecordStateChanged(data); + } +} + +void AbilityRecordObserverManager::NotifyAbilityRecordCleanup(char *appName) +{ + for (auto it = observers_.Begin(); it != observers_.End(); it = it->next_) { + it->value_->OnAbilityRecordCleanup(appName); + } +} +} // namespace AbilitySlite +} // namespace OHOS \ No newline at end of file -- Gitee