Add new cache APIs (#5088)
authorakash1-kumar <115205462+akash1-kumar@users.noreply.github.com>
Mon, 3 Apr 2023 03:58:01 +0000 (09:28 +0530)
committerGitHub <noreply@github.com>
Mon, 3 Apr 2023 03:58:01 +0000 (12:58 +0900)
* Add new APIs for cache.

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
* Add new APIs for cache.

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
* Change methods to C# properties for set/get APIs.

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
* Add class 'CacheManager' for managing cache properties.

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
* Update documentation: Add '<feature>' tag

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
---------

Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
src/Tizen.Content.Download/Interop/Interop.Download.cs
src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs [new file with mode: 0644]
src/Tizen.Content.Download/Tizen.Content.Download/Request.cs

index 839ee635ef05e5b00776feb28bac7454da8a9650..c4433c4141e396aee4f0115a9aafd569f213c33c 100755 (executable)
@@ -106,5 +106,25 @@ internal static partial class Interop
         internal static extern int SetNotificationAppControl(int requestId, int appControlType, SafeAppControlHandle handle);
         [DllImport(Libraries.Download, EntryPoint = "download_get_notification_app_control")]
         internal static extern int GetNotificationAppControl(int requestId, int appControlType, out SafeAppControlHandle handle);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_cache")]
+        internal static extern int SetDownloadCache(int downloadId, bool enable);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_cache")]
+        internal static extern int GetDownloadCache(int downloadId, out bool enable);
+        [DllImport(Libraries.Download, EntryPoint = "download_reset_cache")]
+        internal static extern int ResetDownloadCache();
+        [DllImport(Libraries.Download, EntryPoint = "download_set_cache_max_size")]
+        internal static extern int SetDownloadCacheMaxSize(uint maxSize);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_cache_max_size")]
+        internal static extern int GetDownloadCacheMaxSize(out uint maxSize);
+        [DllImport(Libraries.Download, EntryPoint = "download_reset_all_cache")]
+        internal static extern int ResetAllDownloadCache();
+        [DllImport(Libraries.Download, EntryPoint = "download_set_cache_path")]
+        internal static extern int SetDownloadCachePath(string cachePath);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_cache_path")]
+        internal static extern int GetDownloadCachePath(out string cachePath);
+        [DllImport(Libraries.Download, EntryPoint = "download_set_cache_lifecycle")]
+        internal static extern int SetDownloadCacheLifeCycle(uint time);
+        [DllImport(Libraries.Download, EntryPoint = "download_get_cache_lifecycle")]
+        internal static extern int GetDownloadCacheLifeCycle(out uint time);
     }
 }
diff --git a/src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs b/src/Tizen.Content.Download/Tizen.Content.Download/CacheManager.cs
new file mode 100644 (file)
index 0000000..2a07319
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+* Copyright (c) 2023 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.
+*/
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.Content.Download
+{
+    /// <summary>
+    /// The CacheManager class provides the functions to manage cache properties.
+    /// </summary>
+    /// <since_tizen> 11 </since_tizen>
+    static class CacheManager
+    {
+
+        /// <summary>
+        /// Clears per app download cache.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        static public void ResetCache()
+        {
+            int ret = Interop.Download.ResetDownloadCache();
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Failed to reset cache");
+            }
+        }
+
+        /// <summary>
+        /// Total maximum cache size considering all apps.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <exception cref="ArgumentException">Thrown when it is failed due to setting an invalid value.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public uint MaxCacheSize
+        {
+            get
+            {
+                uint maxCacheSize;
+                int ret = Interop.Download.GetDownloadCacheMaxSize(out maxCacheSize);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to get max size of cache");
+                }
+                return maxCacheSize;
+            }
+            set
+            {
+                int ret = Interop.Download.SetDownloadCacheMaxSize(value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set cache max size");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Clears all system download cache.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public void ResetAllCache()
+        {
+            int ret = Interop.Download.ResetAllDownloadCache();
+            if (ret != (int)DownloadError.None)
+            {
+                DownloadErrorFactory.ThrowException(ret, "Failed to reset all cache");
+            }
+        }
+
+        /// <summary>
+        /// Path of the cache stored.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <exception cref="ArgumentException">Thrown when it is failed due to setting an invalid value.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public string CachePath
+        {
+            get
+            {
+                string cachePath;
+                int ret = Interop.Download.GetDownloadCachePath(out cachePath);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to get cache path");
+                }
+                return cachePath;
+            }
+            set
+            {
+                int ret = Interop.Download.SetDownloadCachePath(value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set cache path");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Life cycle of the cache in seconds.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <remarks> The time after which the stored cache will be invalid/stale.</remarks>
+        /// <exception cref="ArgumentException">Thrown when it is failed due to setting an invalid value.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public uint CacheLifeCycle
+        {
+            get
+            {
+                uint lifeCycle;
+                int ret = Interop.Download.GetDownloadCacheLifeCycle(out lifeCycle);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to get cache life cycle.");
+                }
+                return lifeCycle;
+            }
+            set
+            {
+                int ret = Interop.Download.SetDownloadCacheLifeCycle(value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set cache life cycle.");
+                }
+            }
+        }
+    }
+}
index bd484be3974162f8f661f73edcf22ed8b5430f0d..25e282804f56212e72c944f628a3ce3298f99a37 100755 (executable)
@@ -17,6 +17,7 @@
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
+using System.ComponentModel;
 
 namespace Tizen.Content.Download
 {
@@ -843,6 +844,38 @@ namespace Tizen.Content.Download
                 DownloadErrorFactory.ThrowException(ret, "Unsetting ProgressChanged callback failed");
             }
         }
+
+        /// <summary>
+        /// Enabled state of the cache feature.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/download</privilege>
+        /// <feature>http://tizen.org/feature/download</feature>
+        /// <exception cref="ArgumentException">Thrown when it is failed due to setting an invalid value.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception>
+        /// <exception cref="NotSupportedException">Thrown when not supported.</exception>
+        public bool UsesCache
+        {
+            get
+            {
+                bool enable;
+                int ret = Interop.Download.GetDownloadCache(_downloadId, out enable);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to get enabled state of cache");
+                }
+                return enable;
+            }
+            set
+            {
+                int ret = Interop.Download.SetDownloadCache(_downloadId, value);
+                if (ret != (int)DownloadError.None)
+                {
+                    DownloadErrorFactory.ThrowException(ret, "Failed to set enabled state of download cache");
+                }
+            }
+        }
     }
 }