From ccad664c273ef6c74ac25b92e68d2b8f470ae2ed Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Wed, 27 Mar 2024 15:51:24 +0900 Subject: [PATCH] [Tizen.System.Storage] Register eventhandler if it is already existed Register event handler in the class Storage if eventhandler is already existed. If at least one event handler is already registered, the API returns the storage state from a variable within the class. Otherwise, it retrieves the status externally. In the previous implementation, an event handler was only registered within class Storage when it was registered for each storage ID, and no event handler was registered within class Storage when it was registered by storage type. As a result of that, when the USB (or SD card) was removed, it attempted to obtain the state from outside and provided incorrect information to the application because there is no storage already removed. Signed-off-by: Unsung Lee --- src/Tizen.System.Storage/Storage/Storage.cs | 8 +++++++- src/Tizen.System.Storage/Storage/StorageManager.cs | 11 +++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Tizen.System.Storage/Storage/Storage.cs b/src/Tizen.System.Storage/Storage/Storage.cs index 643e6d0a8..d02665216 100644 --- a/src/Tizen.System.Storage/Storage/Storage.cs +++ b/src/Tizen.System.Storage/Storage/Storage.cs @@ -59,7 +59,10 @@ namespace Tizen.System }; } - internal Storage(int storageID, Interop.Storage.StorageArea storageType, Interop.Storage.StorageState storagestate, string rootDirectory, Interop.Storage.StorageDevice devicetype, string fstype, string fsuuid, bool primary, int flags) + internal Storage(int storageID, Interop.Storage.StorageArea storageType, + Interop.Storage.StorageState storagestate, string rootDirectory, + Interop.Storage.StorageDevice devicetype, string fstype, + string fsuuid, bool primary, int flags, EventHandler eventhandler = null) { Id = storageID; _storagetype = storageType; @@ -71,6 +74,9 @@ namespace Tizen.System _primary = primary; _flags = flags; information_set = true; + s_stateChangedEventHandler = eventhandler; + if (s_stateChangedEventHandler == null) + Log.Warn(LogTag, string.Format("Can't register event handler")); Interop.Storage.ErrorCode err = Interop.Storage.StorageGetTotalSpace(Id, out _totalSpace); if (err != Interop.Storage.ErrorCode.None) diff --git a/src/Tizen.System.Storage/Storage/StorageManager.cs b/src/Tizen.System.Storage/Storage/StorageManager.cs index 444bb064c..5bf91578b 100644 --- a/src/Tizen.System.Storage/Storage/StorageManager.cs +++ b/src/Tizen.System.Storage/Storage/StorageManager.cs @@ -55,12 +55,15 @@ namespace Tizen.System private static EventHandler s_ExtendedInternalStorageChangedEventHandler; private static Interop.Storage.StorageChangedCallback s_ChangedEventCallback = (int id, Interop.Storage.StorageDevice devicetype, Interop.Storage.StorageState state, string fstype, string fsuuid, string rootDirectory, bool primary, int flags, IntPtr userData) => { - Storage storage = new Storage(id, Interop.Storage.StorageArea.External, state, rootDirectory, devicetype, fstype, fsuuid, primary, flags); - + EventHandler eventhandler = null; if (devicetype == Interop.Storage.StorageDevice.ExtendedInternalStorage) - s_ExtendedInternalStorageChangedEventHandler?.Invoke(storage, EventArgs.Empty); + eventhandler = s_ExtendedInternalStorageChangedEventHandler; else - s_ExternalStorageChangedEventHandler?.Invoke(storage, EventArgs.Empty); + eventhandler = s_ExternalStorageChangedEventHandler; + + Storage storage = new Storage(id, Interop.Storage.StorageArea.External, + state, rootDirectory, devicetype, fstype, fsuuid, primary, flags, eventhandler); + eventhandler?.Invoke(storage, EventArgs.Empty); }; private static void RegisterChangedEvent(StorageArea type) -- 2.34.1