From ed5b29be35bf2d4c20196f5d17a23ceb4cd7a0db Mon Sep 17 00:00:00 2001 From: louzhihao Date: Sun, 8 Jun 2025 21:32:11 +0800 Subject: [PATCH] ota Signed-off-by: louzhihao Change-Id: Ifc156f0945ab23dd7c5e20d1ea02347b311753f6 --- .../config/include/model/datashare_config.h | 3 +- .../config/src/model/datashare_config.cpp | 4 +- .../data_share/data_share_service_impl.cpp | 38 ++++++++++++++++++- .../data_share/data_share_service_impl.h | 3 +- .../data_share/sys_event_subscriber.cpp | 11 +++++- .../service/data_share/sys_event_subscriber.h | 3 +- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/config/include/model/datashare_config.h b/services/distributeddataservice/service/config/include/model/datashare_config.h index 4487c0d1b..29ef8e6a4 100644 --- a/services/distributeddataservice/service/config/include/model/datashare_config.h +++ b/services/distributeddataservice/service/config/include/model/datashare_config.h @@ -23,7 +23,8 @@ public: bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; std::vector dataShareExtNames; + std::vector updateLaunchNames; }; } // namespace DistributedData } // namespace OHOS -#endif //OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DATASHARE_CONFIG_H \ No newline at end of file +#endif //OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DATASHARE_CONFIG_H diff --git a/services/distributeddataservice/service/config/src/model/datashare_config.cpp b/services/distributeddataservice/service/config/src/model/datashare_config.cpp index 0eae37a2b..4bdfb6c04 100644 --- a/services/distributeddataservice/service/config/src/model/datashare_config.cpp +++ b/services/distributeddataservice/service/config/src/model/datashare_config.cpp @@ -18,13 +18,15 @@ namespace DistributedData { bool DataShareConfig::Marshal(json &node) const { SetValue(node[GET_NAME(dataShareExtNames)], dataShareExtNames); + SetValue(node[GET_NAME(updateLaunchNames)], updateLaunchNames); return true; } bool DataShareConfig::Unmarshal(const json &node) { GetValue(node, GET_NAME(dataShareExtNames), dataShareExtNames); + GetValue(node, GET_NAME(updateLaunchNames), updateLaunchNames); return true; } } // namespace DistributedData -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 6c30e699c..c162a6e20 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #define LOG_TAG "DataShareServiceImpl" #include "data_share_service_impl.h" @@ -25,6 +26,7 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "concurrent_task_client.h" +#include "config_factory.h" #include "data_ability_observer_interface.h" #include "data_share_profile_config.h" #include "dataobs_mgr_client.h" @@ -68,6 +70,7 @@ using namespace OHOS::DistributedData; __attribute__((used)) DataShareServiceImpl::Factory DataShareServiceImpl::factory_; // decimal base static constexpr int DECIMAL_BASE = 10; +DataShareServiceImpl::BindInfo DataShareServiceImpl::binderInfo_; class DataShareServiceImpl::SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { public: @@ -803,6 +806,39 @@ int32_t DataShareServiceImpl::DataShareStatic::OnAppUpdate(const std::string &bu return E_OK; } +void DataShareServiceImpl::UpdateLaunchInfo() +{ + DataShareConfig *config = ConfigFactory::GetInstance().GetDataShareConfig(); + if (config == nullptr) { + ZLOGE("DataShareConfig is nullptr"); + return; + } + + ZLOGI("UpdateLaunchInfo begin."); + std::vector& names = config->updateLaunchNames; + for (auto bundleName : names) { + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid }); + std::vector storeMetaData; + MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData, true); + std::vector updateMetaData; + for (auto &meta : storeMetaData) { + if (meta.bundleName != bundleName) { + continue; + } + updateMetaData.push_back(meta); + } + for (auto &meta : updateMetaData) { + MetaDataManager::GetInstance().DelMeta(meta.GetAutoLaunchKey(), true); + } + for (auto &meta : updateMetaData) { + BundleMgrProxy::GetInstance()->Delete(bundleName, atoi(meta.user.c_str()), 0); + SaveLaunchInfo(meta.bundleName, meta.user, DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid); + } + ZLOGI("update bundleName %{public}s, size:%{public}zu.", bundleName.c_str(), storeMetaData.size()); + } +} + int32_t DataShareServiceImpl::DataShareStatic::OnClearAppStorage(const std::string &bundleName, int32_t user, int32_t index, int32_t tokenId) { @@ -1106,7 +1142,7 @@ void DataShareServiceImpl::InitSubEvent() matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); - auto sysEventSubscriber = std::make_shared(subscribeInfo); + auto sysEventSubscriber = std::make_shared(subscribeInfo, binderInfo_.executors); if (!EventFwk::CommonEventManager::SubscribeCommonEvent(sysEventSubscriber)) { ZLOGE("Subscribe sys event failed."); alreadySubscribe = false; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 8cc9ca889..90675baab 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -91,6 +91,7 @@ public: const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) override; std::pair DeleteEx(const std::string &uri, const std::string &extUri, const DataSharePredicates &predicate) override; + static void UpdateLaunchInfo(); private: class SystemAbilityStatusChangeListener; using StaticActs = DistributedData::StaticActs; @@ -154,7 +155,7 @@ private: SubscribeStrategy subscribeStrategy_; TemplateStrategy templateStrategy_; RdbNotifyStrategy rdbNotifyStrategy_; - BindInfo binderInfo_; + static BindInfo binderInfo_; std::shared_ptr timerReceiver_ = nullptr; DataShareSilentConfig dataShareSilentConfig_; }; diff --git a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp index b0fe15ee2..4fe77b228 100644 --- a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp +++ b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp @@ -20,8 +20,8 @@ #include "log_print.h" namespace OHOS::DataShare { -SysEventSubscriber::SysEventSubscriber(const EventFwk::CommonEventSubscribeInfo& info) - : CommonEventSubscriber(info) +SysEventSubscriber::SysEventSubscriber(const EventFwk::CommonEventSubscribeInfo& info, + std::shared_ptr executors): CommonEventSubscriber(info), executors_(executors) { callbacks_ = { { EventFwk::CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED, &SysEventSubscriber::OnBMSReady } }; @@ -40,6 +40,13 @@ void SysEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& event) void SysEventSubscriber::OnBMSReady() { NotifyDataShareReady(); + auto executors = executors_; + if (executors == nullptr) { + ZLOGE("executors is null."); + } + executors->Execute([]() { + DataShareServiceImpl::UpdateLaunchInfo(); + }); } void SysEventSubscriber::NotifyDataShareReady() diff --git a/services/distributeddataservice/service/data_share/sys_event_subscriber.h b/services/distributeddataservice/service/data_share/sys_event_subscriber.h index b266387cc..a12070d7c 100644 --- a/services/distributeddataservice/service/data_share/sys_event_subscriber.h +++ b/services/distributeddataservice/service/data_share/sys_event_subscriber.h @@ -23,7 +23,7 @@ namespace OHOS::DataShare { class SysEventSubscriber : public EventFwk::CommonEventSubscriber { public: using SysEventCallback = void (SysEventSubscriber::*)(); - explicit SysEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info); + explicit SysEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info, std::shared_ptr executors); ~SysEventSubscriber() {} void OnReceiveEvent(const EventFwk::CommonEventData& event) override; void OnBMSReady(); @@ -31,6 +31,7 @@ public: private: void NotifyDataShareReady(); std::map callbacks_; + std::shared_ptr executors_ = nullptr; }; } #endif \ No newline at end of file -- Gitee