From 3c49d72eaf2f8ae73029f5efb88fe6e2921d50d4 Mon Sep 17 00:00:00 2001 From: lin-yuqiang666 Date: Thu, 27 Jul 2023 22:37:04 +0800 Subject: [PATCH 1/3] test Signed-off-by: lin-yuqiang666 Change-Id: I95797b96a02d67813daad741ece492e64171ab81 --- .../source/system_ability_manager_proxy.cpp | 43 +++++++++++++++++++ .../include/if_system_ability_manager.h | 9 ++++ .../include/system_ability_manager_proxy.h | 11 +++++ .../native/include/system_ability_manager.h | 1 + 4 files changed, 64 insertions(+) diff --git a/frameworks/native/source/system_ability_manager_proxy.cpp b/frameworks/native/source/system_ability_manager_proxy.cpp index f8fe5ab0..b53759eb 100644 --- a/frameworks/native/source/system_ability_manager_proxy.cpp +++ b/frameworks/native/source/system_ability_manager_proxy.cpp @@ -15,6 +15,7 @@ #include "system_ability_manager_proxy.h" +#include #include #include @@ -30,6 +31,7 @@ #include "string_ex.h" #include "local_abilitys.h" +#include "system_ability_load_callback_stub.h" using namespace std; namespace OHOS { @@ -38,6 +40,30 @@ const int32_t RETRY_TIME_OUT_NUMBER = 10; const int32_t SLEEP_INTERVAL_TIME = 100; const int32_t SLEEP_ONE_MILLI_SECOND_TIME = 1000; } +class SystemAbilityProxyCallback : public SystemAbilityLoadCallbackStub { +public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + std::condition_variable cv_; + sptr loadproxy_; +}; + +void SystemAbilityProxyCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + loadproxy_ = remoteObject; + cv_.notify_one(); + HILOGI("on load system ability success!"); +} + +void SystemAbilityProxyCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + loadproxy_ = nullptr; + cv_.notify_one(); + HILOGI("on load system ability failed!"); +} + sptr SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId) { return GetSystemAbilityWrapper(systemAbilityId); @@ -454,6 +480,23 @@ int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilit return result; } +sptr SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) +{ + sptr callback = new SystemAbilityProxyCallback(); + int32_t ret = LoadSystemAbility(systemAbilityId, callback); + if (ret != ERR_OK) { + HILOGE("LoadSystemAbility error!"); + return nullptr; + } + auto waitStatus = callback->cv_.wait_for(lock, std::chrono::seconds(timeout), + [&callback]() { return callback->loadproxy_ != nullptr; }); + if (!waitStatus) { + HILOGE("load sa timeout"); + return nullptr; + } + return callback->loadproxy_; +} + int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) { diff --git a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h index e31a57aa..d80fdfc6 100644 --- a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h +++ b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h @@ -174,6 +174,15 @@ public: */ virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) = 0; + /** + * LoadSystemAbility, Load sa. + * + * @param systemAbilityId, Need to load the said of sa. + * @param timeout, limited time to load sa. + * @return remote object means that the load was successful. + */ + virtual sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) = 0; + /** * LoadSystemAbility, Load sa. * diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h index a8171340..c8058924 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h @@ -17,6 +17,8 @@ #ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H #define INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_PROXY_H +#include +#include #include #include "if_system_ability_manager.h" #include "system_ability_on_demand_event.h" @@ -135,6 +137,15 @@ public: */ int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; + /** + * LoadSystemAbility, Load sa. + * + * @param systemAbilityId, Need to load the said of sa. + * @param timeout, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten. + * @return return is not nullptr means that the load was successful. + */ + sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) override; + /** * LoadSystemAbility, Load sa. * diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index d95462eb..9067813c 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -97,6 +97,7 @@ public: int32_t SubscribeSystemProcess(const sptr& listener) override; int32_t UnSubscribeSystemProcess(const sptr& listener) override; int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) override; + sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) override { return nullptr; }; int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) override; int32_t DoLoadSystemAbility(int32_t systemAbilityId, const std::u16string& procName, const sptr& callback, int32_t callingPid, const OnDemandEvent& event); -- Gitee From fb1191535b44f3b25ed23982f9309cad25d04d22 Mon Sep 17 00:00:00 2001 From: lin-yuqiang666 Date: Sat, 29 Jul 2023 16:17:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?SA=E9=87=8D=E5=A4=8Dpublish=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lin-yuqiang666 Change-Id: Ibbe09f04d853045097ab561afe1c94f313e7a9ee --- .../source/system_ability_manager_proxy.cpp | 43 ------------------- .../include/if_system_ability_manager.h | 9 ---- .../include/system_ability_manager_proxy.h | 9 ---- .../native/include/system_ability_manager.h | 1 - .../native/source/system_ability_manager.cpp | 3 ++ 5 files changed, 3 insertions(+), 62 deletions(-) diff --git a/frameworks/native/source/system_ability_manager_proxy.cpp b/frameworks/native/source/system_ability_manager_proxy.cpp index b53759eb..f8fe5ab0 100644 --- a/frameworks/native/source/system_ability_manager_proxy.cpp +++ b/frameworks/native/source/system_ability_manager_proxy.cpp @@ -15,7 +15,6 @@ #include "system_ability_manager_proxy.h" -#include #include #include @@ -31,7 +30,6 @@ #include "string_ex.h" #include "local_abilitys.h" -#include "system_ability_load_callback_stub.h" using namespace std; namespace OHOS { @@ -40,30 +38,6 @@ const int32_t RETRY_TIME_OUT_NUMBER = 10; const int32_t SLEEP_INTERVAL_TIME = 100; const int32_t SLEEP_ONE_MILLI_SECOND_TIME = 1000; } -class SystemAbilityProxyCallback : public SystemAbilityLoadCallbackStub { -public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; - std::condition_variable cv_; - sptr loadproxy_; -}; - -void SystemAbilityProxyCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - loadproxy_ = remoteObject; - cv_.notify_one(); - HILOGI("on load system ability success!"); -} - -void SystemAbilityProxyCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - loadproxy_ = nullptr; - cv_.notify_one(); - HILOGI("on load system ability failed!"); -} - sptr SystemAbilityManagerProxy::GetSystemAbility(int32_t systemAbilityId) { return GetSystemAbilityWrapper(systemAbilityId); @@ -480,23 +454,6 @@ int32_t SystemAbilityManagerProxy::UnSubscribeSystemAbility(int32_t systemAbilit return result; } -sptr SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) -{ - sptr callback = new SystemAbilityProxyCallback(); - int32_t ret = LoadSystemAbility(systemAbilityId, callback); - if (ret != ERR_OK) { - HILOGE("LoadSystemAbility error!"); - return nullptr; - } - auto waitStatus = callback->cv_.wait_for(lock, std::chrono::seconds(timeout), - [&callback]() { return callback->loadproxy_ != nullptr; }); - if (!waitStatus) { - HILOGE("load sa timeout"); - return nullptr; - } - return callback->loadproxy_; -} - int32_t SystemAbilityManagerProxy::LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) { diff --git a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h index d80fdfc6..e31a57aa 100644 --- a/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h +++ b/interfaces/innerkits/samgr_proxy/include/if_system_ability_manager.h @@ -174,15 +174,6 @@ public: */ virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) = 0; - /** - * LoadSystemAbility, Load sa. - * - * @param systemAbilityId, Need to load the said of sa. - * @param timeout, limited time to load sa. - * @return remote object means that the load was successful. - */ - virtual sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) = 0; - /** * LoadSystemAbility, Load sa. * diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h index c8058924..ed3543bf 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h @@ -136,15 +136,6 @@ public: * @return ERR_OK indicates successful add. */ int32_t AddSystemProcess(const std::u16string& procName, const sptr& procObject) override; - - /** - * LoadSystemAbility, Load sa. - * - * @param systemAbilityId, Need to load the said of sa. - * @param timeout, OnLoadSystemAbilityFail and OnLoadSystemAbilitySuccess need be rewritten. - * @return return is not nullptr means that the load was successful. - */ - sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) override; /** * LoadSystemAbility, Load sa. diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index 9067813c..d95462eb 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -97,7 +97,6 @@ public: int32_t SubscribeSystemProcess(const sptr& listener) override; int32_t UnSubscribeSystemProcess(const sptr& listener) override; int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel& extraDataParcel) override; - sptr LoadSystemAbility(int32_t systemAbilityId, int32_t timeout) override { return nullptr; }; int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr& callback) override; int32_t DoLoadSystemAbility(int32_t systemAbilityId, const std::u16string& procName, const sptr& callback, int32_t callingPid, const OnDemandEvent& event); diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 1c21399b..25a7ff3a 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -973,6 +973,9 @@ int32_t SystemAbilityManager::AddSystemAbility(int32_t systemAbilityId, const sp saInfo.isDistributed = extraProp.isDistributed; saInfo.capability = extraProp.capability; saInfo.permission = Str16ToStr8(extraProp.permission); + if (abilityMap_.count(systemAbilityId) > 0) { + HILOGW("systemAbility: %{public}d is being covered", systemAbilityId); + } abilityMap_[systemAbilityId] = std::move(saInfo); HILOGI("insert %{public}d. size : %{public}zu", systemAbilityId, abilityMap_.size()); } -- Gitee From 1336fbb1cd790003620377005b011a2a5f331606 Mon Sep 17 00:00:00 2001 From: lin-yuqiang666 Date: Tue, 1 Aug 2023 09:38:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B9=BF=E6=92=AD=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=B5=E6=BA=90=E6=8F=92=E6=8B=94=E5=B9=BF?= =?UTF-8?q?=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lin-yuqiang666 Change-Id: Ib255cb43db72dc35ccb45e0b46d075392af36c8f --- .../samgr/native/source/collect/common_event_collect.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 060277b4..0bece175 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -76,12 +76,15 @@ void CommonEventCollect::Init(const std::list& onDemandSaProfiles) std::lock_guard autoLock(commonEventStateLock_); commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING); + commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCONNECTED); } std::lock_guard autoLock(commomEventLock_); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING); commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING); + commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTED); + commonEventNames_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCONNECTED); for (auto& profile : onDemandSaProfiles) { for (auto iterStart = profile.startOnDemand.onDemandEvents.begin(); iterStart != profile.startOnDemand.onDemandEvents.end(); iterStart++) { @@ -154,6 +157,12 @@ void CommonEventCollect::SaveAction(const std::string& action) } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING) { commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING); commonEventState_.erase(EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTED) { + commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTED); + commonEventState_.erase(EventFwk::CommonEventSupport::COMMON_EVENT_DISCONNECTED); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISCONNECTED) { + commonEventState_.insert(EventFwk::CommonEventSupport::COMMON_EVENT_DISCONNECTED); + commonEventState_.erase(EventFwk::CommonEventSupport::COMMON_EVENT_CONNECTED); } } -- Gitee