diff --git a/services/distributed/include/distributed_database.h b/services/distributed/include/distributed_database.h index c9faa48d6fbacc374a33c27c4583c0678ce1956d..6833350eac45e0863a6277e3e0dbb013cad50b2e 100644 --- a/services/distributed/include/distributed_database.h +++ b/services/distributed/include/distributed_database.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -47,7 +47,7 @@ public: /** * @brief The deconstructor. */ - ~DistributedDatabase(); + virtual ~DistributedDatabase(); /** * @brief Put a key-value to database. @@ -126,28 +126,26 @@ public: bool OnDeviceConnected(); private: - void GetKvDataManager(void); - bool CheckKvDataManager(void); - void GetKvStore(void); - bool CheckKvStore(void); + void GetKvDataManager(); + bool CheckKvDataManager(); + void GetKvStore(); + bool CheckKvStore(); -private: std::mutex mutex_; std::unique_ptr kvDataManager_; std::shared_ptr kvStore_; std::shared_ptr databaseCb_; std::shared_ptr deviceCb_; std::shared_ptr initCallback_; - std::string localDeviceId_; -class DeviceInitCallBack : public DistributedHardware::DmInitCallback { - void OnRemoteDied() override; -}; + class DeviceInitCallBack : public DistributedHardware::DmInitCallback { + public: + void OnRemoteDied() override; + }; DISALLOW_COPY_AND_MOVE(DistributedDatabase); }; } // namespace Notification } // namespace OHOS - #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_DATABASE_H \ No newline at end of file diff --git a/services/distributed/include/distributed_database_callback.h b/services/distributed/include/distributed_database_callback.h index f5cfdb0082223b02141e97c0e43005d2dad7cc62..82c88bc0798481c9e3411b00aef2f6af72d621cc 100644 --- a/services/distributed/include/distributed_database_callback.h +++ b/services/distributed/include/distributed_database_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -43,15 +43,13 @@ public: /** * @brief The deconstructor. */ - ~DistributedDatabaseCallback(); + virtual ~DistributedDatabaseCallback(); private: void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; -private: IDatabaseChange callback_; }; } // namespace Notification } // namespace OHOS - #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_DATABASE_CALLBACK_H \ No newline at end of file diff --git a/services/distributed/include/distributed_device_callback.h b/services/distributed/include/distributed_device_callback.h index a47358d27e12f32c0bb3a429dd96c04f62a289e8..3cda760edaaee35c92de360a19b670a7d0931087 100644 --- a/services/distributed/include/distributed_device_callback.h +++ b/services/distributed/include/distributed_device_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -43,7 +43,7 @@ public: /** * @brief The deconstructor. */ - ~DistributedDeviceCallback(); + virtual ~DistributedDeviceCallback(); private: void OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; @@ -51,10 +51,8 @@ private: void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override; void OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) override; -private: IDeviceChange callback_; }; } // namespace Notification } // namespace OHOS - #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_DEVICE_CALLBACK_H \ No newline at end of file diff --git a/services/distributed/include/distributed_flow_control.h b/services/distributed/include/distributed_flow_control.h index 22e945c34e0b1604716567665354ba1dfdf20e18..a79c2ccfcc867334ad18607b56799e683af2e77f 100644 --- a/services/distributed/include/distributed_flow_control.h +++ b/services/distributed/include/distributed_flow_control.h @@ -41,24 +41,24 @@ public: * * @return True on passed, otherwise false. */ - bool KvManagerFlowControl(void); + bool KvManagerFlowControl(); /** * @brief Check if SingleKvStore interface flow control can pass. * * @return True on passed, otherwise false. */ - bool KvStoreFlowControl(void); + bool KvStoreFlowControl(); /** * @brief Clear DistributedKvDataManager interface flow control count. */ - void KvManagerFlowControlClear(void); + void KvManagerFlowControlClear(); /** * @brief Clear SingleKvStore interface flow control count. */ - void KvStoreFlowControlClear(void); + void KvStoreFlowControlClear(); protected: static const size_t KVMANAGER_MAXINUM_PER_SECOND = 50; @@ -76,5 +76,4 @@ private: }; } // namespace Notification } // namespace OHOS - #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_FLOW_CONTROL_H \ No newline at end of file diff --git a/services/distributed/include/distributed_notification_manager.h b/services/distributed/include/distributed_notification_manager.h index 7a493347a94770b995b27f68d361a7261eb4ad68..d25604ca85d78e5aa34129c364499ffc887a1f9a 100644 --- a/services/distributed/include/distributed_notification_manager.h +++ b/services/distributed/include/distributed_notification_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -107,7 +107,7 @@ public: * * @return ErrCode Returns the unregister result. */ - ErrCode UngegisterCallback(void); + ErrCode UngegisterCallback(); /** * @brief Get all distributed notification in database. diff --git a/services/distributed/include/distributed_preferences.h b/services/distributed/include/distributed_preferences.h index 35e34a73ae9beebf0a2699e6a2d3b5173fd481eb..4f6853a149c3f598683b60514d629c02a420f5d3 100644 --- a/services/distributed/include/distributed_preferences.h +++ b/services/distributed/include/distributed_preferences.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -91,17 +91,15 @@ public: ErrCode GetSyncEnabledWithoutApp(const int32_t userId, bool &enabled); private: - bool InitDistributedAllInfo(void); + bool InitDistributedAllInfo(); void GetDistributedMainKey(std::string &key); void GetDistributedBundleKey(const sptr &bundleOption, std::string &key); bool ResolveDistributedKey(const DistributedKv::Entry &entry); void GetEnabledWithoutApp(const int32_t userId, std::string &key); - bool ResolveDistributedEnable(const std::string &value); bool ResolveDistributedBundleEnable(const std::string &key, const int32_t startPos, const std::string &value); bool ResolveSyncWithoutAppEnable(const std::string &key, const int32_t startPos, const std::string &value); -private: std::unique_ptr preferencesInfo_ = nullptr; std::unique_ptr database_ = nullptr; diff --git a/services/distributed/include/distributed_preferences_database.h b/services/distributed/include/distributed_preferences_database.h index 1fc06ba15189fe78cd17709b5a40df5bf3bf9bde..b291bd14a18cab621ab33b809ab2a5eb9c6ad586 100644 --- a/services/distributed/include/distributed_preferences_database.h +++ b/services/distributed/include/distributed_preferences_database.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -34,7 +34,7 @@ public: using Entry = DistributedKv::Entry; DistributedPreferencesDatabase(); - ~DistributedPreferencesDatabase(); + virtual ~DistributedPreferencesDatabase(); /** * @brief Put a key-value to database. @@ -76,16 +76,15 @@ public: * * @return Whether to clear database success. */ - bool ClearDatabase(void); + bool ClearDatabase(); private: - void GetKvDataManager(void); - bool CheckKvDataManager(void); - void GetKvStore(void); - bool CheckKvStore(void); + void GetKvDataManager(); + bool CheckKvDataManager(); + void GetKvStore(); + bool CheckKvStore(); void CloseKvStore(); -private: std::mutex mutex_; std::unique_ptr kvDataManager_; std::shared_ptr kvStore_; diff --git a/services/distributed/include/distributed_preferences_info.h b/services/distributed/include/distributed_preferences_info.h index 8548fa15175a6a67332f44e192031e56a4cc83b3..caafab0b041df5986235fa3b95f86a2254cc51ee 100644 --- a/services/distributed/include/distributed_preferences_info.h +++ b/services/distributed/include/distributed_preferences_info.h @@ -40,7 +40,7 @@ public: * * @return True if the device supports distributed notification; false otherwise. */ - bool GetDistributedEnable(void); + bool GetDistributedEnable(); /** * @brief Set whether an application supports distributed notifications. diff --git a/services/distributed/include/distributed_screen_status_manager.h b/services/distributed/include/distributed_screen_status_manager.h index 0b71223a25fc82f4e1823d017a1df3095e775c38..48054e7c9485d2699d9478d92ffd8416d9bf2f1b 100644 --- a/services/distributed/include/distributed_screen_status_manager.h +++ b/services/distributed/include/distributed_screen_status_manager.h @@ -51,10 +51,10 @@ private: void OnDeviceConnected(const std::string &deviceId); void OnDeviceDisconnected(const std::string &deviceId); - void GetKvDataManager(void); - bool CheckKvDataManager(void); - void GetKvStore(void); - bool CheckKvStore(void); + void GetKvDataManager(); + bool CheckKvDataManager(); + void GetKvStore(); + bool CheckKvStore(); std::string GenerateDistributedKey(const std::string &deviceId); @@ -69,9 +69,10 @@ private: bool localScreenOn_ = false; -class DeviceInitCallBack : public DistributedHardware::DmInitCallback { - void OnRemoteDied() override; -}; + class DeviceInitCallBack : public DistributedHardware::DmInitCallback { + public: + void OnRemoteDied() override; + }; DECLARE_DELAYED_SINGLETON(DistributedScreenStatusManager); DISALLOW_COPY_AND_MOVE(DistributedScreenStatusManager); diff --git a/services/distributed/src/distributed_database.cpp b/services/distributed/src/distributed_database.cpp index 59c2ba03bdff5507e4bbafb74051eb96e7eadbb1..3567f82519f797fe2fd71f0a7b2e6f54759732f3 100644 --- a/services/distributed/src/distributed_database.cpp +++ b/services/distributed/src/distributed_database.cpp @@ -36,7 +36,7 @@ DistributedDatabase::DistributedDatabase( DistributedDatabase::~DistributedDatabase() {} -void DistributedDatabase::GetKvDataManager(void) +void DistributedDatabase::GetKvDataManager() { initCallback_ = std::make_shared(); int32_t ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(APP_ID + STORE_ID, initCallback_); @@ -59,7 +59,7 @@ void DistributedDatabase::DeviceInitCallBack::OnRemoteDied() ANS_LOGW("DeviceInitCallBack OnRemoteDied"); } -bool DistributedDatabase::CheckKvDataManager(void) +bool DistributedDatabase::CheckKvDataManager() { if (kvDataManager_ == nullptr) { GetKvDataManager(); @@ -71,7 +71,7 @@ bool DistributedDatabase::CheckKvDataManager(void) return true; } -void DistributedDatabase::GetKvStore(void) +void DistributedDatabase::GetKvStore() { if (!CheckKvDataManager()) { return; @@ -107,7 +107,7 @@ void DistributedDatabase::GetKvStore(void) KvStoreFlowControlClear(); } -bool DistributedDatabase::CheckKvStore(void) +bool DistributedDatabase::CheckKvStore() { std::lock_guard lock(mutex_); if (kvStore_ == nullptr) { diff --git a/services/distributed/src/distributed_database_callback.cpp b/services/distributed/src/distributed_database_callback.cpp index ee088ec92a8561a6a712215c43b71729f3531c61..a166aa62d8b058e95e29ea39d1c1a5d757752d21 100644 --- a/services/distributed/src/distributed_database_callback.cpp +++ b/services/distributed/src/distributed_database_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -27,9 +27,9 @@ DistributedDatabaseCallback::~DistributedDatabaseCallback() void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotification &changeNotification) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); - if (callback_.OnInsert) { + if (callback_.OnInsert != nullptr) { const std::vector &entryList = changeNotification.GetInsertEntries(); ANS_LOGI("GetInsertEntries count %{public}zu", entryList.size()); for (auto entry : entryList) { @@ -37,7 +37,7 @@ void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotificati } } - if (callback_.OnUpdate) { + if (callback_.OnUpdate != nullptr) { const std::vector &entryList = changeNotification.GetUpdateEntries(); ANS_LOGI("GetUpdateEntries count %{public}zu", entryList.size()); for (auto entry : entryList) { @@ -45,7 +45,7 @@ void DistributedDatabaseCallback::OnChange(const DistributedKv::ChangeNotificati } } - if (callback_.OnDelete) { + if (callback_.OnDelete != nullptr) { const std::vector &entryList = changeNotification.GetDeleteEntries(); ANS_LOGI("GetDeleteEntries count %{public}zu", entryList.size()); for (auto entry : entryList) { diff --git a/services/distributed/src/distributed_flow_control.cpp b/services/distributed/src/distributed_flow_control.cpp index de58271022ef6cb13dbe6004ca2c101b8d629274..c45d71d5a136f81f60056fab185ddc10ffdc3763 100644 --- a/services/distributed/src/distributed_flow_control.cpp +++ b/services/distributed/src/distributed_flow_control.cpp @@ -26,7 +26,7 @@ DistributedFlowControl::DistributedFlowControl( kvStoreMinuteMaxinum_(kvStoreMinuteMaxinum) {} -bool DistributedFlowControl::KvManagerFlowControl(void) +bool DistributedFlowControl::KvManagerFlowControl() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); kvDataManagerTimestampList_.remove_if([&](const std::chrono::system_clock::time_point &value) -> bool { @@ -54,7 +54,7 @@ bool DistributedFlowControl::KvManagerFlowControl(void) return true; } -bool DistributedFlowControl::KvStoreFlowControl(void) +bool DistributedFlowControl::KvStoreFlowControl() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); kvStoreTimestampList_.remove_if([&](const std::chrono::system_clock::time_point &value) -> bool { @@ -82,12 +82,12 @@ bool DistributedFlowControl::KvStoreFlowControl(void) return true; } -void DistributedFlowControl::KvManagerFlowControlClear(void) +void DistributedFlowControl::KvManagerFlowControlClear() { kvDataManagerTimestampList_.clear(); } -void DistributedFlowControl::KvStoreFlowControlClear(void) +void DistributedFlowControl::KvStoreFlowControlClear() { kvStoreTimestampList_.clear(); } diff --git a/services/distributed/src/distributed_notification_manager.cpp b/services/distributed/src/distributed_notification_manager.cpp index 1711c9c626a8739ef14035b730d0a13cfcaff8f4..0bfc91fa8f0b3eb388deecfb9abf34e74e6351bb 100644 --- a/services/distributed/src/distributed_notification_manager.cpp +++ b/services/distributed/src/distributed_notification_manager.cpp @@ -57,23 +57,16 @@ DistributedNotificationManager::DistributedNotificationManager() .OnDisconnected = std::bind(&DistributedNotificationManager::OnDeviceDisconnected, this, std::placeholders::_1), }; deviceCb_ = std::make_shared(deviceCallback); - database_ = std::make_shared(databaseCb_, deviceCb_); - if (database_ == nullptr) { - ANS_LOGE("database_ is nullptr."); - return; - } } DistributedNotificationManager::~DistributedNotificationManager() { ANS_LOGI("deconstructor"); - ANS_LOGE("ffrt start!"); if (distributedQueue_ != nullptr) { ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = {}; })); distributedQueue_->wait(handler); } - ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::ResetFfrtQueue() @@ -146,14 +139,12 @@ bool DistributedNotificationManager::CheckDeviceId(const std::string &deviceId, void DistributedNotificationManager::OnDatabaseInsert( const std::string &deviceId, const std::string &key, const std::string &value) { - ANS_LOGD("%{public}s", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is nullptr."); return; } distributedQueue_->submit(std::bind([=]() { - ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id is distinct. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -173,20 +164,17 @@ void DistributedNotificationManager::OnDatabaseInsert( PublishCallback(resolveKey.deviceId, resolveKey.bundleName, request); })); - ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDatabaseUpdate( const std::string &deviceId, const std::string &key, const std::string &value) { - ANS_LOGD("%{public}s", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return; } ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([=]() { - ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id are not the same. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -206,20 +194,17 @@ void DistributedNotificationManager::OnDatabaseUpdate( UpdateCallback(resolveKey.deviceId, resolveKey.bundleName, request); })); - ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDatabaseDelete( const std::string &deviceId, const std::string &key, const std::string &value) { - ANS_LOGD("%{public}s", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return; } distributedQueue_->submit(std::bind([=]() { - ANS_LOGE("ffrt enter!"); if (!CheckDeviceId(deviceId, key)) { ANS_LOGD("device id are not the same. deviceId:%{public}s key:%{public}s", deviceId.c_str(), key.c_str()); } @@ -232,19 +217,16 @@ void DistributedNotificationManager::OnDatabaseDelete( DeleteCallback(resolveKey.deviceId, resolveKey.bundleName, resolveKey.label, resolveKey.id); })); - ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDeviceConnected(const std::string &deviceId) { - ANS_LOGD("%{public}s", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return; } distributedQueue_->submit(std::bind([=]() { - ANS_LOGE("ffrt enter!"); if (database_ == nullptr) { ANS_LOGE("OnDeviceConnected failed: database is null"); return; @@ -253,20 +235,16 @@ void DistributedNotificationManager::OnDeviceConnected(const std::string &device ANS_LOGE("OnDeviceConnected failed."); } })); - ANS_LOGE("ffrt end!"); } void DistributedNotificationManager::OnDeviceDisconnected(const std::string &deviceId) { - ANS_LOGD("%{public}s", __FUNCTION__); - - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return; } distributedQueue_->submit(std::bind([=]() { - ANS_LOGE("ffrt enter!"); std::string prefixKey = deviceId + DELIMITER; std::vector entries; if (database_ == nullptr) { @@ -295,18 +273,16 @@ void DistributedNotificationManager::OnDeviceDisconnected(const std::string &dev database_->RecreateDistributedDB(); } })); - ANS_LOGE("ffrt end!"); - return; } bool DistributedNotificationManager::PublishCallback( const std::string &deviceId, const std::string &bundleName, sptr &request) { - ANS_LOGI("callback_.OnPublish start."); + ANS_LOGI("start"); if (callback_.OnPublish) { callback_.OnPublish(deviceId, bundleName, request); } - ANS_LOGI("callback_.OnPublish end."); + ANS_LOGI("end"); return true; } @@ -314,11 +290,11 @@ bool DistributedNotificationManager::PublishCallback( bool DistributedNotificationManager::UpdateCallback( const std::string &deviceId, const std::string &bundleName, sptr &request) { - ANS_LOGI("callback_.OnUpdate start."); + ANS_LOGI("start"); if (callback_.OnUpdate) { callback_.OnUpdate(deviceId, bundleName, request); } - ANS_LOGI("callback_.OnUpdate end."); + ANS_LOGI("end"); return true; } @@ -326,11 +302,11 @@ bool DistributedNotificationManager::UpdateCallback( bool DistributedNotificationManager::DeleteCallback( const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id) { - ANS_LOGI("callback_.OnDelete start."); + ANS_LOGI("start"); if (callback_.OnDelete) { callback_.OnDelete(deviceId, bundleName, label, id); } - ANS_LOGI("callback_.OnDelete end."); + ANS_LOGI("end"); return true; } @@ -339,7 +315,7 @@ ErrCode DistributedNotificationManager::Publish( const std::string &bundleName, const std::string &label, int32_t id, const sptr &request) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); std::string key; if (!GenerateLocalDistributedKey(bundleName, label, id, key)) { ANS_LOGE("Failed to generate distributed key."); @@ -367,7 +343,7 @@ ErrCode DistributedNotificationManager::Publish( ErrCode DistributedNotificationManager::Update( const std::string &bundleName, const std::string &label, int32_t id, const sptr &request) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); std::string key; if (!GenerateLocalDistributedKey(bundleName, label, id, key)) { ANS_LOGE("Generate distributed key failed."); @@ -394,7 +370,7 @@ ErrCode DistributedNotificationManager::Update( ErrCode DistributedNotificationManager::Delete(const std::string &bundleName, const std::string &label, int32_t id) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); std::string key; if (!GenerateLocalDistributedKey(bundleName, label, id, key)) { ANS_LOGE("Generate distributed key failed."); @@ -416,7 +392,7 @@ ErrCode DistributedNotificationManager::DeleteRemoteNotification( const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); std::string key; GenerateDistributedKey(deviceId, bundleName, label, id, key); @@ -434,36 +410,32 @@ ErrCode DistributedNotificationManager::DeleteRemoteNotification( ErrCode DistributedNotificationManager::RegisterCallback(const IDistributedCallback &callback) { - ANS_LOGI("%{public}s start", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return ERR_ANS_INVALID_PARAM; } ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = callback; })); distributedQueue_->wait(handler); - ANS_LOGE("ffrt end!"); return ERR_OK; } -ErrCode DistributedNotificationManager::UngegisterCallback(void) +ErrCode DistributedNotificationManager::UngegisterCallback() { - ANS_LOGI("%{public}s start", __FUNCTION__); - ANS_LOGE("ffrt start!"); + ANS_LOGD("start"); if (distributedQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); return ERR_ANS_INVALID_PARAM; } ffrt::task_handle handler = distributedQueue_->submit_h(std::bind([&]() { callback_ = {}; })); distributedQueue_->wait(handler); - ANS_LOGE("ffrt end!"); return ERR_OK; } ErrCode DistributedNotificationManager::GetCurrentDistributedNotification( std::vector> &requestList) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGD("start"); std::string prefixKey = ""; std::vector entries; if (database_ == nullptr) { @@ -497,8 +469,7 @@ ErrCode DistributedNotificationManager::GetCurrentDistributedNotification( ErrCode DistributedNotificationManager::GetLocalDeviceInfo(DistributedDatabase::DeviceInfo &deviceInfo) { - ANS_LOGI("%{public}s start", __FUNCTION__); - + ANS_LOGD("start"); if (database_ == nullptr) { ANS_LOGE("database_ is invalid."); return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; @@ -512,13 +483,8 @@ ErrCode DistributedNotificationManager::GetLocalDeviceInfo(DistributedDatabase:: ErrCode DistributedNotificationManager::OnDistributedKvStoreDeathRecipient() { - ANS_LOGI("%{public}s start", __FUNCTION__); - + ANS_LOGD("start"); database_ = std::make_shared(databaseCb_, deviceCb_); - if (database_ == nullptr) { - ANS_LOGE("database_ is nullptr."); - return ERR_ANS_NO_MEMORY; - } if (!database_->RecreateDistributedDB()) { ANS_LOGE("RecreateDistributedDB failed."); return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; diff --git a/services/distributed/src/distributed_preferences.cpp b/services/distributed/src/distributed_preferences.cpp index 980860796180f1696ca5bb9481bf3f41589db12c..a075a59b35e8ded031851836019a8c4fc155129a 100644 --- a/services/distributed/src/distributed_preferences.cpp +++ b/services/distributed/src/distributed_preferences.cpp @@ -37,7 +37,6 @@ inline bool GetBoolFromString(const std::string &str) DistributedPreferences::DistributedPreferences() { database_ = std::make_unique(); - preferencesInfo_ = std::make_unique(); InitDistributedAllInfo(); } @@ -45,7 +44,7 @@ DistributedPreferences::DistributedPreferences() DistributedPreferences::~DistributedPreferences() {} -bool DistributedPreferences::InitDistributedAllInfo(void) +bool DistributedPreferences::InitDistributedAllInfo() { std::vector entries; if (!database_->GetEntriesFromDistributedDB(DISTRIBUTED_LABEL, entries)) { @@ -140,7 +139,7 @@ bool DistributedPreferences::ResolveSyncWithoutAppEnable(const std::string &key, ErrCode DistributedPreferences::SetDistributedEnable(bool isEnable) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGI("start"); std::string key; GetDistributedMainKey(key); @@ -156,7 +155,7 @@ ErrCode DistributedPreferences::SetDistributedEnable(bool isEnable) ErrCode DistributedPreferences::GetDistributedEnable(bool &isEnable) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGI("start"); isEnable = preferencesInfo_->GetDistributedEnable(); @@ -166,7 +165,7 @@ ErrCode DistributedPreferences::GetDistributedEnable(bool &isEnable) ErrCode DistributedPreferences::SetDistributedBundleEnable( const sptr &bundleOption, bool isEnable) { - ANS_LOGI("%{public}s start", __FUNCTION__); + ANS_LOGI("start"); if (bundleOption == nullptr) { ANS_LOGE("bundleOption is nullptr."); return ERR_ANS_INVALID_PARAM; @@ -188,12 +187,16 @@ ErrCode DistributedPreferences::SetDistributedBundleEnable( ErrCode DistributedPreferences::GetDistributedBundleEnable( const sptr &bundleOption, bool &isEnable) { - ANS_LOGI("%{public}s start", __FUNCTION__); if (bundleOption == nullptr) { ANS_LOGE("bundleOption is nullptr."); return ERR_ANS_INVALID_PARAM; } + if (preferencesInfo_ == nullptr) { + ANS_LOGE("preferencesInfo is nullptr"); + return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; + } + isEnable = preferencesInfo_->GetDistributedBundleEnable(bundleOption->GetBundleName(), bundleOption->GetUid()); return ERR_OK; @@ -201,12 +204,16 @@ ErrCode DistributedPreferences::GetDistributedBundleEnable( ErrCode DistributedPreferences::DeleteDistributedBundleInfo(const sptr &bundleOption) { - ANS_LOGI("%{public}s start", __FUNCTION__); if (bundleOption == nullptr) { ANS_LOGE("bundleOption is nullptr."); return ERR_ANS_INVALID_PARAM; } + if (database_ == nullptr || preferencesInfo_ == nullptr) { + ANS_LOGE("database or preferencesInfo is nullptr"); + return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; + } + std::string key; GetDistributedBundleKey(bundleOption, key); @@ -222,6 +229,11 @@ ErrCode DistributedPreferences::DeleteDistributedBundleInfo(const sptrClearDatabase()) { return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; } @@ -240,22 +252,24 @@ void DistributedPreferences::GetEnabledWithoutApp(const int32_t userId, std::str ErrCode DistributedPreferences::SetSyncEnabledWithoutApp(const int32_t userId, const bool enabled) { + if (database_ == nullptr || preferencesInfo_ == nullptr) { + ANS_LOGE("database or preferencesInfo is nullptr"); + return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; + } std::string key; GetEnabledWithoutApp(userId, key); - if (!database_->PutToDistributedDB(key, std::to_string(enabled))) { ANS_LOGE("put to distributed DB failed. key:%{public}s", key.c_str()); return ERR_ANS_DISTRIBUTED_OPERATION_FAILED; } - preferencesInfo_->SetSyncEnabledWithoutApp(userId, enabled); - return ERR_OK; } ErrCode DistributedPreferences::GetSyncEnabledWithoutApp(const int32_t userId, bool &enabled) { - return preferencesInfo_->GetSyncEnabledWithoutApp(userId, enabled); + return preferencesInfo_ == nullptr ? + ERR_ANS_DISTRIBUTED_OPERATION_FAILED : preferencesInfo_->GetSyncEnabledWithoutApp(userId, enabled); } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/distributed/src/distributed_preferences_database.cpp b/services/distributed/src/distributed_preferences_database.cpp index aa4ff718ef316744c6c889332f2fc184302a3e7a..d3f9885e4f152b60c1fb018ff743f82c6951c5e5 100644 --- a/services/distributed/src/distributed_preferences_database.cpp +++ b/services/distributed/src/distributed_preferences_database.cpp @@ -33,14 +33,14 @@ DistributedPreferencesDatabase::DistributedPreferencesDatabase() : DistributedFl DistributedPreferencesDatabase::~DistributedPreferencesDatabase() {} -void DistributedPreferencesDatabase::GetKvDataManager(void) +void DistributedPreferencesDatabase::GetKvDataManager() { kvDataManager_ = std::make_unique(); KvManagerFlowControlClear(); } -bool DistributedPreferencesDatabase::CheckKvDataManager(void) +bool DistributedPreferencesDatabase::CheckKvDataManager() { if (kvDataManager_ == nullptr) { GetKvDataManager(); @@ -51,7 +51,7 @@ bool DistributedPreferencesDatabase::CheckKvDataManager(void) return true; } -void DistributedPreferencesDatabase::GetKvStore(void) +void DistributedPreferencesDatabase::GetKvStore() { if (!CheckKvDataManager()) { return; @@ -77,7 +77,7 @@ void DistributedPreferencesDatabase::GetKvStore(void) KvStoreFlowControlClear(); } -bool DistributedPreferencesDatabase::CheckKvStore(void) +bool DistributedPreferencesDatabase::CheckKvStore() { if (kvStore_ == nullptr) { GetKvStore(); @@ -183,7 +183,7 @@ bool DistributedPreferencesDatabase::DeleteToDistributedDB(const std::string &ke return true; } -bool DistributedPreferencesDatabase::ClearDatabase(void) +bool DistributedPreferencesDatabase::ClearDatabase() { std::lock_guard lock(mutex_); @@ -200,13 +200,13 @@ bool DistributedPreferencesDatabase::ClearDatabase(void) DistributedKv::StoreId storeId = {.storeId = STORE_ID}; DistributedKv::Status status = kvDataManager_->CloseKvStore(appId, storeId); if (status != DistributedKv::Status::SUCCESS) { - ANS_LOGE("kvDataManager CloseKvStore() failed ret = 0x%{public}x", status); + ANS_LOGE("CloseKvStore failed ret = 0x%{public}x", status); return false; } status = kvDataManager_->DeleteKvStore(appId, storeId, KV_STORE_PATH); if (status != DistributedKv::Status::SUCCESS) { - ANS_LOGE("kvDataManager DeleteKvStore() failed ret = 0x%{public}x", status); + ANS_LOGE("DeleteKvStore failed ret = 0x%{public}x", status); return false; } return true; diff --git a/services/distributed/src/distributed_preferences_info.cpp b/services/distributed/src/distributed_preferences_info.cpp index 7a46b7805b29663a7757ae78000c0e5537f454fd..b9ef2836afc1643249d2143c3fbb1740b06ec9a7 100644 --- a/services/distributed/src/distributed_preferences_info.cpp +++ b/services/distributed/src/distributed_preferences_info.cpp @@ -30,7 +30,7 @@ void DistributedPreferencesInfo::SetDistributedEnable(bool enable) distributedEnable_ = enable; } -bool DistributedPreferencesInfo::GetDistributedEnable(void) +bool DistributedPreferencesInfo::GetDistributedEnable() { return distributedEnable_; } diff --git a/services/distributed/src/distributed_screen_status_manager.cpp b/services/distributed/src/distributed_screen_status_manager.cpp index c40df0b96103064475c40a1af24e203bae30e59b..f557b8e445eb9430d2db36971012f7f206cc6745 100644 --- a/services/distributed/src/distributed_screen_status_manager.cpp +++ b/services/distributed/src/distributed_screen_status_manager.cpp @@ -29,7 +29,7 @@ const std::string SCREEN_STATUS_LABEL = "screen_status"; const std::string SCREEN_STATUS_VALUE_ON = "on"; const std::string SCREEN_STATUS_VALUE_OFF = "off"; constexpr char KV_STORE_PATH[] = "/data/service/el1/public/database/notification_service"; -} // namespace +} // namespace DistributedScreenStatusManager::DistributedScreenStatusManager() : DistributedFlowControl() { @@ -83,7 +83,7 @@ void DistributedScreenStatusManager::OnDeviceDisconnected(const std::string &dev SetLocalScreenStatus(localScreenOn_); } -void DistributedScreenStatusManager::GetKvDataManager(void) +void DistributedScreenStatusManager::GetKvDataManager() { initCallback_ = std::make_shared(); int32_t ret = DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(APP_ID + STORE_ID, initCallback_); @@ -106,7 +106,7 @@ void DistributedScreenStatusManager::DeviceInitCallBack::OnRemoteDied() ANS_LOGW("DeviceInitCallBack OnRemoteDied"); } -bool DistributedScreenStatusManager::CheckKvDataManager(void) +bool DistributedScreenStatusManager::CheckKvDataManager() { if (kvDataManager_ == nullptr) { GetKvDataManager(); @@ -118,7 +118,7 @@ bool DistributedScreenStatusManager::CheckKvDataManager(void) return true; } -void DistributedScreenStatusManager::GetKvStore(void) +void DistributedScreenStatusManager::GetKvStore() { if (!CheckKvDataManager()) { return; @@ -145,7 +145,7 @@ void DistributedScreenStatusManager::GetKvStore(void) KvStoreFlowControlClear(); } -bool DistributedScreenStatusManager::CheckKvStore(void) +bool DistributedScreenStatusManager::CheckKvStore() { if (kvStore_ == nullptr) { GetKvStore(); diff --git a/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_flow_control.cpp b/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_flow_control.cpp old mode 100755 new mode 100644 index 4b0b89ff61f0cb8e0b6f07d3797ea0550f5b7d1d..53545db8cd118f23faf55995f3f729d40a6b31ca --- a/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_flow_control.cpp +++ b/services/distributed/test/unittest/distributed_database_branch_test/mock_distributed_flow_control.cpp @@ -41,12 +41,12 @@ DistributedFlowControl::DistributedFlowControl( kvStoreMinuteMaxinum_(kvStoreMinuteMaxinum) {} -bool DistributedFlowControl::KvManagerFlowControl(void) +bool DistributedFlowControl::KvManagerFlowControl() { return g_mockKvManagerFlowControlRet; } -bool DistributedFlowControl::KvStoreFlowControl(void) +bool DistributedFlowControl::KvStoreFlowControl() { return g_mockKvStoreFlowControlRet; } diff --git a/services/distributed/test/unittest/distributed_preferences_database_test/mock_distributed_flow_control.cpp b/services/distributed/test/unittest/distributed_preferences_database_test/mock_distributed_flow_control.cpp old mode 100755 new mode 100644 index d0d353fe22f2de2b4f5e2ceaf9c51b060cb29816..f4f84212cf3a3e1e5600c781a4b1e6ba88a299ef --- a/services/distributed/test/unittest/distributed_preferences_database_test/mock_distributed_flow_control.cpp +++ b/services/distributed/test/unittest/distributed_preferences_database_test/mock_distributed_flow_control.cpp @@ -41,12 +41,12 @@ DistributedFlowControl::DistributedFlowControl( kvStoreMinuteMaxinum_(kvStoreMinuteMaxinum) {} -bool DistributedFlowControl::KvStoreFlowControl(void) +bool DistributedFlowControl::KvStoreFlowControl() { return g_mockKvStoreFlowControlRet; } -bool DistributedFlowControl::KvManagerFlowControl(void) +bool DistributedFlowControl::KvManagerFlowControl() { return g_mockKvManagerFlowControlRet; } diff --git a/services/distributed/test/unittest/distributed_screen_status_manager_branch_test/mock_distributed_flow_control.cpp b/services/distributed/test/unittest/distributed_screen_status_manager_branch_test/mock_distributed_flow_control.cpp old mode 100755 new mode 100644 index 63cfff2a5552baa631eb16b5fc6dcd9af3b56b76..3a4014de2abceceae0a5d6b83ca9a8584702ce9e --- a/services/distributed/test/unittest/distributed_screen_status_manager_branch_test/mock_distributed_flow_control.cpp +++ b/services/distributed/test/unittest/distributed_screen_status_manager_branch_test/mock_distributed_flow_control.cpp @@ -41,12 +41,12 @@ DistributedFlowControl::DistributedFlowControl( kvStoreMinuteMaxinum_(kvStoreMinuteMaxinum) {} -bool DistributedFlowControl::KvManagerFlowControl(void) +bool DistributedFlowControl::KvManagerFlowControl() { return g_mockKvManagerFlowControlRet; } -bool DistributedFlowControl::KvStoreFlowControl(void) +bool DistributedFlowControl::KvStoreFlowControl() { return g_mockKvStoreFlowControlRet; }