From 2847d64802e8ba6ee7029672b53c5208849fd9f7 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 15 Feb 2022 16:12:44 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=B9=BF=E6=92=AD=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 38 ++++++++++++++++--- .../ext_storage/ext_storage_subscriber.h | 2 + 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 410864dd..acdbdddd 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -42,8 +42,9 @@ bool ExtStorageSubscriber::Subscriber(void) { if (ExtStorageSubscriber_ == nullptr) { EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_MOUNTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); ExtStorageSubscriber_ = std::make_shared(subscribeInfo); @@ -68,17 +69,32 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) { + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_MOUNTED) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); std::string fsUuid = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("fsUuid"))); std::string path = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("path"))); - DEBUG_LOG("%{public}s, volumeState:%{public}d.", __func__, volumeState); + DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_MOUNTED volumeState:%{public}d.", __func__, volumeState); DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); + if (mountStatus.find(path) == mountStatus.end()) { + ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); + mountStatus.insert(std::pair(path, extStatus)); + } else { + modifyMountStatus(id, volumeState); + } + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED) { + int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); + DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_UNMOUNTED volumeState:%{public}d.", __func__, volumeState); + + modifyMountStatus(id, volumeState); + } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT) { + int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); + DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_EJECT volumeState:%{public}d.", __func__, volumeState); + + modifyMountStatus(id, volumeState); } + } bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) @@ -93,5 +109,15 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) return false; } } + +void ExtStorageSubscriber::modifyMountStatus(const std::string &id, int32_t volumeState) +{ + for (auto itr:mountStatus) { + auto extStatus = itr.second; + if(extStatus.GetId() == id) { + extStatus.SetVolumeState(VolumeState(volumeState)); + } + } +} } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 18a34b77..f57dd7c5 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -46,6 +46,8 @@ public: bool CheckMountPoint(const std::string &path); std::unordered_map mountStatus; +private: + void modifyMountStatus(const std::string &id, int32_t volumeState); }; } // namespace FileManagerService } // namespace OHOS -- Gitee From e18926d870f8129948282d211e174ce37dcf868b Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 15 Feb 2022 16:20:56 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index acdbdddd..d8498d01 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -94,7 +94,6 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event modifyMountStatus(id, volumeState); } - } bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) @@ -114,7 +113,7 @@ void ExtStorageSubscriber::modifyMountStatus(const std::string &id, int32_t volu { for (auto itr:mountStatus) { auto extStatus = itr.second; - if(extStatus.GetId() == id) { + if (extStatus.GetId() == id) { extStatus.SetVolumeState(VolumeState(volumeState)); } } -- Gitee From 0adca2e15f9b5fe35cb68fdaa079f17a4fef6ff0 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 15 Feb 2022 18:20:32 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9modify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../src/fileoper/ext_storage/ext_storage_subscriber.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index d8498d01..c19d9854 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -111,10 +111,9 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) void ExtStorageSubscriber::modifyMountStatus(const std::string &id, int32_t volumeState) { - for (auto itr:mountStatus) { - auto extStatus = itr.second; - if (extStatus.GetId() == id) { - extStatus.SetVolumeState(VolumeState(volumeState)); + for (auto itr = mountStatus.begin(); itr != mountStatus.end(); itr++) { + if (iter->second.GetId() == id) { + iter->second.SetVolumeState(VolumeState(volumeState)); } } } -- Gitee From c5a1afaf633349979655a0ad3222e3e9426ecb5b Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 16 Feb 2022 09:50:20 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8B=BC=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index c19d9854..bc8737df 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -111,7 +111,7 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) void ExtStorageSubscriber::modifyMountStatus(const std::string &id, int32_t volumeState) { - for (auto itr = mountStatus.begin(); itr != mountStatus.end(); itr++) { + for (auto iter = mountStatus.begin(); iter != mountStatus.end(); iter++) { if (iter->second.GetId() == id) { iter->second.SetVolumeState(VolumeState(volumeState)); } -- Gitee From 262b53367f71d2688dcdc0097525f01f755a0c82 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 16 Feb 2022 15:31:15 +0800 Subject: [PATCH 05/19] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 28 ++++++++++++------- .../ext_storage/ext_storage_subscriber.h | 3 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index bc8737df..d32cfe52 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -77,22 +77,29 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - if (mountStatus.find(path) == mountStatus.end()) { + if (idPathMap.count(id) == 0) { + idPathMap.insert(std::pair(id, path)); + ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); mountStatus.insert(std::pair(path, extStatus)); } else { - modifyMountStatus(id, volumeState); + idPathMap[id] = path; + ModifyMountStatus(path, volumeState); } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_UNMOUNTED volumeState:%{public}d.", __func__, volumeState); - - modifyMountStatus(id, volumeState); + + if (idPathMap.count(id) == 1) { + ModifyMountStatus(idPathMap[id], volumeState); + } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_EJECT volumeState:%{public}d.", __func__, volumeState); - modifyMountStatus(id, volumeState); + if (idPathMap.count(id) == 1) { + ModifyMountStatus(idPathMap[id], volumeState); + } } } @@ -109,12 +116,13 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) } } -void ExtStorageSubscriber::modifyMountStatus(const std::string &id, int32_t volumeState) +void ExtStorageSubscriber::ModifyMountStatus(const std::string &path, int32_t volumeState) { - for (auto iter = mountStatus.begin(); iter != mountStatus.end(); iter++) { - if (iter->second.GetId() == id) { - iter->second.SetVolumeState(VolumeState(volumeState)); - } + auto iter = mountStatus.find(path); + if (iter == mountStatus.end()) { + return; + } else { + iter->second.SetVolumeState(VolumeState(volumeState)); } } } // namespace FileManagerService diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index f57dd7c5..9c90b0be 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -46,8 +46,9 @@ public: bool CheckMountPoint(const std::string &path); std::unordered_map mountStatus; + std::unordered_map idPathMap; private: - void modifyMountStatus(const std::string &id, int32_t volumeState); + void ModifyMountStatus(const std::string &path, int32_t volumeState); }; } // namespace FileManagerService } // namespace OHOS -- Gitee From f7e67a6f3e3f6c224ae33ad62361fc4a2cf446e4 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 16 Feb 2022 19:59:29 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9map=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index d32cfe52..c3d60f7a 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -83,7 +83,6 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); mountStatus.insert(std::pair(path, extStatus)); } else { - idPathMap[id] = path; ModifyMountStatus(path, volumeState); } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED) { @@ -91,7 +90,8 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_UNMOUNTED volumeState:%{public}d.", __func__, volumeState); if (idPathMap.count(id) == 1) { - ModifyMountStatus(idPathMap[id], volumeState); + idPathMap.erase(idPathMap.find(id)); + mountStatus.erase(mountStatus.find(idPathMap[id])); } } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); -- Gitee From e39500be13e10f88d34cb1e03feb4ec07c8492a5 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 16 Feb 2022 20:21:29 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 46 +++++++++++++------ .../ext_storage/ext_storage_subscriber.h | 4 ++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index c3d60f7a..554294e6 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -77,29 +77,17 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - if (idPathMap.count(id) == 0) { - idPathMap.insert(std::pair(id, path)); - - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); - } else { - ModifyMountStatus(path, volumeState); - } + ReceiveMounted(id, diskId, fsUuid, path, volumeState); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_UNMOUNTED volumeState:%{public}d.", __func__, volumeState); - if (idPathMap.count(id) == 1) { - idPathMap.erase(idPathMap.find(id)); - mountStatus.erase(mountStatus.find(idPathMap[id])); - } + ReceiveUnmounted(id); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT) { int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_EJECT volumeState:%{public}d.", __func__, volumeState); - if (idPathMap.count(id) == 1) { - ModifyMountStatus(idPathMap[id], volumeState); - } + ReceiveOther(id, volumeState); } } @@ -125,5 +113,33 @@ void ExtStorageSubscriber::ModifyMountStatus(const std::string &path, int32_t vo iter->second.SetVolumeState(VolumeState(volumeState)); } } + +void ExtStorageSubscriber::ReceiveMounted(const std::string &id, const std::string &diskId, + const std::string &fsUuid, const std::string &path, const int32_t &volumeState) +{ + if (idPathMap.count(id) == 0) { + idPathMap.insert(std::pair(id, path)); + + ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); + mountStatus.insert(std::pair(path, extStatus)); + } else { + ModifyMountStatus(path, volumeState); + } +} + +void ExtStorageSubscriber::ReceiveUnmounted(const std::string &id) +{ + if (idPathMap.count(id) == 1) { + idPathMap.erase(idPathMap.find(id)); + mountStatus.erase(mountStatus.find(idPathMap[id])); + } +} + +void ExtStorageSubscriber::ReceiveOther(const std::string &id, int32_t volumeState) +{ + if (idPathMap.count(id) == 1) { + ModifyMountStatus(idPathMap[id], volumeState); + } +} } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 9c90b0be..57b49e7a 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -49,6 +49,10 @@ public: std::unordered_map idPathMap; private: void ModifyMountStatus(const std::string &path, int32_t volumeState); + void ReceiveMounted(const std::string &id, const std::string &diskId, + const std::string &fsUuid, const std::string &path, const int32_t &volumeState); + void ReceiveUnmounted(const std::string &id); + void ReceiveOther(const std::string &id, int32_t volumeState); }; } // namespace FileManagerService } // namespace OHOS -- Gitee From 568f842ae89174828aebf1989447ba0c4ae0fd22 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 16 Feb 2022 20:27:14 +0800 Subject: [PATCH 08/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 554294e6..6ae9183d 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -115,7 +115,7 @@ void ExtStorageSubscriber::ModifyMountStatus(const std::string &path, int32_t vo } void ExtStorageSubscriber::ReceiveMounted(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const int32_t &volumeState) + const std::string &fsUuid, const std::string &path, const int32_t &volumeState) { if (idPathMap.count(id) == 0) { idPathMap.insert(std::pair(id, path)); -- Gitee From 22d1190d00b2985424a913fc2e3161f3bfd34839 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Thu, 17 Feb 2022 10:00:07 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../src/fileoper/ext_storage/ext_storage_subscriber.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 6ae9183d..3ea7995b 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -130,8 +130,12 @@ void ExtStorageSubscriber::ReceiveMounted(const std::string &id, const std::stri void ExtStorageSubscriber::ReceiveUnmounted(const std::string &id) { if (idPathMap.count(id) == 1) { - idPathMap.erase(idPathMap.find(id)); - mountStatus.erase(mountStatus.find(idPathMap[id])); + if (idPathMap.find(id) != idPathMap.end()) { + idPathMap.erase(idPathMap.find(id)); + } + if (mountStatus.find(idPathMap[id]) != mountStatus.end()) { + mountStatus.erase(mountStatus.find(idPathMap[id])); + } } } -- Gitee From aff144b66bd2688319eda25040c48a75677c158a Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Thu, 17 Feb 2022 10:36:12 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 34 +++++++++++-------- .../ext_storage/ext_storage_subscriber.h | 6 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 3ea7995b..d1011dd5 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -93,8 +93,8 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) { - auto extStorageStatus = mountStatus.find(path); - if (extStorageStatus == mountStatus.end()) { + auto extStorageStatus = mountStatus_.find(path); + if (extStorageStatus == mountStatus_.end()) { return false; } else { if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { @@ -106,43 +106,49 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) void ExtStorageSubscriber::ModifyMountStatus(const std::string &path, int32_t volumeState) { - auto iter = mountStatus.find(path); - if (iter == mountStatus.end()) { + auto iter = mountStatus_.find(path); + if (iter == mountStatus_.end()) { return; } else { iter->second.SetVolumeState(VolumeState(volumeState)); + DEBUG_LOG("%{public}s, SetVolumeState:%{public}d.", __func__, volumeState); } } void ExtStorageSubscriber::ReceiveMounted(const std::string &id, const std::string &diskId, const std::string &fsUuid, const std::string &path, const int32_t &volumeState) { - if (idPathMap.count(id) == 0) { - idPathMap.insert(std::pair(id, path)); + if (idPathMap_.count(id) == 0) { + idPathMap_.insert(std::pair(id, path)); ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); + mountStatus_.insert(std::pair(path, extStatus)); + DEBUG_LOG("%{public}s, insert data to map:%{public}s.", __func__, path.c_str()); } else { ModifyMountStatus(path, volumeState); + DEBUG_LOG("%{public}s, update map:%{public}s.", __func__, path.c_str()); } } void ExtStorageSubscriber::ReceiveUnmounted(const std::string &id) { - if (idPathMap.count(id) == 1) { - if (idPathMap.find(id) != idPathMap.end()) { - idPathMap.erase(idPathMap.find(id)); + if (idPathMap_.count(id) == 1) { + if (idPathMap_.find(id) != idPathMap_.end()) { + idPathMap_.erase(idPathMap_.find(id)); + DEBUG_LOG("%{public}s, erase data from idPathMap_:%{public}s.", __func__, id.c_str()); } - if (mountStatus.find(idPathMap[id]) != mountStatus.end()) { - mountStatus.erase(mountStatus.find(idPathMap[id])); + if (mountStatus_.find(idPathMap_[id]) != mountStatus_.end()) { + mountStatus_.erase(mountStatus_.find(idPathMap_[id])); + DEBUG_LOG("%{public}s, erase data from mountStatus_:%{public}s.", __func__, idPathMap_[id].c_str()); } } } void ExtStorageSubscriber::ReceiveOther(const std::string &id, int32_t volumeState) { - if (idPathMap.count(id) == 1) { - ModifyMountStatus(idPathMap[id], volumeState); + if (idPathMap_.count(id) == 1) { + ModifyMountStatus(idPathMap_[id], volumeState); + DEBUG_LOG("%{public}s, update data from mountStatus_:%{public}s, %{public}s.", __func__, idPathMap_[id].c_str(), id.c_str()); } } } // namespace FileManagerService diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 57b49e7a..161ede11 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -44,15 +44,15 @@ public: virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; bool CheckMountPoint(const std::string &path); - - std::unordered_map mountStatus; - std::unordered_map idPathMap; private: void ModifyMountStatus(const std::string &path, int32_t volumeState); void ReceiveMounted(const std::string &id, const std::string &diskId, const std::string &fsUuid, const std::string &path, const int32_t &volumeState); void ReceiveUnmounted(const std::string &id); void ReceiveOther(const std::string &id, int32_t volumeState); + + std::unordered_map mountStatus_; + std::unordered_map idPathMap_; }; } // namespace FileManagerService } // namespace OHOS -- Gitee From 5a352979f4e8e34304fa7f668468ba4432aaac8c Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Thu, 17 Feb 2022 10:43:12 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E8=A1=8C=E5=AE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index d1011dd5..373b5795 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -148,7 +148,8 @@ void ExtStorageSubscriber::ReceiveOther(const std::string &id, int32_t volumeSta { if (idPathMap_.count(id) == 1) { ModifyMountStatus(idPathMap_[id], volumeState); - DEBUG_LOG("%{public}s, update data from mountStatus_:%{public}s, %{public}s.", __func__, idPathMap_[id].c_str(), id.c_str()); + DEBUG_LOG("%{public}s, update data from mountStatus_:%{public}s, %{public}s.", + __func__, idPathMap_[id].c_str(), id.c_str()); } } } // namespace FileManagerService -- Gitee From 4422547854d513ccd6447514c3c7ce4d11b8287c Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 18 Feb 2022 17:02:48 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 109 ++++++++---------- .../ext_storage/ext_storage_subscriber.h | 7 +- 2 files changed, 48 insertions(+), 68 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 373b5795..aadaea1e 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -21,11 +21,13 @@ #include "bundle_info.h" #include "common_event_manager.h" #include "common_event_support.h" +#include "int_wrapper.h" #include "log.h" #include "string_wrapper.h" -#include "int_wrapper.h" +#include "storage_manager_inf.h" #include "want.h" + using namespace OHOS::AAFwk; namespace OHOS { namespace FileManagerService { @@ -69,26 +71,8 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_MOUNTED) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - std::string fsUuid = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("fsUuid"))); - std::string path = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("path"))); - DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_MOUNTED volumeState:%{public}d.", __func__, volumeState); - DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", - __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - ReceiveMounted(id, diskId, fsUuid, path, volumeState); - } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_UNMOUNTED) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_UNMOUNTED volumeState:%{public}d.", __func__, volumeState); - - ReceiveUnmounted(id); - } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_VOLUME_EJECT) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - DEBUG_LOG("%{public}s, COMMON_EVENT_VOLUME_EJECT volumeState:%{public}d.", __func__, volumeState); - - ReceiveOther(id, volumeState); - } + ReceiveEventDeal(); } bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) @@ -104,52 +88,53 @@ bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) } } -void ExtStorageSubscriber::ModifyMountStatus(const std::string &path, int32_t volumeState) +void ExtStorageSubscriber::ReceiveEventDeal() { - auto iter = mountStatus_.find(path); - if (iter == mountStatus_.end()) { - return; - } else { - iter->second.SetVolumeState(VolumeState(volumeState)); - DEBUG_LOG("%{public}s, SetVolumeState:%{public}d.", __func__, volumeState); - } -} - -void ExtStorageSubscriber::ReceiveMounted(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const int32_t &volumeState) -{ - if (idPathMap_.count(id) == 0) { - idPathMap_.insert(std::pair(id, path)); - - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus_.insert(std::pair(path, extStatus)); - DEBUG_LOG("%{public}s, insert data to map:%{public}s.", __func__, path.c_str()); - } else { - ModifyMountStatus(path, volumeState); - DEBUG_LOG("%{public}s, update map:%{public}s.", __func__, path.c_str()); - } -} - -void ExtStorageSubscriber::ReceiveUnmounted(const std::string &id) -{ - if (idPathMap_.count(id) == 1) { - if (idPathMap_.find(id) != idPathMap_.end()) { - idPathMap_.erase(idPathMap_.find(id)); - DEBUG_LOG("%{public}s, erase data from idPathMap_:%{public}s.", __func__, id.c_str()); + std::vector volVec = StorageManagerInf::GetAllVolumes(); + size_t len = volVec.size(); + // Clean up redundant data in map + for (auto iter = mountStatus_.begin(); iter != mountStatus_.end(); iter++) { + bool isExist = false; + for (size_t i=0; ifirst == path) { + isExist = true; + DEBUG_LOG("%{public}s, path in map, path:%{public}s.", __func__, path.c_str()); + } } - if (mountStatus_.find(idPathMap_[id]) != mountStatus_.end()) { - mountStatus_.erase(mountStatus_.find(idPathMap_[id])); - DEBUG_LOG("%{public}s, erase data from mountStatus_:%{public}s.", __func__, idPathMap_[id].c_str()); + if (isExist == false) { + mountStatus_.erase(iter++); + DEBUG_LOG("%{public}s, erase map.", __func__); } } -} - -void ExtStorageSubscriber::ReceiveOther(const std::string &id, int32_t volumeState) -{ - if (idPathMap_.count(id) == 1) { - ModifyMountStatus(idPathMap_[id], volumeState); - DEBUG_LOG("%{public}s, update data from mountStatus_:%{public}s, %{public}s.", - __func__, idPathMap_[id].c_str(), id.c_str()); + // update map data + for (size_t j=0; j(path, extStatus)); + DEBUG_LOG("%{public}s, insert map, id:%{public}s.", __func__, volStatus.GetId().c_str()); + DEBUG_LOG("%{public}s, insert map, diskid:%{public}s.", __func__, volStatus.GetDiskId().c_str()); + DEBUG_LOG("%{public}s, insert map, uuid:%{public}s.", __func__, volStatus.GetUuid().c_str()); + DEBUG_LOG("%{public}s, insert map, path:%{public}s.", __func__, path.c_str()); + DEBUG_LOG("%{public}s, insert map, state:%{public}d.", __func__, volStatus.GetState()); + } else { + iter->second.SetId(volStatus.GetId()); + iter->second.SetDiskId(volStatus.GetDiskId()); + iter->second.SetFsUuid(volStatus.GetUuid()); + iter->second.SetPath(path); + iter->second.SetVolumeState(VolumeState(volStatus.GetState())); + DEBUG_LOG("%{public}s, update data, path:%{public}s, state:%{public}d.", __func__, + path.c_str(), volStatus.GetState()); + } + } } } } // namespace FileManagerService diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 161ede11..1d7191ce 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -45,14 +45,9 @@ public: bool CheckMountPoint(const std::string &path); private: - void ModifyMountStatus(const std::string &path, int32_t volumeState); - void ReceiveMounted(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const int32_t &volumeState); - void ReceiveUnmounted(const std::string &id); - void ReceiveOther(const std::string &id, int32_t volumeState); + void ReceiveEventDeal(); std::unordered_map mountStatus_; - std::unordered_map idPathMap_; }; } // namespace FileManagerService } // namespace OHOS -- Gitee From d2d013543fe97b73d78e1d2bb0ef9181697fe32a Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 18 Feb 2022 17:09:50 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../src/fileoper/ext_storage/ext_storage_subscriber.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index aadaea1e..d201a6a7 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -71,7 +71,6 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - ReceiveEventDeal(); } @@ -95,7 +94,7 @@ void ExtStorageSubscriber::ReceiveEventDeal() // Clean up redundant data in map for (auto iter = mountStatus_.begin(); iter != mountStatus_.end(); iter++) { bool isExist = false; - for (size_t i=0; i(path, extStatus)); DEBUG_LOG("%{public}s, insert map, id:%{public}s.", __func__, volStatus.GetId().c_str()); -- Gitee From 62948f326b1f3ab5d0dbe0668ca5fc4a9ece1036 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 18 Feb 2022 17:17:58 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index d201a6a7..21b88c91 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -97,7 +97,6 @@ void ExtStorageSubscriber::ReceiveEventDeal() for (size_t i = 0; i < len; i++) { StorageManager::VolumeExternal volStatus = volVec[i]; std::string path = volStatus.GetPath(); - if (iter->first == path) { isExist = true; DEBUG_LOG("%{public}s, path in map, path:%{public}s.", __func__, path.c_str()); -- Gitee From ec005040decbc3d3af20e20897b96b05f887f1ea Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Mon, 21 Feb 2022 10:21:27 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 40 ++++++++++++------- .../ext_storage/ext_storage_subscriber.h | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 21b88c91..e3adb16e 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -51,6 +51,8 @@ bool ExtStorageSubscriber::Subscriber(void) EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); ExtStorageSubscriber_ = std::make_shared(subscribeInfo); EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); + + ExtStorageSubscriber_->CheckAndUpdateData(); } return true; } @@ -71,48 +73,56 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - ReceiveEventDeal(); + CheckAndUpdateData(); } bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) { - auto extStorageStatus = mountStatus_.find(path); - if (extStorageStatus == mountStatus_.end()) { + std::vector volVec = StorageManagerInf::GetAllVolumes(); + if (volVec.size() == 0) { + ERR_LOG("empty volume result"); return false; - } else { - if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { - return true; + } + bool succ = false; + for (auto vol : volVec) { + if (vol.GetPath() == path && vol.GetState() == VolumeState::MOUNTED) { + succ = true; + DEBUG_LOG("%{public}s, path:%{public}s, state:%{public}d.", __func__, path.c_str(), vol.GetState()); + break; } - return false; } + DEBUG_LOG("%{public}s, path in map, path:%{public}s.", __func__, path.c_str()); + return succ; } -void ExtStorageSubscriber::ReceiveEventDeal() +void ExtStorageSubscriber::CheckAndUpdateData() { std::vector volVec = StorageManagerInf::GetAllVolumes(); - size_t len = volVec.size(); // Clean up redundant data in map for (auto iter = mountStatus_.begin(); iter != mountStatus_.end(); iter++) { bool isExist = false; - for (size_t i = 0; i < len; i++) { - StorageManager::VolumeExternal volStatus = volVec[i]; + for (auto volStatus : volVec) { std::string path = volStatus.GetPath(); if (iter->first == path) { isExist = true; DEBUG_LOG("%{public}s, path in map, path:%{public}s.", __func__, path.c_str()); + break; } } if (isExist == false) { - mountStatus_.erase(iter++); + if (iter != mountStatus_.end()) { + mountStatus_.erase(iter++); + } else { + mountStatus_.erase(iter); + } DEBUG_LOG("%{public}s, erase map.", __func__); } } // update map data - for (size_t j = 0; j < len; j++) { - StorageManager::VolumeExternal volStatus = volVec[j]; + for (auto volStatus : volVec) { std::string path = volStatus.GetPath(); if (!path.empty()) { - // 已在map中存在的,更新数据; 没有的插入新数据 + // Update the data if it already exists in the map; No new data to insert auto iter = mountStatus_.find(path); if (iter == mountStatus_.end()) { ExtStorageStatus extStatus(volStatus.GetId(), volStatus.GetDiskId(), volStatus.GetUuid(), diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 1d7191ce..3fd93d3d 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -45,7 +45,7 @@ public: bool CheckMountPoint(const std::string &path); private: - void ReceiveEventDeal(); + void CheckAndUpdateData(); std::unordered_map mountStatus_; }; -- Gitee From 996fa04f2baf98bb07ad586d4f413ba6a5283fbc Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Mon, 21 Feb 2022 10:24:30 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index e3adb16e..a799ab85 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -113,7 +113,7 @@ void ExtStorageSubscriber::CheckAndUpdateData() if (iter != mountStatus_.end()) { mountStatus_.erase(iter++); } else { - mountStatus_.erase(iter); + mountStatus_.erase(iter); } DEBUG_LOG("%{public}s, erase map.", __func__); } -- Gitee From 02f91d2bf04865be983dddfd1631f24d1400f352 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Mon, 21 Feb 2022 13:03:56 +0800 Subject: [PATCH 17/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 13 ++++++------- .../fileoper/ext_storage/ext_storage_subscriber.h | 2 +- .../fileoper/ext_storage/storage_manager_inf.cpp | 15 ++------------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index a799ab85..efecaa14 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -99,7 +99,8 @@ void ExtStorageSubscriber::CheckAndUpdateData() { std::vector volVec = StorageManagerInf::GetAllVolumes(); // Clean up redundant data in map - for (auto iter = mountStatus_.begin(); iter != mountStatus_.end(); iter++) { + auto iter = mountStatus_.begin(); + while (iter != mountStatus_.end()) { bool isExist = false; for (auto volStatus : volVec) { std::string path = volStatus.GetPath(); @@ -110,12 +111,10 @@ void ExtStorageSubscriber::CheckAndUpdateData() } } if (isExist == false) { - if (iter != mountStatus_.end()) { - mountStatus_.erase(iter++); - } else { - mountStatus_.erase(iter); - } - DEBUG_LOG("%{public}s, erase map.", __func__); + mountStatus_.erase(iter++); + DEBUG_LOG("%{public}s, erase map, path:%{public}s.", __func__, iter->first.c_str()); + } else { + iter++; } } // update map data diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/services/src/fileoper/ext_storage/ext_storage_subscriber.h index 3fd93d3d..83376689 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -43,7 +43,7 @@ public: */ virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; - bool CheckMountPoint(const std::string &path); + static bool CheckMountPoint(const std::string &path); private: void CheckAndUpdateData(); diff --git a/services/src/fileoper/ext_storage/storage_manager_inf.cpp b/services/src/fileoper/ext_storage/storage_manager_inf.cpp index fc14f550..2baaf3f8 100644 --- a/services/src/fileoper/ext_storage/storage_manager_inf.cpp +++ b/services/src/fileoper/ext_storage/storage_manager_inf.cpp @@ -15,6 +15,7 @@ #include "storage_manager_inf.h" +#include "ext_storage_subscriber.h" #include "file_manager_service_def.h" #include "file_manager_service_errno.h" #include "log.h" @@ -99,19 +100,7 @@ bool StorageManagerInf::StoragePathValidCheck(const string &path) ERR_LOG("uri path is invalid"); return false; } - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return false; - } - bool succ = false; - for (auto vol : result) { - if (vol.GetPath() == mountPoint && vol.GetState() == VolumeState::MOUNTED) { - succ = true; - break; - } - } - return succ; + return ExtStorageSubscriber::CheckMountPoint(mountPoint); } } // FileManagerService } // OHOS -- Gitee From d64755b53f52da3a9a45e4ef46b3928105cea06a Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 22 Feb 2022 15:30:17 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../ext_storage/ext_storage_subscriber.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index efecaa14..b13154b9 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -52,6 +52,8 @@ bool ExtStorageSubscriber::Subscriber(void) ExtStorageSubscriber_ = std::make_shared(subscribeInfo); EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); + ExtStorageSubscriber_->CheckAndUpdateData(); + } else { ExtStorageSubscriber_->CheckAndUpdateData(); } return true; @@ -78,21 +80,19 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) { - std::vector volVec = StorageManagerInf::GetAllVolumes(); - if (volVec.size() == 0) { - ERR_LOG("empty volume result"); - return false; + if (ExtStorageSubscriber_ == nullptr) { + ExtStorageSubscriber::Subscriber(); } - bool succ = false; - for (auto vol : volVec) { - if (vol.GetPath() == path && vol.GetState() == VolumeState::MOUNTED) { - succ = true; - DEBUG_LOG("%{public}s, path:%{public}s, state:%{public}d.", __func__, path.c_str(), vol.GetState()); - break; + + auto extStorageStatus = ExtStorageSubscriber_->mountStatus_.find(path); + if (extStorageStatus == ExtStorageSubscriber_->mountStatus_.end()) { + return false; + } else { + if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { + return true; } } - DEBUG_LOG("%{public}s, path in map, path:%{public}s.", __func__, path.c_str()); - return succ; + return false; } void ExtStorageSubscriber::CheckAndUpdateData() -- Gitee From 1a768c2fe0bcf5c97a8fe88b40c9c7a1baa9fbed Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 22 Feb 2022 16:15:09 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/src/fileoper/ext_storage/ext_storage_subscriber.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index b13154b9..db69769b 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -52,8 +52,6 @@ bool ExtStorageSubscriber::Subscriber(void) ExtStorageSubscriber_ = std::make_shared(subscribeInfo); EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); - ExtStorageSubscriber_->CheckAndUpdateData(); - } else { ExtStorageSubscriber_->CheckAndUpdateData(); } return true; -- Gitee