diff --git a/services/BUILD.gn b/services/BUILD.gn index 78366209e0d768b06d58cd2cead640a6aff7df52..69aeafa82690bb41aebacb256f297c1acf5ed3a8 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_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h new file mode 100644 index 0000000000000000000000000000000000000000..a2b27b0e35c31b2e9f68263f888d5929efe91b8f --- /dev/null +++ b/services/src/fileoper/ext_storage/ext_storage_status.h @@ -0,0 +1,112 @@ +/* + * 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 + +#include "file_manager_service_def.h" + +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 VolumeState &volumeState) + : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), volumeState_(volumeState) {} + + ExtStorageStatus(const ExtStorageStatus &extStatus) + { + this->id_ = extStatus.id_; + this->diskId_ = extStatus.diskId_; + this->fsUuid_ = extStatus.fsUuid_; + this->path_ = extStatus.path_; + this->volumeState_ = extStatus.volumeState_; + } + + ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) + { + 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; + } + + 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; + } + + VolumeState GetVolumeState() + { + return volumeState_; + } + + void SetVolumeState(const VolumeState &volumeState) + { + volumeState_ = volumeState; + } + +private: + std::string id_; + std::string diskId_; + std::string fsUuid_; + std::string path_; + VolumeState volumeState_; +}; +} // namespace FileManagerService +} // namespace OHOS +#endif // STORAGE_EXT_STORAGE_STATUS_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp index 0f82363a848177d7feb6a7818940fab6eb773fbe..410864dd94eaa48c62225d4be7215ee88193651c 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; @@ -40,7 +42,8 @@ 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_UNMOUNTED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); ExtStorageSubscriber_ = std::make_shared(subscribeInfo); @@ -58,6 +61,37 @@ 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"))); + 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) { + 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, 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 bbd55a46a86ee090e6fe0323e76a9ba10c81275c..18a34b779970bb9b509c5aa06372bfea2e18ed16 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,10 @@ public: * @param eventData Common event data. */ virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; + + bool CheckMountPoint(const std::string &path); + + std::unordered_map mountStatus; }; } // namespace FileManagerService } // namespace OHOS