Skip to content

Commit

Permalink
[Tizen.System.Storage] Register eventhandler if it is already existed
Browse files Browse the repository at this point in the history
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 <unsung.lee@samsung.com>
  • Loading branch information
Unsung Lee authored and chanwoochoi committed Mar 29, 2024
1 parent 6420c38 commit b47915f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Tizen.System.Storage/Storage/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ internal Storage(int storageID, Interop.Storage.StorageArea storageType, Interop
};
}

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;
Expand All @@ -71,6 +74,9 @@ internal Storage(int storageID, Interop.Storage.StorageArea storageType, Interop
_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)
Expand Down
11 changes: 7 additions & 4 deletions src/Tizen.System.Storage/Storage/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public static IEnumerable<Storage> Storages
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)
Expand Down

0 comments on commit b47915f

Please sign in to comment.