diff --git a/interfaces/innerkits/storage_manager/native/mtp_stats.h b/interfaces/innerkits/storage_manager/native/mtp_stats.h new file mode 100644 index 0000000000000000000000000000000000000000..04eaffa5dbe14477a97ce9045b2a386f5f0b0d8d --- /dev/null +++ b/interfaces/innerkits/storage_manager/native/mtp_stats.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 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 MTP_STATS_H +#define MTP_STATS_H + +#include "parcel.h" + +namespace OHOS { +namespace StorageManager { +class MtpStats final : public Parcelable { +public: + MtpStats(); + MtpStats(std::string id, std::string path); + + std::string GetId(); + std::string GetPath(); + + bool Marshalling(Parcel &parcel) const override; + static std::unique_ptr Unmarshalling(Parcel &parcel); + +private: + std::string id_; + std::string path_; + std::string devlinks_; +}; +} // namespace StorageManager +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/services/storage_daemon/include/mtp/mtp_device_manager.h b/services/storage_daemon/include/mtp/mtp_device_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..3667392c2edfad0a53cc3d32b9e032dddbc6a670 --- /dev/null +++ b/services/storage_daemon/include/mtp/mtp_device_manager.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 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 MTP_DEVICE_MANAGER_H +#define MTP_DEVICE_MANAGER_H +#include +#include "singleton.h" +#include +namespace OHOS { +namespace StorageDaemon { +class MtpDeviceManager : public Singleton { +public: + bool MountMtp(std::string id, std::string devlinks, std::string path); + bool UnMountMtp(std::string id, std::string path); + bool UnMountMtpAll(std::string path); + +private: + bool isMounting = false; + bool Exec(const std::string &devlinks, const std::string &path); + uid_t FILE_MANAGER_UID = 1006; + gid_t FILE_MANAGER_GID = 1006; + mode_t PUBLIC_DIR_MODE = 0770; +}; +} // namespace StorageDaemon +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/storage_daemon/include/mtp/mtp_monitor.h b/services/storage_daemon/include/mtp/mtp_monitor.h new file mode 100644 index 0000000000000000000000000000000000000000..7b4813dabdf612a730cba96404ac81a69ea7505b --- /dev/null +++ b/services/storage_daemon/include/mtp/mtp_monitor.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 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 MTP_MONITOR_H +#define MTP_MONITOR_H +#include +#include +#include +#include "libudev.h" +#include "singleton.h" +#include "simple-mtpfs-fuse.h" +#include "simple-mtpfs-util.h" +namespace OHOS { +namespace StorageDaemon { +class MtpMonitor : public Singleton { +public: + struct UdevInfo { + std::string id; + std::string action; + std::string major; + std::string minor; + std::string idMtpDevice; + std::string devlinks; + std::string path; + }; + + static bool Monitor(); + + static std::vector addMtpDevices; + static void GetUdevInfoList(std::vector &infos); +private: + static bool udevExit; + const static std::string MTP_ROOT_PATH; + + static std::vector umountFailDevices; + static void SigHandler(int signum); + static void MonitorDevice(struct udev &udev); + static bool ContainMtpInfo(const std::string &devlinks, const std::vector &mtpInfos); + static void GetUdevInfos(struct udev_device &device, + std::vector &mtpInfos, + std::vector &removeInfos); + static bool MtpDeviceControl(const std::vector &mtpDevices, + const std::vector &removeDevices); + static bool MountMtpDevice(const std::vector &udevInfos); + static bool UnMountMtpDevice(const std::vector &udevInfos); + static bool HadMount(const UdevInfo &info, const std::vector &infos); + static bool UmountDevices(); + static void MonitorMtp(bool &success); +}; +} // namespace StorageDaemon +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/storage_daemon/include/utils/cmd_utils.h b/services/storage_daemon/include/utils/cmd_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..38aded448a522611e24451663b0b621d60aa6d92 --- /dev/null +++ b/services/storage_daemon/include/utils/cmd_utils.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 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 CMD_UTILS_H +#define CMD_UTILS_H +#include +#include +#include "singleton.h" +namespace OHOS { +namespace StorageDaemon { +class CmdUtils : public Singleton { +public: + CmdUtils(); + ~CmdUtils(); + bool RunCmd(const std::string &cmd, std::vector &result); + +private: +}; +} // namespace StorageService +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/services/storage_manager/include/mtp/mtp_brocast.h b/services/storage_manager/include/mtp/mtp_brocast.h new file mode 100644 index 0000000000000000000000000000000000000000..978b0e0100d7195b2129b174c531b1373cdcb82a --- /dev/null +++ b/services/storage_manager/include/mtp/mtp_brocast.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 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 MTP_BROCAST_H +#define MTP_BROCAST_H +#include "singleton.h" +namespace OHOS { +namespace StorageManager { +enum MtpState { MOUNTED_SUCCESSED, MOUNTED_FAILED, UMOUNTED_SUCCESSED, UMOUNTED_ALL }; + +class MtpBrocast : public Singleton { +public: + void NotifyMtpChange(const MtpState ¬ifyCode, const std::string &id, const std::string &path); + +private: +}; +} // namespace StorageManager +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/services/storage_manager/include/mtp/mtp_manager_service.h b/services/storage_manager/include/mtp/mtp_manager_service.h new file mode 100644 index 0000000000000000000000000000000000000000..d4f5626bd94a81d5f3422b5985bcab0979c28f1e --- /dev/null +++ b/services/storage_manager/include/mtp/mtp_manager_service.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 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 MTP_MANAGER_SERVICE_H +#define MTP_MANAGER_SERVICE_H +#include +#include +#include +#include "mtp_stats.h" +namespace OHOS { +namespace StorageManager { +class MtpManagerService : public NoCopyable { + DECLARE_DELAYED_SINGLETON(MtpManagerService); + +public: + std::vector GetAllMtpDevs(); + void NofifyChange(std::string id, std::string path); + int32_t Mount(std::string id, std::string path, bool success); + int32_t UnMount(std::string id, std::string path, bool success); + void UnMountAll(); + +private: + std::vector mtpDevs_; +}; +} // namespace StorageManager +} // namespace OHOS + +#endif \ No newline at end of file