{
Internal = 0,
External = 1,
+ ExtendedInternal = 2,
}
// Any change here might require changes in Tizen.System.StorageState enum
Ringtones = 8,
}
+ // Any change here might require changes in Tizen.System.StorageDevice enum
+ internal enum StorageDevice
+ {
+ ExternalSDCard = 1001,
+ ExternalUSBMassStorage = 1002,
+ ExtendedInternalStorage = 1003,
+ }
+
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ internal delegate void StorageChangedCallback(int id, StorageDevice devicetype, StorageState state, string fstype, string fsuuid, string mountpath, bool primary, int flags, IntPtr userData);
+
[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
internal delegate void StorageStateChangedCallback(int id, StorageState state, IntPtr userData);
[DllImport(Libraries.Storage, EntryPoint = "storage_foreach_device_supported")]
public static extern ErrorCode StorageManagerGetForeachDeviceSupported(StorageDeviceSupportedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Storage, EntryPoint = "storage_set_changed_cb")]
+ internal static extern ErrorCode StorageSetChanged(int id, StorageChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Storage, EntryPoint = "storage_unset_changed_cb")]
+ internal static extern ErrorCode StorageUnsetChanged(int id, StorageChangedCallback callback);
}
}
{
private const string LogTag = "Tizen.System";
private Interop.Storage.StorageState _state;
+ private StorageDevice _devicetype;
+ private string _fstype;
+ private string _fsuuid;
private ulong _totalSpace;
+ private bool _primary;
+ private int _flags;
+ private bool information_set = false;
internal Storage(int storageID, Interop.Storage.StorageArea storageType, Interop.Storage.StorageState storagestate, string rootDirectory)
{
RootDirectory = rootDirectory;
_state = storagestate;
+
+ Interop.Storage.ErrorCode err = Interop.Storage.StorageGetTotalSpace(Id, out _totalSpace);
+ if (err != Interop.Storage.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to get total storage space for storage Id: {0}. err = {1}", Id, err));
+ }
+
+ s_stateChangedEventCallback = (id, state, userData) =>
+ {
+ if (id == Id)
+ {
+ _state = state;
+ s_stateChangedEventHandler?.Invoke(this, EventArgs.Empty);
+ }
+ };
+ }
+
+ 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)
+ {
+ Id = storageID;
+ StorageType = (StorageArea)storageType;
+ RootDirectory = rootDirectory;
+ _state = storagestate;
+ _devicetype = (StorageDevice)devicetype;
+ _fstype = fstype;
+ _fsuuid = fsuuid;
+ _primary = primary;
+ _flags = flags;
+ information_set = true;
+
Interop.Storage.ErrorCode err = Interop.Storage.StorageGetTotalSpace(Id, out _totalSpace);
if (err != Interop.Storage.ErrorCode.None)
{
}
/// <summary>
+ /// The StorageDevice
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when DeviceType is not initialized.</exception>
+ public StorageDevice DeviceType
+ {
+ get
+ {
+ if (!information_set)
+ {
+ Log.Error(LogTag, string.Format("Doesn't know StorageDevice type."));
+ throw new InvalidOperationException("Doesn't know StorageDevice type");
+ }
+ return (StorageDevice)_devicetype;
+ }
+ }
+
+ /// <summary>
+ /// The type of file system
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when Fstype is not initialized.</exception>
+ public string Fstype
+ {
+ get
+ {
+ if (!information_set)
+ {
+ Log.Error(LogTag, string.Format("Doesn't know fstype."));
+ throw new InvalidOperationException("Doesn't know type of file system");
+ }
+ return _fstype;
+ }
+ }
+
+ /// <summary>
+ /// The uuid of the file system
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when Fsuuid is not initialized.</exception>
+ public string Fsuuid
+ {
+ get
+ {
+ if (!information_set)
+ {
+ Log.Error(LogTag, string.Format("Doesn't know fsuuid."));
+ throw new InvalidOperationException("Doesn't know uuid of file system");
+ }
+ return _fsuuid;
+ }
+ }
+
+ /// <summary>
+ /// Information about whether this is primary partition
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when Primary is not initialized.</exception>
+ public bool Primary
+ {
+ get
+ {
+ if (!information_set)
+ {
+ Log.Error(LogTag, string.Format("Doesn't know primary information."));
+ throw new InvalidOperationException("Doesn't know primary information");
+ }
+ return _primary;
+ }
+ }
+
+ /// <summary>
+ /// The flags for the storage status
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="InvalidOperationException">Thrown when Flags is not initialized.</exception>
+ public int Flags
+ {
+ get
+ {
+ if (!information_set)
+ {
+ Log.Error(LogTag, string.Format("Doesn't know flags."));
+ throw new InvalidOperationException("Doesn't know flags");
+ }
+ return _flags;
+ }
+ }
+
+ /// <summary>
/// The available storage size in bytes.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// </summary>
/// <since_tizen> 3 </since_tizen>
External = Interop.Storage.StorageArea.External,
+ /// <summary>
+ /// Extended internal storage
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ ExtendedInternal = Interop.Storage.StorageArea.ExtendedInternal,
}
}
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// Enumeration for storage devices.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public enum StorageDevice
+ {
+ /// <summary>
+ /// External sd card device
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ ExternalSDCard = Interop.Storage.StorageDevice.ExternalSDCard,
+ /// <summary>
+ /// External usb mass storage
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ ExternalUSBMassStorage = Interop.Storage.StorageDevice.ExternalUSBMassStorage,
+ /// <summary>
+ /// Extended internal storage
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ ExtendedInternalStorage = Interop.Storage.StorageDevice.ExtendedInternalStorage,
+ }
+}
return storageList;
}
}
+
+ private static EventHandler s_ExternalStorageChangedEventHandler;
+ 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);
+
+ if (devicetype == Interop.Storage.StorageDevice.ExtendedInternalStorage)
+ s_ExtendedInternalStorageChangedEventHandler?.Invoke(storage, EventArgs.Empty);
+ else
+ s_ExternalStorageChangedEventHandler?.Invoke(storage, EventArgs.Empty);
+ };
+
+ private static void RegisterChangedEvent(StorageArea type)
+ {
+ Interop.Storage.ErrorCode err = Interop.Storage.StorageSetChanged((int)type, s_ChangedEventCallback, IntPtr.Zero);
+ if (err != Interop.Storage.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to Register changed event callback for external storage. err = {0}", err));
+ }
+ }
+
+ private static void UnregisterChangedEvent(StorageArea type)
+ {
+ Interop.Storage.ErrorCode err = Interop.Storage.StorageUnsetChanged((int)type, s_ChangedEventCallback);
+ if (err != Interop.Storage.ErrorCode.None)
+ {
+ Log.Warn(LogTag, string.Format("Failed to Unreegister changed event callback for external storage. err = {0}", err));
+ }
+ }
+
+ /// <summary>
+ /// Registers an eventhandler for state chages of specific storage type
+ /// </summary>
+ /// <param name="type">Storage type</param>
+ /// <param name="handler">An eventhandler to register</param>
+ /// <since_tizen> 4 </since_tizen>
+ public static void SetChangedEvent(StorageArea type, EventHandler handler)
+ {
+ if (type == StorageArea.Internal)
+ {
+ Log.Warn(LogTag, "Internal storage state is not changed");
+ }
+ if (s_ExternalStorageChangedEventHandler == null && s_ExtendedInternalStorageChangedEventHandler == null)
+ {
+ RegisterChangedEvent(type);
+ }
+ if ((type == StorageArea.External && s_ExternalStorageChangedEventHandler == null) ||
+ (type == StorageArea.ExtendedInternal && s_ExtendedInternalStorageChangedEventHandler == null))
+ {
+ RegisterChangedEvent(type);
+ }
+ if (type == StorageArea.External)
+ s_ExternalStorageChangedEventHandler += handler;
+ else if (type == StorageArea.ExtendedInternal)
+ s_ExtendedInternalStorageChangedEventHandler += handler;
+ }
+
+ /// <summary>
+ /// Unregisters an eventhandler for state chages of specific storage type
+ /// </summary>
+ /// <param name="type">Storage type</param>
+ /// <param name="handler">An eventhandler to unregister</param>
+ /// <since_tizen> 4 </since_tizen>
+ public static void UnsetChangedEvent(StorageArea type, EventHandler handler)
+ {
+ if (type == StorageArea.Internal)
+ {
+ Log.Warn(LogTag, "Internal storage state is not changed");
+ }
+ if (type == StorageArea.External)
+ s_ExternalStorageChangedEventHandler -= handler;
+ else if (type == StorageArea.ExtendedInternal)
+ s_ExtendedInternalStorageChangedEventHandler -= handler;
+ if ((type == StorageArea.External && s_ExternalStorageChangedEventHandler == null) ||
+ (type == StorageArea.ExtendedInternal && s_ExtendedInternalStorageChangedEventHandler == null))
+ {
+ UnregisterChangedEvent(type);
+ }
+ }
}
}