[MediaContent] Deprecate unused APIs (#5473)
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / MediaInfoCommand.cs
index e2f51ba..ef0303e 100644 (file)
@@ -145,6 +145,7 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
         /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API11; Will be removed in API13.")]
         public int CountFaceInfo(string mediaId, CountArguments arguments)
         {
             ValidateDatabase();
@@ -165,6 +166,7 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
         /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API11; Will be removed in API13.")]
         public MediaDataReader<FaceInfo> SelectFaceInfo(string mediaId)
         {
             return SelectFaceInfo(mediaId, null);
@@ -182,6 +184,7 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
         /// <exception cref="ArgumentException"><paramref name="mediaId"/> is a zero-length string, contains only white space.</exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API11; Will be removed in API13.")]
         public MediaDataReader<FaceInfo> SelectFaceInfo(string mediaId, SelectArguments arguments)
         {
             ValidateDatabase();
@@ -872,9 +875,10 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="UnsupportedContentException">
         ///     The thumbnail is not available for the given media.<br/>
         ///     -or-<br/>
-        ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
+        ///     The media is in the external USB storage.
         /// </exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API10; Will be removed in API12. Please use CreateThumbnail instead.")]
         public Task<string> CreateThumbnailAsync(string mediaId)
         {
             return CreateThumbnailAsync(mediaId, CancellationToken.None);
@@ -904,9 +908,10 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="UnsupportedContentException">
         ///     The thumbnail is not available for the given media.<br/>
         ///     -or-<br/>
-        ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
+        ///     The media is in the external USB storage.
         /// </exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API10; Will be removed in API12. Please use CreateThumbnail instead.")]
         public Task<string> CreateThumbnailAsync(string mediaId, CancellationToken cancellationToken)
         {
             ValidateDatabase();
@@ -962,6 +967,49 @@ namespace Tizen.Content.MediaContent
         }
         #endregion
 
+        /// <summary>
+        /// Creates the thumbnail image for the given media.
+        /// If the thumbnail already exists for the given media, the existing path will be returned.
+        /// </summary>
+        /// <privilege>http://tizen.org/privilege/content.write</privilege>
+        /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+        /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+        /// <param name="mediaId">The ID of the media for which the thumbnail will be created.</param>
+        /// <returns>A created thumbnail path.</returns>
+        /// <exception cref="InvalidOperationException">
+        ///     The <see cref="MediaDatabase"/> is disconnected.<br/>
+        ///     -or-<br/>
+        ///     An internal error occurred while executing.
+        /// </exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
+        /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
+        /// <exception cref="RecordNotFoundException"><paramref name="mediaId"/> does not exist in the database.</exception>
+        /// <exception cref="ArgumentException">
+        ///     <paramref name="mediaId"/> is a zero-length string, contains only white space.
+        /// </exception>
+        /// <exception cref="FileNotFoundException">The file of the media does not exists; moved or deleted.</exception>
+        /// <exception cref="UnsupportedContentException">
+        ///     The thumbnail is not available for the given media.<br/>
+        ///     -or-<br/>
+        ///     The media is in the external USB storage.
+        /// </exception>
+        /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        public string CreateThumbnail(string mediaId)
+        {
+            ValidateDatabase();
+
+            ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
+
+            using (var handle = ValidateFile(mediaId))
+            {
+                Interop.MediaInfo.GenerateThumbnail(handle).ThrowIfError("Failed to create thumbnail");
+
+                return InteropHelper.GetString(handle, Interop.MediaInfo.GetThumbnailPath, true);
+            }
+        }
+
         private Interop.MediaInfoHandle ValidateFile(string mediaId)
         {
             Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle).ThrowIfError("Failed to create thumbnail");
@@ -975,6 +1023,11 @@ namespace Tizen.Content.MediaContent
             {
                 var path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath);
 
+                if (String.IsNullOrEmpty(path) || File.Exists(path) == false)
+                {
+                    throw new FileNotFoundException($"The media file does not exist. Path={path}.", path);
+                }
+
                 foreach (var extendedInternal in StorageManager.Storages.Where(s => s.StorageType == StorageArea.ExtendedInternal))
                 {
                     if (path.Contains(extendedInternal.RootDirectory))
@@ -982,11 +1035,6 @@ namespace Tizen.Content.MediaContent
                         throw new UnsupportedContentException("The media is in external usb storage.");
                     }
                 }
-
-                if (File.Exists(path) == false)
-                {
-                    throw new FileNotFoundException($"The media file does not exist. Path={path}.", path);
-                }
             }
             catch (Exception ex)
             {
@@ -1023,6 +1071,7 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API11; Will be removed in API13.")]
         public Task<int> DetectFaceAsync(string mediaId)
         {
             return DetectFaceAsync(mediaId, CancellationToken.None);
@@ -1057,10 +1106,11 @@ namespace Tizen.Content.MediaContent
         /// <exception cref="UnsupportedContentException">
         ///     Face detection is not available for the given media.<br/>
         ///     -or-<br/>
-        ///     The media is in the external USB storage (<see cref="MediaInfo.StorageType"/> is <see cref="StorageType.ExternalUsb"/>).
+        ///     The media is in the external USB storage.
         /// </exception>
         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated since API11; Will be removed in API13.")]
         public Task<int> DetectFaceAsync(string mediaId, CancellationToken cancellationToken)
         {
             if (Features.IsSupported(Features.FaceRecognition) == false)
@@ -1089,11 +1139,6 @@ namespace Tizen.Content.MediaContent
 
             using (handle)
             {
-                if (InteropHelper.GetValue<StorageType>(handle, Interop.MediaInfo.GetStorageType) == StorageType.ExternalUsb)
-                {
-                    throw new UnsupportedContentException("The media is in external usb storage.");
-                }
-
                 if (InteropHelper.GetValue<MediaType>(handle, Interop.MediaInfo.GetMediaType) != MediaType.Image)
                 {
                     throw new UnsupportedContentException("Only image is supported.");
@@ -1117,7 +1162,13 @@ namespace Tizen.Content.MediaContent
                 using (RegisterCancelFaceDetection(cancellationToken, tcs, handle))
                 using (var cbKeeper = ObjectKeeper.Get(GetFaceDetectionCallback(tcs)))
                 {
-                    Interop.MediaInfo.StartFaceDetection(handle, cbKeeper.Target).ThrowIfError("Failed to detect faces");
+                    var ret = Interop.MediaInfo.StartFaceDetection(handle, cbKeeper.Target);
+                    if (ret == MediaContentError.InvalidParameter)
+                    {
+                        throw new UnsupportedContentException("The media is in external usb storage.");
+                    }
+
+                    ret.ThrowIfError("Failed to detect faces");
 
                     return await tcs.Task;
                 }