From c9dc52a365f7ae3fd82726d79172874f94ec816d Mon Sep 17 00:00:00 2001 From: mjh Date: Fri, 5 Sep 2025 16:42:00 +0800 Subject: [PATCH] Opt changeAppSwitch Signed-off-by: mjh --- .../src/data_sync/sync_state_manager.cpp | 10 ++- .../src/data_sync/task_state_manager.cpp | 2 + .../src/data_sync_manager.cpp | 2 +- .../src/sync_rule/cloud_status.cpp | 2 +- .../src/sync_rule/network_set_manager.cpp | 7 -- .../src/sync_rule/settings_data_manager.cpp | 65 +++++++++------ .../include/cloud_sync_manager_impl.h | 1 + .../src/cloud_sync_manager_impl.cpp | 13 ++- .../src/cloud_sync_service_proxy_lite.cpp | 2 +- .../cloud_file_kit_inner/cloud_status.h | 2 + .../cloud_file_kit_inner/data_sync_const.h | 2 +- .../cloud_file_kit_inner/data_sync_manager.h | 2 +- .../settings_data_manager.h | 9 ++- .../cloudsync_kit_inner/cloud_sync_manager.h | 8 ++ .../cloudsyncservice/ICloudSyncService.idl | 2 +- .../include/ipc/cloud_sync_service.h | 2 +- .../src/ipc/cloud_sync_service.cpp | 10 ++- .../src/sync_rule/user_status_listener.cpp | 2 + .../ani_core/cloud_sync_manager_mock.h | 1 + .../data_sync/sync_state_manager_test.cpp | 43 +++++++++- .../cloud_sync_manager_impl_test.cpp | 11 ++- .../include/i_cloud_sync_service_mock.h | 2 +- .../include/service_proxy_mock.h | 2 +- .../ipc/cloud_sync_service_stub_test.cpp | 2 +- .../mock/data_ability_observer_stub.cpp | 4 +- .../unittests/cloudsync_sa/sync_rule/BUILD.gn | 1 + .../sync_rule/settings_data_manager_test.cpp | 80 ++++++++++++++++--- utils/system/src/dfsu_access_token_helper.cpp | 2 +- 28 files changed, 221 insertions(+), 70 deletions(-) diff --git a/frameworks/native/cloud_file_kit_inner/src/data_sync/sync_state_manager.cpp b/frameworks/native/cloud_file_kit_inner/src/data_sync/sync_state_manager.cpp index 3268f0acc..fe5a5cf66 100644 --- a/frameworks/native/cloud_file_kit_inner/src/data_sync/sync_state_manager.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/data_sync/sync_state_manager.cpp @@ -19,6 +19,7 @@ #include #include "cloud_file_fault_event.h" +#include "cloud_status.h" #include "dfs_error.h" #include "utils_log.h" @@ -67,6 +68,11 @@ static bool ConvertToNumber(const std::string &str, uint64_t &val) bool SyncStateManager::CheckMediaLibCleaning() { + if (CloudStatus::isStopSync_.load()) { + LOGI("cloudfileservice in stop sync"); + return true; + } + std::string closeSwitchTime = system::GetParameter(CLOUDSYNC_SWITCH_STATUS, ""); LOGD("prev close time: %{public}s", closeSwitchTime.c_str()); if (closeSwitchTime.empty() || closeSwitchTime == "0") { @@ -83,10 +89,10 @@ bool SyncStateManager::CheckMediaLibCleaning() uint64_t curTime = GetCurrentTimeStampMs(); uint64_t intervalTime = curTime - prevTime; LOGI("media clean time: %{public}s, cur: %{public}s", closeSwitchTime.c_str(), std::to_string(curTime).c_str()); - if (prevTime > curTime || intervalTime >= TWELVE_HOURS_MILLISECOND) { + if (prevTime > curTime || intervalTime >= SIX_HOURS_MILLISECOND) { CLOUD_SYNC_FAULT_REPORT({"", CloudFile::FaultScenarioCode::CLOUD_SWITCH_CLOSE, CloudFile::FaultType::TIMEOUT, E_TIMEOUT, - "media clean time is: " + closeSwitchTime + " over 12h"}); + "media clean time is: " + closeSwitchTime + " over 6h"}); system::SetParameter(CLOUDSYNC_SWITCH_STATUS, "0"); return false; } diff --git a/frameworks/native/cloud_file_kit_inner/src/data_sync/task_state_manager.cpp b/frameworks/native/cloud_file_kit_inner/src/data_sync/task_state_manager.cpp index 00c616c21..032837d80 100644 --- a/frameworks/native/cloud_file_kit_inner/src/data_sync/task_state_manager.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/data_sync/task_state_manager.cpp @@ -19,6 +19,7 @@ #include "iservice_registry.h" #include "mem_mgr_client.h" #include "parameters.h" +#include "settings_data_manager.h" #include "system_ability_definition.h" #include "utils_log.h" @@ -150,6 +151,7 @@ void TaskStateManager::DelayUnloadTask(bool needSetCritical) LOGE("remove system ability failed"); return; } + SettingsDataManager::UnregisterObserver(); }; CancelUnloadTask(); diff --git a/frameworks/native/cloud_file_kit_inner/src/data_sync_manager.cpp b/frameworks/native/cloud_file_kit_inner/src/data_sync_manager.cpp index 9b998bf01..2960c4b45 100644 --- a/frameworks/native/cloud_file_kit_inner/src/data_sync_manager.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/data_sync_manager.cpp @@ -59,7 +59,7 @@ int32_t DataSyncManager::TriggerRecoverySync(SyncTriggerType triggerType) return E_OK; } -int32_t DataSyncManager::ResetCursor(const std::string &bundleName, const int32_t &userId) +int32_t DataSyncManager::ResetCursor(const std::string &bundleName, const int32_t &userId, bool flag) { return E_OK; } diff --git a/frameworks/native/cloud_file_kit_inner/src/sync_rule/cloud_status.cpp b/frameworks/native/cloud_file_kit_inner/src/sync_rule/cloud_status.cpp index 1226a50bf..65c7a2f72 100644 --- a/frameworks/native/cloud_file_kit_inner/src/sync_rule/cloud_status.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/sync_rule/cloud_status.cpp @@ -17,8 +17,8 @@ #include "cloud_file_kit.h" #include "dfs_error.h" -#include "utils_log.h" #include "settings_data_manager.h" +#include "utils_log.h" namespace OHOS::FileManagement::CloudSync { int32_t CloudStatus::GetCurrentCloudInfo(const std::string &bundleName, const int32_t userId) diff --git a/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_set_manager.cpp b/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_set_manager.cpp index 1c297a963..138f326ca 100644 --- a/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_set_manager.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_set_manager.cpp @@ -283,14 +283,7 @@ void NetworkSetManager::InitNetworkSetManager(const std::string &bundleName, con LOGI("InitNetworkSetManager bundleName: %{public}s", bundleName.c_str()); if (bundleName == GALLERY_BUNDLE_NAME) { RegisterObserver(bundleName, userId, CELLULARCONNECT); - RegisterObserver(bundleName, userId, NETCONNECT); GetCellularConnect(bundleName, userId); - GetNetConnect(bundleName, userId); - } else if (bundleName == HDC_BUNDLE_NAME) { - SettingsDataManager::GetNetworkConnectionStatus(); - SettingsDataManager::GetMobileDataStatus(); - } else { - LOGE("InitNetworkSetManager bundleName is illegals"); } } diff --git a/frameworks/native/cloud_file_kit_inner/src/sync_rule/settings_data_manager.cpp b/frameworks/native/cloud_file_kit_inner/src/sync_rule/settings_data_manager.cpp index b1f63bad1..e1d69f5eb 100644 --- a/frameworks/native/cloud_file_kit_inner/src/sync_rule/settings_data_manager.cpp +++ b/frameworks/native/cloud_file_kit_inner/src/sync_rule/settings_data_manager.cpp @@ -40,12 +40,18 @@ static const int32_t LOCAL_SPACE_DAYS_DEFAULT = 30; void SettingsDataManager::InitSettingsDataManager() { - LOGI("InitSettingsDataManager"); - RegisterObserver(SYNC_SWITCH_KEY); - RegisterObserver(NETWORK_CONNECTION_KEY); - RegisterObserver(MOBILE_DATA_SYNC_KEY); - RegisterObserver(LOCAL_SPACE_FREE_KEY); - RegisterObserver(LOCAL_SPACE_DAYS_KEY); + LOGI("InitSettingsDataManager start"); + SyncSwitchObserver_ = sptr(new (std::nothrow) SettingsDataObserver(SYNC_SWITCH_KEY)); + NetworkConnectionObserver_ = + sptr(new (std::nothrow) SettingsDataObserver(NETWORK_CONNECTION_KEY)); + MobileDataSyncObserver_ = sptr(new (std::nothrow) SettingsDataObserver(MOBILE_DATA_SYNC_KEY)); + LocalSpaceFreeObserver_ = sptr(new (std::nothrow) SettingsDataObserver(LOCAL_SPACE_FREE_KEY)); + LocalSpaceDaysObserver_ = sptr(new (std::nothrow) SettingsDataObserver(LOCAL_SPACE_DAYS_KEY)); + RegisterObserver(SYNC_SWITCH_KEY, SyncSwitchObserver_); + RegisterObserver(NETWORK_CONNECTION_KEY, NetworkConnectionObserver_); + RegisterObserver(MOBILE_DATA_SYNC_KEY, MobileDataSyncObserver_); + RegisterObserver(LOCAL_SPACE_FREE_KEY, LocalSpaceFreeObserver_); + RegisterObserver(LOCAL_SPACE_DAYS_KEY, LocalSpaceDaysObserver_); QuerySwitchStatus(); QueryNetworkConnectionStatus(); QueryLocalSpaceFreeStatus(); @@ -53,6 +59,21 @@ void SettingsDataManager::InitSettingsDataManager() QueryMobileDataStatus(); } +void SettingsDataManager::UnregisterObserver() +{ + LOGI("UnregisterObserver start"); + UnregisterObserver(SYNC_SWITCH_KEY, SyncSwitchObserver_); + UnregisterObserver(NETWORK_CONNECTION_KEY, NetworkConnectionObserver_); + UnregisterObserver(MOBILE_DATA_SYNC_KEY, MobileDataSyncObserver_); + UnregisterObserver(LOCAL_SPACE_FREE_KEY, LocalSpaceFreeObserver_); + UnregisterObserver(LOCAL_SPACE_DAYS_KEY, LocalSpaceDaysObserver_); + SyncSwitchObserver_ = nullptr; + NetworkConnectionObserver_ = nullptr; + MobileDataSyncObserver_ = nullptr; + LocalSpaceFreeObserver_ = nullptr; + LocalSpaceDaysObserver_ = nullptr; +} + int32_t SettingsDataManager::QuerySwitchStatus() { std::string value; @@ -258,30 +279,17 @@ int32_t SettingsDataManager::QueryParamInSettingsData(const std::string &key, st return E_RDB; } - LOGI("Query success, value: %{public}s", value.c_str()); + LOGI("Query key: %{public}s success, value: %{public}s", key.c_str(), value.c_str()); return E_OK; } -void SettingsDataManager::RegisterObserver(const std::string &key) +void SettingsDataManager::RegisterObserver(const std::string &key, sptr dataObserver) { - LOGD("register key: %{public}s", key.c_str()); - DataShare::CreateOptions options; - options.enabled_ = true; - auto dataShareHelper = DataShare::DataShareHelper::Creator(SETTING_DATA_QUERY_URI, options); - if (dataShareHelper == nullptr) { - LOGE("dataShareHelper == nullptr"); + if (dataObserver == nullptr) { + LOGW("registerObserver key: %{public}s dataObserver is nullptr", key.c_str()); return; } - sptr dataObserver(new (std::nothrow) SettingsDataObserver(key)); - Uri observerUri(SETTING_DATA_COMMON_URI + "&key=" + key); - dataShareHelper->RegisterObserver(observerUri, dataObserver); - dataShareHelper->Release(); - LOGI("Register SettingsDataObserver key: %{public}s finish", key.c_str()); -} -void SettingsDataManager::RegisterObserver(const std::string &key, sptr dataObserver) -{ - LOGD("register key: %{public}s", key.c_str()); DataShare::CreateOptions options; options.enabled_ = true; auto dataShareHelper = DataShare::DataShareHelper::Creator(SETTING_DATA_QUERY_URI, options); @@ -296,8 +304,13 @@ void SettingsDataManager::RegisterObserver(const std::string &key, sptr dataObserver) { + if (dataObserver == nullptr) { + LOGW("unregisterObserver key: %{public}s dataObserver is nullptr", key.c_str()); + return; + } + DataShare::CreateOptions options; options.enabled_ = true; auto dataShareHelper = DataShare::DataShareHelper::Creator(SETTING_DATA_QUERY_URI, options); @@ -305,7 +318,7 @@ void SettingsDataManager::UnregisterObserver(const std::string &key) LOGE("dataShareHelper == nullptr"); return; } - sptr dataObserver(new (std::nothrow) SettingsDataObserver(key)); + Uri observerUri(SETTING_DATA_COMMON_URI + "&key=" + key); dataShareHelper->UnregisterObserver(observerUri, dataObserver); dataShareHelper->Release(); @@ -314,7 +327,7 @@ void SettingsDataManager::UnregisterObserver(const std::string &key) void SettingsDataObserver::OnChange() { - LOGD("change key: %{public}s", key_.c_str()); + LOGI("change key: %{public}s", key_.c_str()); if (key_ == SYNC_SWITCH_KEY) { SettingsDataManager::QuerySwitchStatus(); } else if (key_ == NETWORK_CONNECTION_KEY) { diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h index de592796b..0fbafdc19 100644 --- a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h @@ -45,6 +45,7 @@ public: int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) override; int32_t StopFileSync(const std::string &bundleName = "", bool forceFlag = false) override; int32_t ResetCursor(const std::string &bundleName = "") override; + int32_t ResetCursor(bool flag, const std::string &bundleName = "") override; int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) override; int32_t OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions, const std::shared_ptr optimizeCallback = nullptr) override; diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index 3d9545568..0ada7d33a 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -271,7 +271,18 @@ int32_t CloudSyncManagerImpl::ResetCursor(const std::string &bundleName) return E_SA_LOAD_FAILED; } SetDeathRecipient(CloudSyncServiceProxy->AsObject()); - return CloudSyncServiceProxy->ResetCursor(bundleName); + return CloudSyncServiceProxy->ResetCursor(false, bundleName); +} + +int32_t CloudSyncManagerImpl::ResetCursor(bool flag, const std::string &bundleName) +{ + auto CloudSyncServiceProxy = ServiceProxy::GetInstance(); + if (!CloudSyncServiceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + SetDeathRecipient(CloudSyncServiceProxy->AsObject()); + return CloudSyncServiceProxy->ResetCursor(flag, bundleName); } int32_t CloudSyncManagerImpl::ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) diff --git a/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_service_proxy_lite.cpp b/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_service_proxy_lite.cpp index 5f8931eda..9a4e70873 100644 --- a/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_service_proxy_lite.cpp +++ b/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_service_proxy_lite.cpp @@ -194,7 +194,7 @@ int32_t CloudSyncServiceProxy::StopFileSyncInner(const std::string &bundleName, return E_OK; } -int32_t CloudSyncServiceProxy::ResetCursor(const std::string &bundleName) +int32_t CloudSyncServiceProxy::ResetCursor(bool flag, const std::string &bundleName) { return E_OK; } diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/cloud_status.h b/interfaces/inner_api/native/cloud_file_kit_inner/cloud_status.h index 3c631f903..c97dec992 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/cloud_status.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/cloud_status.h @@ -16,6 +16,7 @@ #ifndef OHOS_FILEMGMT_CLOUD_STATUS_H #define OHOS_FILEMGMT_CLOUD_STATUS_H +#include #include #include #include @@ -30,6 +31,7 @@ public: static bool IsCloudStatusOkay(const std::string &bundleName, const int32_t userId); static int32_t ChangeAppSwitch(const std::string &bundleName, const int32_t userId, bool appSwitchStatus); static bool IsAccountIdChanged(const std::string &accountId); + static inline std::atomic isStopSync_ = false; private: static inline CloudFile::CloudUserInfo userInfo_; diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h index cb21e60ac..d97abef0c 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h @@ -81,7 +81,7 @@ const int32_t DIRECTORY = 1; const int32_t MILLISECOND_TO_SECOND = 1000; const int32_t SECOND_TO_MILLISECOND = 1000; const int64_t MILLISECOND_TO_NANOSECOND = 1e6; -const uint64_t TWELVE_HOURS_MILLISECOND = 12 * 60 * 60 * SECOND_TO_MILLISECOND; +const uint64_t SIX_HOURS_MILLISECOND = 6 * 60 * 60 * SECOND_TO_MILLISECOND; const int32_t NOT_IN_TRASH = 0; const int32_t NOT_IN_PENDING = 0; diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_manager.h b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_manager.h index aef152d43..fe98a1813 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_manager.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_manager.h @@ -43,7 +43,7 @@ public: bool forceFlag, SyncTriggerType triggerType); virtual int32_t TriggerRecoverySync(SyncTriggerType triggerType); virtual int32_t StopUploadTask(const std::string &bundleName, const int32_t userId); - virtual int32_t ResetCursor(const std::string &bundleName, const int32_t &userId); + virtual int32_t ResetCursor(const std::string &bundleName, const int32_t &userId, bool flag = false); virtual void RegisterCloudSyncCallback(const std::string &bundleName, const std::string &callerBundleName, const int32_t userId, diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/settings_data_manager.h b/interfaces/inner_api/native/cloud_file_kit_inner/settings_data_manager.h index e40783570..da11ea8b9 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/settings_data_manager.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/settings_data_manager.h @@ -55,14 +55,19 @@ public: static int32_t GetLocalSpaceFreeStatus(); static int32_t GetLocalSpaceFreeDays(); - static void RegisterObserver(const std::string &key); static void RegisterObserver(const std::string &key, sptr dataObserver); + static void UnregisterObserver(); private: static int32_t QueryParamInSettingsData(const std::string &key, std::string &value); - static void UnregisterObserver(const std::string &key); + static void UnregisterObserver(const std::string &key, sptr dataObserver); static inline SafeMap settingsDataMap_; + static inline sptr SyncSwitchObserver_ = nullptr; + static inline sptr NetworkConnectionObserver_ = nullptr; + static inline sptr MobileDataSyncObserver_ = nullptr; + static inline sptr LocalSpaceFreeObserver_ = nullptr; + static inline sptr LocalSpaceDaysObserver_ = nullptr; }; } // OHOS diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h index c221ba977..fd52e59c7 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h +++ b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h @@ -82,6 +82,14 @@ public: * @return int32_t 同步返回执行结果 */ virtual int32_t ResetCursor(const std::string &bundleName = "") = 0; + /** + * @brief 清理水位 + * + * @param flag 状态位 + * @param bundleName 应用包名 + * @return int32_t 同步返回执行结果 + */ + virtual int32_t ResetCursor(bool flag, const std::string &bundleName = "") = 0; /** * @brief 切换应用云同步开关 * diff --git a/services/cloudsyncservice/ICloudSyncService.idl b/services/cloudsyncservice/ICloudSyncService.idl index fd6bef38b..2891a3c90 100644 --- a/services/cloudsyncservice/ICloudSyncService.idl +++ b/services/cloudsyncservice/ICloudSyncService.idl @@ -35,7 +35,7 @@ interface OHOS.FileManagement.CloudSync.ICloudSyncService void TriggerSyncInner([in] String bundleName, [in] int userId); void StopSyncInner([in] String bundleName, [in] boolean forceFlag); void StopFileSyncInner([in] String bundleName, [in] boolean forceFlag); - void ResetCursor([in] String bundleName); + void ResetCursor([in] boolean flag, [in] String bundleName); void ChangeAppSwitch([in] String accoutId, [in] String bundleName, [in] boolean status); void OptimizeStorage([in] OptimizeSpaceOptions optimizeOptions, [in] boolean isCallbackValid, [in] IRemoteObject optimizeCallback); diff --git a/services/cloudsyncservice/include/ipc/cloud_sync_service.h b/services/cloudsyncservice/include/ipc/cloud_sync_service.h index e19c0abe3..e2ff2d4c5 100644 --- a/services/cloudsyncservice/include/ipc/cloud_sync_service.h +++ b/services/cloudsyncservice/include/ipc/cloud_sync_service.h @@ -52,7 +52,7 @@ public: ErrCode TriggerSyncInner(const std::string &bundleName, int32_t userId) override; ErrCode StopSyncInner(const std::string &bundleName = "", bool forceFlag = false) override; ErrCode StopFileSyncInner(const std::string &bundleName = "", bool forceFlag = false) override; - ErrCode ResetCursor(const std::string &bundleName = "") override; + ErrCode ResetCursor(bool flag = false, const std::string &bundleName = "") override; ErrCode OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions, bool isCallbackValid, const sptr &optimizeCallback) override; diff --git a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp index a353e07ce..e69e67368 100644 --- a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp +++ b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp @@ -561,7 +561,7 @@ int32_t CloudSyncService::StopFileSyncInner(const string &bundleName, bool force return ret; } -int32_t CloudSyncService::ResetCursor(const string &bundleName) +int32_t CloudSyncService::ResetCursor(bool flag, const string &bundleName) { LOGI("Begin ResetCursor"); RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_SYNC, true)); @@ -574,7 +574,7 @@ int32_t CloudSyncService::ResetCursor(const string &bundleName) return ret; } auto callerUserId = DfsuAccessTokenHelper::GetUserId(); - ret = dataSyncManager_->ResetCursor(targetBundleName, callerUserId); + ret = dataSyncManager_->ResetCursor(targetBundleName, callerUserId, flag); LOGI("End ResetCursor"); return ret; } @@ -715,6 +715,9 @@ int32_t CloudSyncService::ChangeAppSwitch(const std::string &accoutId, const std } } else { system::SetParameter(CLOUDSYNC_STATUS_KEY, CLOUDSYNC_STATUS_SWITCHOFF); + if (bundleName == HDC_BUNDLE_NAME || bundleName == GALLERY_BUNDLE_NAME) { + CloudStatus::isStopSync_.store(true); + } ret = dataSyncManager_->StopSyncSynced(bundleName, callerUserId, false, SyncTriggerType::CLOUD_TRIGGER); if (ret != E_OK) { LOGE("StopSyncSynced failed, ret: %{public}d", ret); @@ -722,6 +725,9 @@ int32_t CloudSyncService::ChangeAppSwitch(const std::string &accoutId, const std } ret = dataSyncManager_->ChangeAppSwitch(bundleName, callerUserId, status); + if (!status && (bundleName == HDC_BUNDLE_NAME || bundleName == GALLERY_BUNDLE_NAME)) { + CloudStatus::isStopSync_.store(false); + } LOGI("End ChangeAppSwitch"); return ret; } diff --git a/services/cloudsyncservice/src/sync_rule/user_status_listener.cpp b/services/cloudsyncservice/src/sync_rule/user_status_listener.cpp index af36303b6..50c564d88 100644 --- a/services/cloudsyncservice/src/sync_rule/user_status_listener.cpp +++ b/services/cloudsyncservice/src/sync_rule/user_status_listener.cpp @@ -19,6 +19,7 @@ #include "common_event_support.h" #include "iservice_registry.h" #include "parameters.h" +#include "settings_data_manager.h" #include "system_ability_definition.h" #include "task_state_manager.h" #include "utils_log.h" @@ -113,6 +114,7 @@ void UserStatusListener::DoUnloadSA() LOGE("remove system ability failed"); return; } + SettingsDataManager::UnregisterObserver(); LOGI("unload cloudfileservice end"); } } // namespace OHOS::FileManagement::CloudSync \ No newline at end of file diff --git a/test/unittests/ani_core/cloud_sync_manager_mock.h b/test/unittests/ani_core/cloud_sync_manager_mock.h index 9e5b73232..db3ddff09 100644 --- a/test/unittests/ani_core/cloud_sync_manager_mock.h +++ b/test/unittests/ani_core/cloud_sync_manager_mock.h @@ -41,6 +41,7 @@ public: MOCK_METHOD2(StopSync, int32_t(const std::string &bundleName, bool forceFlag)); MOCK_METHOD2(StopFileSync, int32_t(const std::string &bundleName, bool forceFlag)); MOCK_METHOD1(ResetCursor, int32_t(const std::string &bundleName)); + MOCK_METHOD2(ResetCursor, int32_t(bool flag, const std::string &bundleName)); MOCK_METHOD3(ChangeAppSwitch, int32_t(const std::string &accoutId, const std::string &bundleName, bool status)); MOCK_METHOD2(OptimizeStorage, int32_t(const OptimizeSpaceOptions &optimizeOptions, const std::shared_ptr optimizeCallback)); diff --git a/test/unittests/cloud_file_kit_inner/data_sync/sync_state_manager_test.cpp b/test/unittests/cloud_file_kit_inner/data_sync/sync_state_manager_test.cpp index 356d13c93..36d1b2371 100644 --- a/test/unittests/cloud_file_kit_inner/data_sync/sync_state_manager_test.cpp +++ b/test/unittests/cloud_file_kit_inner/data_sync/sync_state_manager_test.cpp @@ -12,11 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include "sync_state_manager.h" + #include #include -#include "sync_state_manager.h" -#include "system_mock.h" + +#include "cloud_status.h" #include "data_sync_const.h" +#include "system_mock.h" namespace OHOS::FileManagement::CloudSync::Test { using namespace testing; @@ -512,6 +516,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_001, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_001 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return("")); @@ -531,6 +536,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_002, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_002 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return("0")); @@ -550,6 +556,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_003, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_003 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return("xxx")); @@ -570,6 +577,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_004, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_004 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return("10xx")); @@ -590,6 +598,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_005, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_005 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return(" 10")); @@ -610,6 +619,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_006, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_006 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return("10 ")); @@ -630,9 +640,10 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_007, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_007 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; - uint64_t curTime = GetCurrentTimeStampMs() - TWELVE_HOURS_MILLISECOND; + uint64_t curTime = GetCurrentTimeStampMs() - SIX_HOURS_MILLISECOND; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillRepeatedly(Return(std::to_string(curTime))); EXPECT_CALL(*systemMock, SetParameter(_, _)).WillRepeatedly(Return(true)); SyncStateManager syncStateManager; @@ -651,6 +662,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_008, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_008 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; uint64_t curTime = GetCurrentTimeStampMs() - 10; @@ -671,6 +683,7 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_009, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_009 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; uint64_t curTime = GetCurrentTimeStampMs() + 10; @@ -692,9 +705,10 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_010, TestSize.Level1) { GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_010 start"; try { + CloudStatus::isStopSync_.store(false); std::shared_ptr systemMock = std::make_shared(); ISystem::system_ = systemMock; - uint64_t curTime = GetCurrentTimeStampMs() - TWELVE_HOURS_MILLISECOND + 50000; + uint64_t curTime = GetCurrentTimeStampMs() - SIX_HOURS_MILLISECOND + 50000; EXPECT_CALL(*systemMock, GetParameter(_, _)).WillOnce(Return(std::to_string(curTime))); SyncStateManager syncStateManager; bool ret = syncStateManager.CheckMediaLibCleaning(); @@ -707,4 +721,25 @@ HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_010, TestSize.Level1) } GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_010 End"; } + +HWTEST_F(SyncStateManagerTest, CheckMediaLibCleaningTest_011, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_011 start"; + try { + CloudStatus::isStopSync_.store(true); + std::shared_ptr systemMock = std::make_shared(); + ISystem::system_ = systemMock; + EXPECT_CALL(*systemMock, GetParameter(_, _)).Times(0); + SyncStateManager syncStateManager; + bool ret = syncStateManager.CheckMediaLibCleaning(); + EXPECT_EQ(ret, true); + + ISystem::system_ = nullptr; + CloudStatus::isStopSync_.store(false); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_011 ERROR"; + } + GTEST_LOG_(INFO) << "CheckMediaLibCleaningTest_011 End"; +} } \ No newline at end of file diff --git a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp index ec2f9db67..c61dca359 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp +++ b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp @@ -581,11 +581,20 @@ HWTEST_F(CloudSyncManagerImplTest, ResetCursorTest, TestSize.Level1) { string bundleName = "com.ohos.photos"; EXPECT_CALL(*proxy_, GetInstance()).WillOnce(Return(serviceProxy_)); - EXPECT_CALL(*serviceProxy_, ResetCursor(_)).WillOnce(Return(E_PERMISSION_DENIED)); + EXPECT_CALL(*serviceProxy_, ResetCursor(_, _)).WillOnce(Return(E_PERMISSION_DENIED)); int res = CloudSyncManagerImpl::GetInstance().ResetCursor(bundleName); EXPECT_EQ(res, E_PERMISSION_DENIED); } +HWTEST_F(CloudSyncManagerImplTest, ResetCursorTest002, TestSize.Level1) +{ + string bundleName = "com.ohos.photos"; + EXPECT_CALL(*proxy_, GetInstance()).WillOnce(Return(serviceProxy_)); + EXPECT_CALL(*serviceProxy_, ResetCursor(_, _)).WillOnce(Return(E_PERMISSION_DENIED)); + int res = CloudSyncManagerImpl::GetInstance().ResetCursor(false, bundleName); + EXPECT_EQ(res, E_PERMISSION_DENIED); +} + HWTEST_F(CloudSyncManagerImplTest, DownloadThumbTest, TestSize.Level1) { EXPECT_CALL(*proxy_, GetInstance()).WillOnce(Return(serviceProxy_)); diff --git a/test/unittests/cloudsync_api/cloudsync_impl/include/i_cloud_sync_service_mock.h b/test/unittests/cloudsync_api/cloudsync_impl/include/i_cloud_sync_service_mock.h index ecfe4a624..c90a9a99d 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/include/i_cloud_sync_service_mock.h +++ b/test/unittests/cloudsync_api/cloudsync_impl/include/i_cloud_sync_service_mock.h @@ -87,7 +87,7 @@ public: return E_OK; } - int32_t ResetCursor(const std::string &bundleName = "") override + int32_t ResetCursor(bool flag = false, const std::string &bundleName = "") override { return E_OK; } diff --git a/test/unittests/cloudsync_api/cloudsync_impl/include/service_proxy_mock.h b/test/unittests/cloudsync_api/cloudsync_impl/include/service_proxy_mock.h index 99ac86a60..854705877 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/include/service_proxy_mock.h +++ b/test/unittests/cloudsync_api/cloudsync_impl/include/service_proxy_mock.h @@ -43,7 +43,7 @@ public: MOCK_METHOD2(TriggerSyncInner, int32_t(const std::string &bundleName, int32_t userId)); MOCK_METHOD2(StopSyncInner, int32_t(const std::string &bundleName, bool forceFlag)); MOCK_METHOD2(StopFileSyncInner, int32_t(const std::string &bundleName, bool forceFlag)); - MOCK_METHOD1(ResetCursor, int32_t(const std::string &bundleName)); + MOCK_METHOD2(ResetCursor, int32_t(bool flag, const std::string &bundleName)); MOCK_METHOD3(ChangeAppSwitch, int32_t(const std::string &accoutId, const std::string &bundleName, bool status)); MOCK_METHOD3(OptimizeStorage, int32_t(const OptimizeSpaceOptions &optimizeOptions, diff --git a/test/unittests/cloudsync_sa/ipc/cloud_sync_service_stub_test.cpp b/test/unittests/cloudsync_sa/ipc/cloud_sync_service_stub_test.cpp index 136cc4498..94fec32d3 100644 --- a/test/unittests/cloudsync_sa/ipc/cloud_sync_service_stub_test.cpp +++ b/test/unittests/cloudsync_sa/ipc/cloud_sync_service_stub_test.cpp @@ -42,7 +42,7 @@ public: MOCK_METHOD2(TriggerSyncInner, int32_t(const std::string &bundleName, const int32_t &userId)); MOCK_METHOD2(StopSyncInner, int32_t(const std::string &bundleName, bool forceFlag)); MOCK_METHOD2(StopFileSyncInner, int32_t(const std::string &bundleName, bool forceFlag)); - MOCK_METHOD1(ResetCursor, int32_t(const std::string &bundleName)); + MOCK_METHOD2(ResetCursor, int32_t(bool flag, const std::string &bundleName)); MOCK_METHOD3(ChangeAppSwitch, int32_t(const std::string &accoutId, const std::string &bundleName, bool status)); MOCK_METHOD2(Clean, int32_t(const std::string &accountId, const CleanOptions &cleanOptions)); MOCK_METHOD2(NotifyDataChange, int32_t(const std::string &accoutId, const std::string &bundleName)); diff --git a/test/unittests/cloudsync_sa/mock/data_ability_observer_stub.cpp b/test/unittests/cloudsync_sa/mock/data_ability_observer_stub.cpp index 6a7b78f9d..67138d96c 100644 --- a/test/unittests/cloudsync_sa/mock/data_ability_observer_stub.cpp +++ b/test/unittests/cloudsync_sa/mock/data_ability_observer_stub.cpp @@ -15,12 +15,12 @@ #include "data_ability_observer_stub.h" +#include "common_utils.h" +#include "dataobs_mgr_changeinfo.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "ipc_skeleton.h" -#include "common_utils.h" #include "string_ex.h" -#include "dataobs_mgr_changeinfo.h" namespace OHOS { namespace AAFwk { diff --git a/test/unittests/cloudsync_sa/sync_rule/BUILD.gn b/test/unittests/cloudsync_sa/sync_rule/BUILD.gn index b3b3e56cd..c1ffceb09 100644 --- a/test/unittests/cloudsync_sa/sync_rule/BUILD.gn +++ b/test/unittests/cloudsync_sa/sync_rule/BUILD.gn @@ -490,6 +490,7 @@ ohos_unittest("user_status_listener_test") { external_deps = [ "ability_base:want", + "ability_runtime:dataobs_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", diff --git a/test/unittests/cloudsync_sa/sync_rule/settings_data_manager_test.cpp b/test/unittests/cloudsync_sa/sync_rule/settings_data_manager_test.cpp index 6454db279..bc021ae0a 100644 --- a/test/unittests/cloudsync_sa/sync_rule/settings_data_manager_test.cpp +++ b/test/unittests/cloudsync_sa/sync_rule/settings_data_manager_test.cpp @@ -70,6 +70,32 @@ void SettingsDataManagerTest::SetUp(void) void SettingsDataManagerTest::TearDown(void) {} +HWTEST_F(SettingsDataManagerTest, UnregisterObserverTest000, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnregisterObserverTest000 Start"; + DataShareResultSetMock::proxy_ = nullptr; + SettingsDataManager::UnregisterObserver(); + EXPECT_EQ(SettingsDataManager::SyncSwitchObserver_, nullptr); + EXPECT_EQ(SettingsDataManager::NetworkConnectionObserver_, nullptr); + EXPECT_EQ(SettingsDataManager::MobileDataSyncObserver_, nullptr); + EXPECT_EQ(SettingsDataManager::LocalSpaceFreeObserver_, nullptr); + EXPECT_EQ(SettingsDataManager::LocalSpaceDaysObserver_, nullptr); + GTEST_LOG_(INFO) << "UnregisterObserverTest000 End"; +} + +HWTEST_F(SettingsDataManagerTest, InitSettingsDataManagerTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "InitSettingsDataManagerTest001 Start"; + DataShareResultSetMock::proxy_ = nullptr; + SettingsDataManager::InitSettingsDataManager(); + EXPECT_NE(SettingsDataManager::SyncSwitchObserver_, nullptr); + EXPECT_NE(SettingsDataManager::NetworkConnectionObserver_, nullptr); + EXPECT_NE(SettingsDataManager::MobileDataSyncObserver_, nullptr); + EXPECT_NE(SettingsDataManager::LocalSpaceFreeObserver_, nullptr); + EXPECT_NE(SettingsDataManager::LocalSpaceDaysObserver_, nullptr); + GTEST_LOG_(INFO) << "InitSettingsDataManagerTest001 End"; +} + HWTEST_F(SettingsDataManagerTest, QueryParamInSettingsDataTest001, TestSize.Level1) { GTEST_LOG_(INFO) << "QueryParamInSettingsDataTest001 Start"; @@ -508,8 +534,9 @@ HWTEST_F(SettingsDataManagerTest, RegisterObserverTest001, TestSize.Level1) GTEST_LOG_(INFO) << "RegisterObserverTest001 Start"; EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(nullptr)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::RegisterObserver(""); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::RegisterObserver("", dataObserver); GTEST_LOG_(INFO) << "RegisterObserverTest001 End"; } @@ -520,8 +547,9 @@ HWTEST_F(SettingsDataManagerTest, RegisterObserverTest002, TestSize.Level1) std::shared_ptr dataShareHelper = std::make_shared(); EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(dataShareHelper)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::RegisterObserver(""); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::RegisterObserver("", dataObserver); GTEST_LOG_(INFO) << "RegisterObserverTest002 End"; } @@ -531,8 +559,9 @@ HWTEST_F(SettingsDataManagerTest, RegisterObserverTest003, TestSize.Level1) GTEST_LOG_(INFO) << "RegisterObserverTest003 Start"; EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(nullptr)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::RegisterObserver("", nullptr); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::RegisterObserver("", dataObserver); GTEST_LOG_(INFO) << "RegisterObserverTest003 End"; } @@ -543,19 +572,33 @@ HWTEST_F(SettingsDataManagerTest, RegisterObserverTest004, TestSize.Level1) std::shared_ptr dataShareHelper = std::make_shared(); EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(dataShareHelper)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::RegisterObserver("", nullptr); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::RegisterObserver("", dataObserver); GTEST_LOG_(INFO) << "RegisterObserverTest004 End"; } +HWTEST_F(SettingsDataManagerTest, RegisterObserverTest005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterObserverTest005 Start"; + std::shared_ptr dataShareHelper = std::make_shared(); + EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).Times(0); + EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); + sptr dataObserver = nullptr; + SettingsDataManager::RegisterObserver("", dataObserver); + + GTEST_LOG_(INFO) << "RegisterObserverTest005 End"; +} + HWTEST_F(SettingsDataManagerTest, UnregisterObserverTest001, TestSize.Level1) { GTEST_LOG_(INFO) << "UnregisterObserverTest001 Start"; EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(nullptr)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::UnregisterObserver(""); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::UnregisterObserver("", dataObserver); GTEST_LOG_(INFO) << "UnregisterObserverTest001 End"; } @@ -566,12 +609,25 @@ HWTEST_F(SettingsDataManagerTest, UnregisterObserverTest002, TestSize.Level1) std::shared_ptr dataShareHelper = std::make_shared(); EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).WillOnce(Return(dataShareHelper)); EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); - SettingsDataManager::UnregisterObserver(""); - EXPECT_TRUE(true); + sptr dataObserver = + sptr(new (std::nothrow) SettingsDataObserver("")); + SettingsDataManager::UnregisterObserver("", dataObserver); GTEST_LOG_(INFO) << "UnregisterObserverTest002 End"; } +HWTEST_F(SettingsDataManagerTest, UnregisterObserverTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnregisterObserverTest003 Start"; + std::shared_ptr dataShareHelper = std::make_shared(); + EXPECT_CALL(*dataShareHelperMock_, Creator(_, _, _)).Times(0); + EXPECT_CALL(*dataShareHelperMock_, Query(_, _, _, _)).Times(0); + sptr dataObserver = nullptr; + SettingsDataManager::UnregisterObserver("", dataObserver); + + GTEST_LOG_(INFO) << "UnregisterObserverTest003 End"; +} + HWTEST_F(SettingsDataManagerTest, QueryTest001, TestSize.Level1) { GTEST_LOG_(INFO) << "QueryTest001 Start"; diff --git a/utils/system/src/dfsu_access_token_helper.cpp b/utils/system/src/dfsu_access_token_helper.cpp index a8209de3a..cbccb9ff3 100644 --- a/utils/system/src/dfsu_access_token_helper.cpp +++ b/utils/system/src/dfsu_access_token_helper.cpp @@ -18,12 +18,12 @@ #include "dfs_error.h" #include "dfsu_access_token_helper.h" #include "ipc_skeleton.h" +#include "os_account_manager.h" #include "tokenid_kit.h" #include "uri_permission_manager_client.h" #include "uri.h" #include "utils_log.h" #include "want.h" -#include "os_account_manager.h" namespace OHOS::FileManagement { using namespace std; -- Gitee