From 36f8f302c859c25b1a941bccaba69e9fd3439cb1 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 9 Feb 2022 14:42:47 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=EF=BC=8C=E8=AE=B0=E5=BD=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../fileoper/ext_storage/ext_storage_status.h | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 services/src/fileoper/ext_storage/ext_storage_status.h diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h new file mode 100644 index 00000000..fee1ad8e --- /dev/null +++ b/services/src/fileoper/ext_storage/ext_storage_status.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef STORAGE_EXT_STORAGE_STATUS_H +#define STORAGE_EXT_STORAGE_STATUS_H + +#include + +namespace OHOS { +namespace FileManagerService { +class ExtStorageStatus { +public: + ExtStorageStatus() = default; + ~ExtStorageStatus() = default; + ExtStorageStatus(const std::string &id, const std::string &diskId, + const std::string &fsUuid, const std::string &path, const int32_t notifyCode) + : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), notifyCode_(notifyCode) {} + + ExtStorageStatus(const ExtStorageStatus &extStatus) + { + this->id_ = extStatus.id_; + this->diskId_ = extStatus.diskId_; + this->fsUuid_ = extStatus.fsUuid_; + this->path_ = extStatus.path_; + this->notifyCode_ = extStatus.notifyCode_; + } + + ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) + { + this->id_ = extStatus.id_; + this->diskId_ = extStatus.diskId_; + this->fsUuid_ = extStatus.fsUuid_; + this->path_ = extStatus.path_; + this->notifyCode_ = extStatus.notifyCode_; + return *this; + } + + std::string GetId() + { + return id_; + } + + void SetId(const std::string &id) + { + id_ = id; + } + + std::string GetDiskId() + { + return diskId_; + } + + void SetDiskId(const std::string &diskId) + { + diskId_ = diskId; + } + + std::string GetFsUuid() + { + return fsUuid_; + } + + void SetFsUuid(const std::string &fsUuid) + { + fsUuid_ = fsUuid; + } + + std::string GetPath() + { + return path_; + } + + void SetPath(const std::string &path) + { + path_ = path; + } + + int32_t GetNotifyCode() + { + return notifyCode_; + } + + void SetNotifyCode(const int32_t ¬ifyCode) + { + notifyCode_ = notifyCode; + } + +private: + std::string id_; + std::string diskId_; + std::string fsUuid_; + std::string path_; + int32_t notifyCode_; +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_EXT_STORAGE_STATUS_H \ No newline at end of file -- Gitee From 2592ec4a3bce3fb4d35abde5218d2e2dd7c1a13f Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 9 Feb 2022 14:44:34 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=B9=BF=E6=92=AD?= =?UTF-8?q?=EF=BC=8C=E8=AE=B0=E5=BD=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- services/BUILD.gn | 1 + .../ext_storage/ext_storage_subscriber.cpp | 32 +++++++++++++++++++ .../ext_storage/ext_storage_subscriber.h | 6 ++++ 3 files changed, 39 insertions(+) diff --git a/services/BUILD.gn b/services/BUILD.gn index 78366209..69aeafa8 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("fms_server") { "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog", "//foundation/filemanagement/storage_service/services/storage_manager/include", "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", + "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", ] sources = [ diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 0f82363a..1a395b3d 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -22,6 +22,8 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "log.h" +#include "string_wrapper.h" +#include "int_wrapper.h" #include "want.h" using namespace OHOS::AAFwk; @@ -41,6 +43,9 @@ bool ExtStorageSubscriber::Subscriber(void) if (ExtStorageSubscriber_ == nullptr) { EventFwk::MatchingSkills matchingSkills; matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); ExtStorageSubscriber_ = std::make_shared(subscribeInfo); @@ -58,6 +63,33 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event const AAFwk::Want& want = eventData.GetWant(); std::string action = want.GetAction(); DEBUG_LOG("%{public}s, action:%{public}s.", __func__, action.c_str()); + + const AAFwk::WantParams wantParams = want.GetParams(); + std::string id = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("id"))); + std::string diskId = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("diskId"))); + int32_t notifyCode = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("notifyCode"))); + DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); + DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); + DEBUG_LOG("%{public}s, notifyCode:%{public}d.", __func__, notifyCode); + + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) + { + 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, id:%{public}s, diskId:%{public}s, fsUuid:%{public}s, path:%{public}s, notifyCode:%{public}d.", + __func__, id.c_str(), diskId.c_str(), fsUuid.c_str(), path.c_str(), notifyCode); + + ExtStorageStatus extStatus(id, diskId, fsUuid, path, notifyCode); + mountStatus.insert(std::pair(path, extStatus)); + } + + // for (auto iter = mountStatus.begin(); iter != mountStatus.end(); ++iter){ + // std::string diskId = iter->second.GetDiskId(); + // int32_t notifyCode = iter->second.GetNotifyCode(); + // DEBUG_LOG("%{public}s, path:%{public}s, diskId:%{public}s, notifyCode:%{public}d.", __func__, iter->first.c_str(), diskId.c_str(), notifyCode); + // } + } } // 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 bbd55a46..645e5379 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -15,10 +15,14 @@ #ifndef STORAGE_FILE_SYS_EVENT_RECEIVER_H #define STORAGE_FILE_SYS_EVENT_RECEIVER_H +#include +#include + #include "common_event_manager.h" #include "common_event_subscribe_info.h" #include "common_event_subscriber.h" #include "common_event_support.h" +#include "ext_storage_status.h" #include "matching_skills.h" namespace OHOS { @@ -38,6 +42,8 @@ public: * @param eventData Common event data. */ virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; + + std::unordered_map mountStatus; }; } // namespace FileManagerService } // namespace OHOS -- Gitee From 7a11d5524742890cb01308cc05f9af8e6f8d4762 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 9 Feb 2022 14:54:17 +0800 Subject: [PATCH 3/6] =?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 --- .../ext_storage/ext_storage_subscriber.cpp | 14 +++----------- 1 file changed, 3 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 1a395b3d..c4a7bb26 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -72,24 +72,16 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); DEBUG_LOG("%{public}s, notifyCode:%{public}d.", __func__, notifyCode); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) - { + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) { 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, id:%{public}s, diskId:%{public}s, fsUuid:%{public}s, path:%{public}s, notifyCode:%{public}d.", - __func__, id.c_str(), diskId.c_str(), fsUuid.c_str(), path.c_str(), notifyCode); + 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, notifyCode); mountStatus.insert(std::pair(path, extStatus)); } - - // for (auto iter = mountStatus.begin(); iter != mountStatus.end(); ++iter){ - // std::string diskId = iter->second.GetDiskId(); - // int32_t notifyCode = iter->second.GetNotifyCode(); - // DEBUG_LOG("%{public}s, path:%{public}s, diskId:%{public}s, notifyCode:%{public}d.", __func__, iter->first.c_str(), diskId.c_str(), notifyCode); - // } - } } // namespace FileManagerService } // namespace OHOS \ No newline at end of file -- Gitee From d6b992cbf3a411f479957222940304df22166bf8 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 9 Feb 2022 16:52:04 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../fileoper/ext_storage/ext_storage_status.h | 22 ++++++++++--------- .../ext_storage/ext_storage_subscriber.cpp | 22 ++++++++++++++----- .../ext_storage/ext_storage_subscriber.h | 2 ++ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h index fee1ad8e..ef35dab9 100644 --- a/services/src/fileoper/ext_storage/ext_storage_status.h +++ b/services/src/fileoper/ext_storage/ext_storage_status.h @@ -17,6 +17,8 @@ #include +#include "file_manager_service_def.h" + namespace OHOS { namespace FileManagerService { class ExtStorageStatus { @@ -24,8 +26,8 @@ public: ExtStorageStatus() = default; ~ExtStorageStatus() = default; ExtStorageStatus(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const int32_t notifyCode) - : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), notifyCode_(notifyCode) {} + const std::string &fsUuid, const std::string &path, const VolumeState &volumeState) + : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), volumeState_(volumeState) {} ExtStorageStatus(const ExtStorageStatus &extStatus) { @@ -33,7 +35,7 @@ public: this->diskId_ = extStatus.diskId_; this->fsUuid_ = extStatus.fsUuid_; this->path_ = extStatus.path_; - this->notifyCode_ = extStatus.notifyCode_; + this->volumeState_ = extStatus.volumeState_; } ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) @@ -42,7 +44,7 @@ public: this->diskId_ = extStatus.diskId_; this->fsUuid_ = extStatus.fsUuid_; this->path_ = extStatus.path_; - this->notifyCode_ = extStatus.notifyCode_; + this->volumeState_ = extStatus.volumeState_; return *this; } @@ -80,20 +82,20 @@ public: { return path_; } - + void SetPath(const std::string &path) { path_ = path; } - int32_t GetNotifyCode() + VolumeState GetVolumeState() { - return notifyCode_; + return volumeState_; } - void SetNotifyCode(const int32_t ¬ifyCode) + void SetVolumeState(const VolumeState &volumeState) { - notifyCode_ = notifyCode; + volumeState_ = volumeState; } private: @@ -101,7 +103,7 @@ private: std::string diskId_; std::string fsUuid_; std::string path_; - int32_t notifyCode_; + VolumeState volumeState_; }; } // namespace FileManagerService } // namespace OHOS diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index c4a7bb26..1b692b60 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -67,21 +67,33 @@ void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &event const AAFwk::WantParams wantParams = want.GetParams(); std::string id = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("id"))); std::string diskId = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("diskId"))); - int32_t notifyCode = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("notifyCode"))); DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - DEBUG_LOG("%{public}s, notifyCode:%{public}d.", __func__, notifyCode); - + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_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, 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, notifyCode); + ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); mountStatus.insert(std::pair(path, extStatus)); } } + +bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) +{ + auto extStorageStatus = mountStatus.find(path); + if (extStorageStatus == mountStatus.end()) { + return false; + } else { + if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { + return true; + } + return false; + } +} } // 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 645e5379..18a34b77 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.h @@ -43,6 +43,8 @@ public: */ virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; + bool CheckMountPoint(const std::string &path); + std::unordered_map mountStatus; }; } // namespace FileManagerService -- Gitee From b5195040058878f9186780a26e043568264717f5 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 9 Feb 2022 17:03:41 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=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 | 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 1b692b60..410864dd 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp @@ -42,8 +42,6 @@ bool ExtStorageSubscriber::Subscriber(void) { if (ExtStorageSubscriber_ == nullptr) { EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_REMOVED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); -- Gitee From c2ec48af44bdd1520287db2cbc325195e1dc0f58 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Thu, 10 Feb 2022 15:09:55 +0800 Subject: [PATCH 6/6] =?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_status.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h index ef35dab9..a2b27b0e 100644 --- a/services/src/fileoper/ext_storage/ext_storage_status.h +++ b/services/src/fileoper/ext_storage/ext_storage_status.h @@ -40,11 +40,13 @@ public: ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; + if (this != &extStatus) { + this->id_ = extStatus.id_; + this->diskId_ = extStatus.diskId_; + this->fsUuid_ = extStatus.fsUuid_; + this->path_ = extStatus.path_; + this->volumeState_ = extStatus.volumeState_; + } return *this; } -- Gitee